I've been battling with this one in Woocommerce a while now. I have set up the following function to fire off when the customer pays. As I have added a some custom fields, I want to add them to the order meta value to later get that information:
add_action( 'woocommerce_checkout_update_order_meta', 'cesaa_saved_custom_fields', 10, 2 );
function cesaa_saved_custom_fields( $order_id, $post_values ) {
if ( !empty( $_POST['cesaa_member_id'] ) ) {
$result = update_post_meta( $order_id, 'cesaa_member_id', sanitize_text_field( $_POST['cesaa_member_id'] ) );
}
}
I've been debugging the function and it fires. The value $_POST['cesaa_member_id']is set but the update_post_meta fails because both $order_id, $post_values are always uninitialised.
Any clues on why this might be happening or what I could do to be able to debug this further?
Thanks!