Update usermeta after checkout
-
someone can help me to update user meta field after checkout complete?
i already have snippet to sync userprofile meta data with wocoommerce billing field
add_filter( 'profile_update' , 'custom_update_checkout_fields', 10, 2 ); function custom_update_checkout_fields($user_id, $old_user_data ) { $current_user = wp_get_current_user(); // Updating Billing info if($current_user->user_firstname != $current_user->billing_first_name) update_user_meta($user_id, 'billing_first_name', $current_user->user_firstname); if($current_user->user_lastname != $current_user->billing_last_name) update_user_meta($user_id, 'billing_last_name', $current_user->user_lastname); if($current_user->user_email != $current_user->billing_email) update_user_meta($user_id, 'billing_email', $current_user->user_email); if($current_user->company != $current_user->billing_company) update_user_meta($user_id, 'billing_company', $current_user->company); if($current_user->telefono != $current_user->billing_phone) update_user_meta($user_id, 'billing_phone', $current_user->telefono); if($current_user->vat != $current_user->billing_piva) update_user_meta($user_id, 'billing_piva', $current_user->vat); if($current_user->sdi != $current_user->billing_code_sdi) update_user_meta($user_id, 'billing_code_sdi', $current_user->sdi); }
wish to do the same if customer change some chckout field… without success
im using this snipped but not works
add_action( 'woocommerce_thankyou', 'update_usermeta_from_billing_checkout' ); function update_usermeta_from_billing_checkout( $user_id ) { $order = wc_get_order( $order_id ); update_user_meta( $user_id, 'first_name', $order->get_billing_first_name() ); update_user_meta( $user_id, 'last_name', $order->get_billing_last_name() ); update_user_meta( $user_id, 'vat', $order->get_billing_piva() ); update_user_meta( $user_id, 'sdi', $order->get_billing_code_sdi() ); update_user_meta( $user_id, 'telefono', $order->get_billing_phone() ); }
someone please can help?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Update usermeta after checkout’ is closed to new replies.