禁止使用模板插件做违法内容(涉黄等),否则将受到法律的制裁。

wordpress woocommerce如何在结算页面添加自定义字段比如微信号

禁止使用模板插件做违法内容(涉黄等),否则将受到法律的制裁。

在woocommerce如果我们需要用户下单时填写微信号方便我们客服联系,可以在主题的functions.php里增加以下代码:

add_action('woocommerce_after_order_notes', 'custom_checkout_field');

function custom_checkout_field($checkout)

{

echo '<div id="custom_checkout_field">';

woocommerce_form_field('weixin', array(

'type' => 'text',

'class' => array(

'my-field-class form-row-wide'

) ,

'label' => __('微信号') ,

'placeholder' => '' ,

) ,

$checkout->get_value('weixin'));

echo '</div>';

}





//add_action('woocommerce_checkout_process', 'customised_checkout_field_process');

function customised_checkout_field_process()

{

// Show an error message if the field is not set.

if (!$_POST['weixin']) wc_add_notice(__('请填写微信号') , 'error');

}





add_action('woocommerce_checkout_update_order_meta', 'custom_checkout_field_update_order_meta');

function custom_checkout_field_update_order_meta($order_id)

{

if (!empty($_POST['weixin'])) {

update_post_meta($order_id, 'weixin',sanitize_text_field($_POST['weixin']));

}

}

0 个评论

 
联系
目前暂停一切业务,客服消息可能不会及时回复,谢谢理解。
在线咨询
    在线咨询
    禁止使用模板插件做违法内容(涉黄等),否则将受到法律的制裁。