From d5819b0720bae755d2de1d54b1720d12ac53c220 Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Tue, 29 Oct 2024 17:25:36 -0500 Subject: [PATCH] Add support for allowedShippingCountries in Express Checkout Element (#9592) --- ...-allowedshippingcountries-in-express-checkout-element | 4 ++++ .../blocks/hooks/use-express-checkout.js | 2 ++ client/express-checkout/index.js | 3 +++ ...class-wc-payments-express-checkout-button-handler.php | 9 +++++---- 4 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 changelog/9104-add-support-for-allowedshippingcountries-in-express-checkout-element diff --git a/changelog/9104-add-support-for-allowedshippingcountries-in-express-checkout-element b/changelog/9104-add-support-for-allowedshippingcountries-in-express-checkout-element new file mode 100644 index 00000000000..5eae7cb8972 --- /dev/null +++ b/changelog/9104-add-support-for-allowedshippingcountries-in-express-checkout-element @@ -0,0 +1,4 @@ +Significance: minor +Type: add + +Add support for allowedShippingCountries in Express Checkout Element. diff --git a/client/express-checkout/blocks/hooks/use-express-checkout.js b/client/express-checkout/blocks/hooks/use-express-checkout.js index 090a16354a7..88f72e76829 100644 --- a/client/express-checkout/blocks/hooks/use-express-checkout.js +++ b/client/express-checkout/blocks/hooks/use-express-checkout.js @@ -68,6 +68,8 @@ export const useExpressCheckout = ( { }; } ), + allowedShippingCountries: getExpressCheckoutData( 'checkout' ) + .allowed_shipping_countries, }; // Click event from WC Blocks. diff --git a/client/express-checkout/index.js b/client/express-checkout/index.js index f4efa4aa10f..535431b7fd1 100644 --- a/client/express-checkout/index.js +++ b/client/express-checkout/index.js @@ -304,6 +304,9 @@ jQuery( ( $ ) => { shippingAddressRequired: options.requestShipping, phoneNumberRequired: options.requestPhone, shippingRates, + allowedShippingCountries: getExpressCheckoutData( + 'checkout' + ).allowed_shipping_countries, }; onClickHandler( event ); diff --git a/includes/express-checkout/class-wc-payments-express-checkout-button-handler.php b/includes/express-checkout/class-wc-payments-express-checkout-button-handler.php index 682b4eac903..d024c3ba611 100644 --- a/includes/express-checkout/class-wc-payments-express-checkout-button-handler.php +++ b/includes/express-checkout/class-wc-payments-express-checkout-button-handler.php @@ -240,11 +240,12 @@ public function scripts() { 'pay_for_order' => wp_create_nonce( 'pay_for_order' ), ], 'checkout' => [ - 'currency_code' => strtolower( get_woocommerce_currency() ), - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), - 'needs_shipping' => WC()->cart->needs_shipping(), + 'currency_code' => strtolower( get_woocommerce_currency() ), + 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), + 'needs_shipping' => WC()->cart->needs_shipping(), // Defaults to 'required' to match how core initializes this option. - 'needs_payer_phone' => 'required' === get_option( 'woocommerce_checkout_phone_field', 'required' ), + 'needs_payer_phone' => 'required' === get_option( 'woocommerce_checkout_phone_field', 'required' ), + 'allowed_shipping_countries' => array_keys( WC()->countries->get_shipping_countries() ?? [] ), ], 'button' => $this->get_button_settings(), 'login_confirmation' => $this->get_login_confirmation_settings(),