Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix address fields mapping for Google Pay and UAE addresses #3432

Merged
merged 5 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading