I created function that adds checkbox to the WooCommerce checkout after billing form.
Checkbox appears, everything looks OK on the front end.
add_filter( 'woocommerce_after_checkout_billing_form' , 'add_field_sendy_woocommerce_agree', 9);
function add_field_sendy_woocommerce_agree( ) {
woocommerce_form_field( 'sendy_woocommerce_agree', array(
'type' => 'checkbox',
'label' => __('Subscribe to our Newsletter.'),
'required' => false,
'default' => 1
), WC()->checkout->get_value( 'sendy_woocommerce_agree' ));
}
The problem is that checkbox is not saved as metadata. In the wp_postmeta
table, _sendy_woocommerce_agree
meta key is missing after submission.
So I can not access it with $xyz = $order->get_meta( '_sendy_woocommerce_agree' );
What am I doing wrong?