diff --git a/changelog.txt b/changelog.txt index f1a070948..824527423 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,6 +1,7 @@ *** Changelog *** = 8.8.0 - xxxx-xx-xx = +* Fix - Fix Google Pay address fields mapping for UAE addresses. * Tweak - Render the Klarna payment page in the store locale. * Tweak - Update the Apple Pay domain registration flow to use the new Stripe API endpoint. * Fix - Fix empty error message for Express Payments when order creation fails. diff --git a/includes/payment-methods/class-wc-stripe-payment-request.php b/includes/payment-methods/class-wc-stripe-payment-request.php index bca2a2801..660e6ea40 100644 --- a/includes/payment-methods/class-wc-stripe-payment-request.php +++ b/includes/payment-methods/class-wc-stripe-payment-request.php @@ -1698,6 +1698,8 @@ public function ajax_create_order() { define( 'WOOCOMMERCE_CHECKOUT', true ); } + $this->fix_address_fields_mapping(); + // Normalizes billing and shipping state values. $this->normalize_state(); @@ -2071,4 +2073,36 @@ private function maybe_restore_recurring_chosen_shipping_methods( $previous_chos WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); } + + /** + * Performs special mapping for address fields for specific contexts. + */ + private function fix_address_fields_mapping() { + $billing_country = ! empty( $_POST['billing_country'] ) ? wc_clean( wp_unslash( $_POST['billing_country'] ) ) : ''; + $shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( wp_unslash( $_POST['shipping_country'] ) ) : ''; + + // For UAE, Google Pay stores the emirate in "region", which gets mapped to the "state" field, + // but WooCommerce expects it in the "city" field. + if ( 'AE' === $billing_country ) { + $billing_state = ! empty( $_POST['billing_state'] ) ? wc_clean( wp_unslash( $_POST['billing_state'] ) ) : ''; + $billing_city = ! empty( $_POST['billing_city'] ) ? wc_clean( wp_unslash( $_POST['billing_city'] ) ) : ''; + + // Move the state (emirate) to the city field. + if ( empty( $billing_city ) && ! empty( $billing_state ) ) { + $_POST['billing_city'] = $billing_state; + $_POST['billing_state'] = ''; + } + } + + if ( 'AE' === $shipping_country ) { + $shipping_state = ! empty( $_POST['shipping_state'] ) ? wc_clean( wp_unslash( $_POST['shipping_state'] ) ) : ''; + $shipping_city = ! empty( $_POST['shipping_city'] ) ? wc_clean( wp_unslash( $_POST['shipping_city'] ) ) : ''; + + // Move the state (emirate) to the city field. + if ( empty( $shipping_city ) && ! empty( $shipping_state ) ) { + $_POST['shipping_city'] = $shipping_state; + $_POST['shipping_state'] = ''; + } + } + } } diff --git a/readme.txt b/readme.txt index ec29486b6..3ebd0ca25 100644 --- a/readme.txt +++ b/readme.txt @@ -129,6 +129,7 @@ If you get stuck, you can ask for help in the Plugin Forum. == Changelog == = 8.8.0 - xxxx-xx-xx = +* Fix - Fix Google Pay address fields mapping for UAE addresses. * Tweak - Render the Klarna payment page in the store locale. * Tweak - Update the Apple Pay domain registration flow to use the new Stripe API endpoint. * Fix - Resolve an error for checkout block where 'wc_stripe_upe_params' is undefined due to the script registering the variable not being loaded yet.