diff --git a/assets/js/admin/users.js b/assets/js/admin/users.js index db2aa305f76..eada2c215bc 100644 --- a/assets/js/admin/users.js +++ b/assets/js/admin/users.js @@ -15,6 +15,8 @@ jQuery( function ( $ ) { $( '.js_field-country' ).select2().change( this.change_country ); $( '.js_field-country' ).trigger( 'change', [ true ] ); $( document.body ).on( 'change', 'select.js_field-state', this.change_state ); + + $( document.body ).on( 'click', 'button.js_copy-billing', this.copy_billing ); }, change_country: function( e, stickValue ) { @@ -75,6 +77,23 @@ jQuery( function ( $ ) { country = $country.val(); $country.data( 'woocommerce.stickState-' + country, state ); + }, + + copy_billing: function( event ) { + event.preventDefault(); + + $( '#fieldset-billing' ).find( 'input, select' ).each( function( i, el ) { + // The address keys match up, except for the prefix + var shipName = el.name.replace( /^billing_/, 'shipping_' ); + // Swap prefix, then check if there are any elements + var shipEl = $( '[name="' + shipName + '"]' ); + // No corresponding shipping field, skip this item + if ( ! shipEl.length ) { + return; + } + // Found a matching shipping element, update the value + shipEl.val( el.value ).trigger( 'change' ); + } ); } }; diff --git a/includes/admin/class-wc-admin-profile.php b/includes/admin/class-wc-admin-profile.php index 04f4ed6856f..39cffd3e2a4 100644 --- a/includes/admin/class-wc-admin-profile.php +++ b/includes/admin/class-wc-admin-profile.php @@ -93,6 +93,13 @@ class WC_Admin_Profile { 'shipping' => array( 'title' => __( 'Customer shipping address', 'woocommerce' ), 'fields' => array( + 'copy_billing' => array( + 'label' => __( 'Copy from billing address', 'woocommerce' ), + 'description' => '', + 'class' => 'js_copy-billing', + 'type' => 'button', + 'text' => __( 'Copy', 'woocommerce' ), + ), 'shipping_first_name' => array( 'label' => __( 'First name', 'woocommerce' ), 'description' => '', @@ -151,10 +158,10 @@ class WC_Admin_Profile { $show_fields = $this->get_customer_meta_fields(); - foreach ( $show_fields as $fieldset ) : + foreach ( $show_fields as $fieldset_key => $fieldset ) : ?>

- +
$field ) : ?> @@ -171,6 +178,8 @@ class WC_Admin_Profile { ID, $key, true ), 1, true ); ?> /> + +