Skip to content

Commit

Permalink
Add support for allowedShippingCountries in Express Checkout Element (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
asumaran authored Oct 29, 2024
1 parent 8d8bee3 commit d5819b0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
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

0 comments on commit d5819b0

Please sign in to comment.