Forked from zgordon/update-woo-order-billing-when-user-saves-address.php
Created
September 20, 2019 06:31
-
-
Save EmranAhmed/b39511f6074e046be4a09669faa5915d to your computer and use it in GitHub Desktop.
Revisions
-
zgordon revised this gist
Jun 7, 2017 . 1 changed file with 17 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,10 @@ <?php add_action( 'woocommerce_customer_save_address', 'jsforwp_update_address_for_orders', 10, 2 ); function jsforwp_update_address_for_orders( $user_id ) { $customer_meta = get_user_meta( $user_id ); $customer_orders = get_posts( array( 'numberposts' => -1, 'meta_key' => '_customer_user', @@ -11,23 +13,22 @@ function custom_update_address_for_orders( $user_id ) { 'post_status' => array_keys( wc_get_order_statuses() ) ) ); foreach( $customer_orders as $order ) { update_post_meta( $order->ID, '_billing_first_name', $customer_meta['billing_first_name'][0] ); update_post_meta( $order->ID, '_billing_last_name', $customer_meta['billing_last_name'][0] ); update_post_meta( $order->ID, '_billing_company', $customer_meta['billing_company'][0] ); update_post_meta( $order->ID, '_billing_address_1', $customer_meta['billing_address_1'][0] ); update_post_meta( $order->ID, '_billing_address_2', $customer_meta['billing_address_2'][0] ); update_post_meta( $order->ID, '_billing_city', $customer_meta['billing_city'][0] ); update_post_meta( $order->ID, '_billing_state', $customer_meta['billing_state'][0] ); update_post_meta( $order->ID, '_billing_postcode', $customer_meta['billing_postcode'][0] ); update_post_meta( $order->ID, '_billing_country', $customer_meta['billing_country'][0] ); update_post_meta( $order->ID, '_billing_email', $customer_meta['billing_email'][0] ); update_post_meta( $order->ID, '_billing_phone', $customer_meta['billing_phone'][0] ); } }; ?> -
zgordon created this gist
Jun 7, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ <?php function custom_update_address_for_orders( $user_id ) { $customer_meta = get_user_meta( $user_id ); $customer_orders = get_posts( array( 'numberposts' => -1, 'meta_key' => '_customer_user', 'meta_value' => $user_id, 'post_type' => wc_get_order_types(), 'post_status' => array_keys( wc_get_order_statuses() ) ) ); foreach( $customer_orders as $order ) { update_post_meta( $order->ID, '_billing_first_name', $customer_meta['billing_first_name'][0] ); update_post_meta( $order->ID, '_billing_last_name', $customer_meta['billing_last_name'][0] ); update_post_meta( $order->ID, '_billing_company', $customer_meta['billing_company'][0] ); update_post_meta( $order->ID, '_billing_address_1', $customer_meta['billing_address_1'][0] ); update_post_meta( $order->ID, '_billing_address_2', $customer_meta['billing_address_2'][0] ); update_post_meta( $order->ID, '_billing_city', $customer_meta['billing_city'][0] ); update_post_meta( $order->ID, '_billing_state', $customer_meta['billing_state'][0] ); update_post_meta( $order->ID, '_billing_postcode', $customer_meta['billing_postcode'][0] ); update_post_meta( $order->ID, '_billing_country', $customer_meta['billing_country'][0] ); update_post_meta( $order->ID, '_billing_email', $customer_meta['billing_email'][0] ); update_post_meta( $order->ID, '_billing_phone', $customer_meta['billing_phone'][0] ); } }; add_action( 'woocommerce_customer_save_address', 'custom_update_address_for_orders', 10, 2 ); ?>