Load default country/state on edit

Closes #13061 Fixes #12899
This commit is contained in:
Mike Jolley 2017-02-08 10:55:57 +00:00
parent 3b06660edf
commit 649f55b494
3 changed files with 28 additions and 13 deletions

View File

@ -99,10 +99,26 @@ jQuery( function ( $ ) {
edit_address: function( e ) { edit_address: function( e ) {
e.preventDefault(); e.preventDefault();
$( this ).hide();
$( this ).parent().find( 'a:not(.edit_address)' ).show(); var $this = $( this ),
$( this ).closest( '.order_data_column' ).find( 'div.address' ).hide(); $wrapper = $this.closest( '.order_data_column' ),
$( this ).closest( '.order_data_column' ).find( 'div.edit_address' ).show(); $edit_address = $wrapper.find( 'div.edit_address' ),
$address = $wrapper.find( 'div.address' ),
$country_input = $edit_address.find( '.js_field-country' ),
$state_input = $edit_address.find( '.js_field-state' );
$address.hide();
$this.parent().find( 'a' ).toggle();
if ( ! $country_input.val() ) {
$country_input.val( woocommerce_admin_meta_boxes_order.default_country ).change();
}
if ( ! $state_input.val() ) {
$state_input.val( woocommerce_admin_meta_boxes_order.default_state ).change();
}
$edit_address.show();
}, },
change_customer_user: function() { change_customer_user: function() {

File diff suppressed because one or more lines are too long

View File

@ -214,19 +214,18 @@ class WC_Admin_Assets {
wp_localize_script( 'wc-admin-variation-meta-boxes', 'woocommerce_admin_meta_boxes_variations', $params ); wp_localize_script( 'wc-admin-variation-meta-boxes', 'woocommerce_admin_meta_boxes_variations', $params );
} }
if ( in_array( str_replace( 'edit-', '', $screen_id ), wc_get_order_types( 'order-meta-boxes' ) ) ) { if ( in_array( str_replace( 'edit-', '', $screen_id ), wc_get_order_types( 'order-meta-boxes' ) ) ) {
wp_register_script( 'wc-admin-order-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-order' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'wc-backbone-modal' ), WC_VERSION ); $default_location = wc_get_customer_default_location();
wp_enqueue_script( 'wc-admin-order-meta-boxes' );
$params = array( wp_enqueue_script( 'wc-admin-order-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-order' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'wc-backbone-modal' ), WC_VERSION );
wp_localize_script( 'wc-admin-order-meta-boxes', 'woocommerce_admin_meta_boxes_order', array(
'countries' => json_encode( array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ) ), 'countries' => json_encode( array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ) ),
'i18n_select_state_text' => esc_attr__( 'Select an option…', 'woocommerce' ), 'i18n_select_state_text' => esc_attr__( 'Select an option…', 'woocommerce' ),
); 'default_country' => isset( $default_location['country'] ) ? $default_location['country'] : '',
'default_state' => isset( $default_location['state'] ) ? $default_location['state'] : '',
wp_localize_script( 'wc-admin-order-meta-boxes', 'woocommerce_admin_meta_boxes_order', $params ); ) );
} }
if ( in_array( $screen_id, array( 'shop_coupon', 'edit-shop_coupon' ) ) ) { if ( in_array( $screen_id, array( 'shop_coupon', 'edit-shop_coupon' ) ) ) {
wp_register_script( 'wc-admin-coupon-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-coupon' . $suffix . '.js', array( 'wc-admin-meta-boxes' ), WC_VERSION ); wp_enqueue_script( 'wc-admin-coupon-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-coupon' . $suffix . '.js', array( 'wc-admin-meta-boxes' ), WC_VERSION );
wp_enqueue_script( 'wc-admin-coupon-meta-boxes' );
} }
if ( in_array( str_replace( 'edit-', '', $screen_id ), array_merge( array( 'shop_coupon', 'product' ), wc_get_order_types( 'order-meta-boxes' ) ) ) ) { if ( in_array( str_replace( 'edit-', '', $screen_id ), array_merge( array( 'shop_coupon', 'product' ), wc_get_order_types( 'order-meta-boxes' ) ) ) ) {
$post_id = isset( $post->ID ) ? $post->ID : ''; $post_id = isset( $post->ID ) ? $post->ID : '';