1 回答
TA贡献1810条经验 获得超4个赞
通过以下方式尝试一下
function add_field_sendy_woocommerce_agree( $checkout ) {
woocommerce_form_field( 'sendy_woocommerce_agree', array(
'type' => 'checkbox',
'label' => __('Subscribe to our Newsletter.'),
'required' => false,
'default' => 1
), $checkout->get_value( 'sendy_woocommerce_agree' ));
}
add_filter( 'woocommerce_after_checkout_billing_form' , 'add_field_sendy_woocommerce_agree', 10, 1 );
// Save
function action_woocommerce_checkout_create_order( $order, $data ) {
if ( isset($_POST['sendy_woocommerce_agree']) && ! empty($_POST['sendy_woocommerce_agree']) ) {
$order->update_meta_data( 'sendy_woocommerce_agree', sanitize_text_field( $_POST['sendy_woocommerce_agree'] ) );
}
}
add_action( 'woocommerce_checkout_create_order', 'action_woocommerce_checkout_create_order', 10, 2 );
// Display the custom field value on admin order pages after billing adress:
function action_woocommerce_admin_order_data_after_billing_address( $order ) {
echo '<p><strong>'.__('Sendy').':</strong> ' . $order->get_meta('sendy_woocommerce_agree') . '</p>';
}
add_action( 'woocommerce_admin_order_data_after_billing_address', 'action_woocommerce_admin_order_data_after_billing_address', 10, 1 );
- 1 回答
- 0 关注
- 92 浏览
添加回答
举报