From faea811a92e067c2701cdc6f253dd098bc1aca75 Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Mon, 15 May 2017 17:09:02 -0400 Subject: [PATCH] =?UTF-8?q?Customer=20profile:=20Add=20a=20=E2=80=9CCopy?= =?UTF-8?q?=20from=20billing=E2=80=9D=20button=20to=20shipping=20user=20me?= =?UTF-8?q?ta=20fields?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/js/admin/users.js | 19 +++++++++++++++++++ includes/admin/class-wc-admin-profile.php | 13 +++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) 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 ); ?> /> + +