A lot changed in WooCommerce 3.0! One of the changes is that the woocommerce_checkout_update_order_meta action hook is deprecated. This hook was often used to save custom checkout field values to the order’s meta data. Here’s how to do it post 3.0 for anyone stuck in the same boat.
This should be pretty self explanatory. The new action hook is woocommerce_checkout_create_order, $custom_fields is an array of the custom field names that you registered as billing/shipping form fields (how to do this is another topic), and their values are saved as Order meta data with their keys prepended by a _.
Hi. I tried the woocommerce_checkout_update_order_meta hook. The woocommerce_checkout_update_user_meta hook worked for me. See my code below.
<?php
function davletov_save_company_fields( $user_id ) {
$custom_fields = array('your_custom_field1','your_custom_field2');
foreach ($custom_fields as $field) {
if ( $user_id && isset($_POST[$field]) ) {
update_user_meta( $user_id, $field, sanitize_text_field($_POST[$field]) );
}
}
}
add_action( 'woocommerce_checkout_update_user_meta', 'davletov_save_company_fields', 10, 2 );