php-在WooCommerce 3中“创建帐户”上方移动“结帐订单注释”字段
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php-在WooCommerce 3中“创建帐户”上方移动“结帐订单注释”字段,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2192字,纯文字阅读大概需要4分钟。
内容图文
我使用的是WooCommerce版本3.2.1,并且尝试在我的主题functions.php中添加以下代码,以移动“订单注释结帐”字段,但是它不起作用:
add_filter( 'woocommerce_checkout_fields', 'bbloomer_move_checkout_fields_woo_3');
function bbloomer_move_checkout_fields_woo_3( $fields ) {
$fields['order']['order_comments']['priority'] = 8;
return $fields;
}
我想在“结帐”页面的“ create_account”复选框上方和“ billing_postcode”字段下方移动“订单注释”文本区域.
我该如何运作?
解决方法:
在下面的代码中:
>我删除了“订购单”
>我添加了一个类似的自定义结算字段(名为“ billing_customer_note”)
>我对字段进行重新排序(*)
>订单在结帐时提交后,我将自定义结算字段“客户注释”数据添加为经典的订单注释…
这是该代码:
// Checkout fields customizations
add_filter( 'woocommerce_checkout_fields' , 'customizing_checkout_fields', 10, 1 );
function customizing_checkout_fields( $fields ) {
// Remove the Order Notes
unset($fields['order']['order_comments']);
// Define custom Order Notes field data array
$customer_note = array(
'type' => 'textarea',
'class' => array('form-row-wide', 'notes'),
'label' => __('Order Notes', 'woocommerce'),
'placeholder' => _x('Notes about your order, e.g. special notes for delivery.', 'placeholder', 'woocommerce')
);
// Set custom Order Notes field
$fields['billing']['billing_customer_note'] = $customer_note;
// Define billing fields new order
$ordered_keys = array(
'billing_first_name',
'billing_last_name',
'billing_company',
'billing_country',
'billing_address_1',
'billing_address_2',
'billing_city',
'billing_state',
'billing_postcode',
'billing_phone',
'billing_email',
'billing_customer_note', // <= HERE
);
// Set billing fields new order
$count = 0;
foreach( $ordered_keys as $key ) {
$count += 10;
$fields['billing'][$key]['priority'] = $count;
}
return $fields;
}
// Set the custom field 'billing_customer_note' in the order object as a default order note (before it's saved)
add_action( 'woocommerce_checkout_create_order', 'customizing_checkout_create_order', 10, 2 );
function customizing_checkout_create_order( $order, $data ) {
$order->set_customer_note( isset( $data['billing_customer_note'] ) ? $data['billing_customer_note'] : '' );
}
代码在您的活动子主题(或主题)的function.php文件中,或者在任何插件文件中.
经过测试和工作.
内容总结
以上是互联网集市为您收集整理的php-在WooCommerce 3中“创建帐户”上方移动“结帐订单注释”字段全部内容,希望文章能够帮你解决php-在WooCommerce 3中“创建帐户”上方移动“结帐订单注释”字段所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。