Woocommerce not saving custom field
Question
Basically, I have a function which should add custom fields depending on a cart quantity.
But it wasn’t working. I started debugging and this is my function and it doesn’t save posted custom field and I can’t figure out why.
add_action('woocommerce_after_checkout_billing_form', 'custom_checkout_field');
function custom_checkout_field($checkout){
echo '<div><h4>Passenger</h4>';
woocommerce_form_field('passenger_birthdate_2', array(
'type' => 'text',
'label' => 'Date of birth',
'required' => true,
),
$checkout->get_value('passenger_birthdate_2'));
echo '</div>';
}
add_action('woocommerce_checkout_update_order_meta', 'custom_checkout_field_update_order_meta');
function custom_checkout_field_update_order_meta( $order_id ) {
if ($_POST['passenger_birthdate_2']) update_post_meta($order_id, 'passenger_birthdate_2', sanitize_text_field($_POST['passenger_birthdate_2']));
}
Am I missing something?
0
9 months
2022-09-06T18:12:09-05:00
2022-09-06T18:12:09-05:00 0 Answers
0 views
0
Leave an answer