Skip to content

Commit

Permalink
Fix address fields mapping for Google Pay and UAE addresses (#3432)
Browse files Browse the repository at this point in the history
* Fix address fields mapping for Google Pay and UAE

* Add readme and changelog entries
  • Loading branch information
annemirasol authored Sep 16, 2024
1 parent c4f3deb commit 7f20b58
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
34 changes: 34 additions & 0 deletions includes/payment-methods/class-wc-stripe-payment-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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'] = '';
}
}
}
}
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 7f20b58

Please sign in to comment.