我正在将woocommerce与自定义主题整合在一起。当我添加自定义结帐字段时,它会显示在左列的所有其他字段的底部。我希望它出现在右侧栏中,位于textarea“订单备注”下面。
functions.php中的代码:
// Change Checkout Fields
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
// Add new fields to checkout
$fields['billing']['card_requests'] = array(
'type' => 'textarea',
'label' => __('Card Requests', 'woocommerce'),
'placeholder' => _x('Please enter messages for your handwritten cards here.', 'placeholder', 'woocommerce'),
'required' => false
);
return $fields;
}
在输出的HTML中,有一个col-1 div和一个col-2 div。我认为这来自templates/formcheckout.php
:
<div class="col-1">
<?php do_action( 'woocommerce_checkout_billing' ); ?>
</div>
<div class="col-2">
<?php do_action( 'woocommerce_checkout_shipping' ); ?>
</div>
截图:
答案 0 :(得分:2)
将以下内容添加到您的functions.php中:
// Change Checkout Fields
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
// Add new fields below order notes section
$fields['order']['card_requests'] = array(
'type' => 'textarea',
'label' => __('Card Requests', 'woocommerce'),
'placeholder' => _x('Please enter messages for your handwritten cards here.', 'placeholder', 'woocommerce'),
'required' => false
);
return $fields;
}