我在结帐页面中添加了一个自定义复选框,并试图在订单页面上获得结果。下面是我试过的。当我提交订单时,即使勾选了,也总是会导致“不适用”。
提前感谢您的帮助。
add_action( \'woocommerce_review_order_before_submit\', \'add_checkout_sign_optout_policy\', 9 );
function add_checkout_sign_optout_policy() {
woocommerce_form_field( \'nosign\', array(
\'type\' => \'checkbox\',
\'class\' => array(\'form-row nosign\'),
\'label_class\' => array(\'woocommerce-form__label woocommerce-form__label-for- checkbox checkbox\'),
\'input_class\' => array(\'woocommerce-form__input woocommerce-form__input-checkbox\'),
\'required\' => false,
\'label\' => \'I Opt-Out of Signature Upon Delivery and understand all <a href="" class="woocommerce-shipping-optout-link">Terms</a>.\',
));
}
/* Save "Terms and Conditions" */
// 1. Save Opt-Out as Order Meta
add_action( \'woocommerce_checkout_update_order_meta\', \'save_optout_acceptance\'
);
function save_optout_acceptance( $order_id ) {
if ( $_POST[\'nosign\'] ) update_post_meta( $order_id, \'nosign\', esc_attr( $_POST[\'nosign\'] ) );
}
// 2. Display Opt-Out Single Order Page
add_action( \'woocommerce_admin_order_data_after_billing_address\', \'display_optout_acceptance\' );
function display_optout_acceptance( $order ) {
if ( get_post_meta( $order->get_id(), \'nosign\', true ) == \'on\' ) {
echo \'<p><strong>Shipping Opt-Out: </strong>accepted</p>\';
} else echo \'<p><strong>Shipping Opt-Out: </strong>N/A</p>\';
}