Woocommerce checkout issue
-
I have added a checkbox (not mandatory) in the checkout page by the following code:
add_action(‘woocommerce_before_order_notes’,
‘my_custom_checkout_field’);
function my_custom_checkout_field( $checkout ) {
echo ‘<div id=”my-new-field”><h3>’.__(”).'</h3>’;
woocommerce_form_field( ‘my_checkbox’, array(
‘type’ => ‘checkbox’,
‘class’ => array(‘input-checkbox’),
‘label’ => __(‘I care about the environment! Do not send me any cutlery and paper napkin with this order’),
‘required’ => false,
), $checkout->get_value( ‘my_checkbox’ ));echo ‘</div>’;
}/**
* Process the checkout
**/add_action(‘woocommerce_checkout_process’,
‘my_custom_checkout_field_process’);
function my_custom_checkout_field_process() {
global $woocommerce;
// Check if set, if its not set add an error.
}
/**
* Update the order meta with field value
**/add_action(‘woocommerce_checkout_update_order_meta’,
‘my_custom_checkout_field_update_order_meta’);
function my_custom_checkout_field_update_order_meta( $order_id ) {
if ($_POST[‘my_checkbox’]) update_post_meta( $order_id, ‘My
Checkbox’, esc_attr($_POST[‘my_checkbox’]));
}
But whether the user is clicking on the checkbox or not I am not able to find. Is there anyway I can find that?
Thank you for the help.
- The topic ‘Woocommerce checkout issue’ is closed to new replies.