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

Add support for allowedShippingCountries in Express Checkout Element #9592

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: add

Add support for allowedShippingCountries in Express Checkout Element.
2 changes: 2 additions & 0 deletions client/express-checkout/blocks/hooks/use-express-checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export const useExpressCheckout = ( {
};
}
),
allowedShippingCountries: getExpressCheckoutData( 'checkout' )
.allowed_shipping_countries,
};

// Click event from WC Blocks.
Expand Down
3 changes: 3 additions & 0 deletions client/express-checkout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ jQuery( ( $ ) => {
shippingAddressRequired: options.requestShipping,
phoneNumberRequired: options.requestPhone,
shippingRates,
allowedShippingCountries: getExpressCheckoutData(
'checkout'
).allowed_shipping_countries,
};

onClickHandler( event );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Loading