Skip to content

Commit 1d4529c

Browse files
Feature/fix checkout form shipping fields visibility (woocommerce#54)
* Add verification of shipping state on update_checkout Show the shipping state if the shipping address state set on Amazon does not match the values in the WC dropdown. * Override Shipping State if Destination State doesn't exists in the country's states list
1 parent 004a510 commit 1d4529c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

assets/js/amazon-app-widgets.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,17 @@ jQuery( function( $ ) {
304304
return window.innerWidth <= 800;
305305
}
306306

307+
function toggleFieldVisibility( type, key ) {
308+
var fieldWrapper = $( '#' + type + '_' + key + '_field' ),
309+
fieldValue = $( '#' + type + '_' + key ).val();
310+
fieldWrapper.addClass( 'hidden' );
311+
$( '.woocommerce-' + type + '-fields' ).addClass( 'hidden' );
312+
if ( fieldValue == null || fieldValue == '' ) {
313+
fieldWrapper.removeClass( 'hidden' );
314+
$( '.woocommerce-' + type + '-fields' ).removeClass( 'hidden' );
315+
}
316+
}
317+
307318
function toggleDetailsVisibility( detailsListName ) {
308319
if ( $( '.' + detailsListName + '__field-wrapper' ).children( ':not(.hidden)' ).length === 0 ) {
309320
$( '.' + detailsListName ).addClass( 'hidden' );
@@ -672,6 +683,7 @@ jQuery( function( $ ) {
672683
}
673684

674685
$( 'body' ).on( 'updated_checkout', function() {
686+
toggleFieldVisibility( 'shipping', 'state' );
675687
if( ! isAmazonCheckout() ) {
676688
return;
677689
}

includes/class-wc-gateway-amazon-payments-advanced.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,15 @@ public function store_order_address_details( $order, $order_reference_details )
12771277
$shipping_info = WC_Amazon_Payments_Advanced_API::format_address( $destination );
12781278
// @codingStandardsIgnoreEnd
12791279

1280+
// Override Shipping State if Destination State doesn't exists in the country's states list.
1281+
$order_current_state = $order->get_shipping_state();
1282+
if ( ! empty( $order_current_state ) && $order_current_state !== $shipping_info['state'] ) {
1283+
$states = WC()->countries->get_states( $shipping_info['country'] );
1284+
if ( empty( $states ) || empty( $states[ $shipping_info['state'] ] ) ) {
1285+
$shipping_info['state'] = $order_current_state;
1286+
}
1287+
}
1288+
12801289
$order->set_address( $shipping_info, 'shipping' );
12811290

12821291
// Some market API endpoint return billing address information, parse it if present.

0 commit comments

Comments
 (0)