Skip to content

Commit 7976363

Browse files
authored
update: add wcpay_express_checkout_js_params filter (#10824)
1 parent b7ef201 commit 7976363

File tree

2 files changed

+49
-32
lines changed

2 files changed

+49
-32
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: update
3+
4+
update: add `wcpay_express_checkout_js_params` filter for express checkout JS params.

includes/express-checkout/class-wc-payments-express-checkout-button-handler.php

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -218,38 +218,51 @@ public function is_account_creation_possible() {
218218
* @return array Parameters for Express Checkout.
219219
*/
220220
public function get_express_checkout_params() {
221-
return [
222-
'ajax_url' => admin_url( 'admin-ajax.php' ),
223-
'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
224-
'stripe' => [
225-
'publishableKey' => $this->account->get_publishable_key( WC_Payments::mode()->is_test() ),
226-
'accountId' => $this->account->get_stripe_account_id(),
227-
'locale' => WC_Payments_Utils::convert_to_stripe_locale( get_locale() ),
228-
],
229-
'nonce' => [
230-
'platform_tracker' => wp_create_nonce( 'platform_tracks_nonce' ),
231-
// needed to communicate via the Store API.
232-
'tokenized_cart_nonce' => wp_create_nonce( 'woopayments_tokenized_cart_nonce' ),
233-
'tokenized_cart_session_nonce' => wp_create_nonce( 'woopayments_tokenized_cart_session_nonce' ),
234-
'store_api_nonce' => wp_create_nonce( 'wc_store_api' ),
235-
],
236-
'checkout' => [
237-
'currency_code' => strtolower( get_woocommerce_currency() ),
238-
'currency_decimals' => WC_Payments::get_localization_service()->get_currency_format( get_woocommerce_currency() )['num_decimals'],
239-
'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
240-
'needs_shipping' => WC()->cart->needs_shipping(),
241-
// Defaults to 'required' to match how core initializes this option.
242-
'needs_payer_phone' => 'required' === get_option( 'woocommerce_checkout_phone_field', 'required' ),
243-
'allowed_shipping_countries' => array_keys( WC()->countries->get_shipping_countries() ?? [] ),
244-
'display_prices_with_tax' => 'incl' === get_option( 'woocommerce_tax_display_cart' ),
245-
],
246-
'button' => $this->get_button_settings(),
247-
'login_confirmation' => $this->get_login_confirmation_settings(),
248-
'button_context' => $this->express_checkout_helper->get_button_context(),
249-
'has_block' => has_block( 'woocommerce/cart' ) || has_block( 'woocommerce/checkout' ),
250-
'product' => $this->express_checkout_helper->get_product_data(),
251-
'store_name' => get_bloginfo( 'name' ),
252-
];
221+
/**
222+
* Allowing some specific configuration to be tweaked by 3pd.
223+
*
224+
* @since 9.5.0
225+
*/
226+
return array_merge(
227+
apply_filters(
228+
'wcpay_express_checkout_js_params',
229+
[
230+
'ajax_url' => admin_url( 'admin-ajax.php' ),
231+
'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
232+
'nonce' => [
233+
'platform_tracker' => wp_create_nonce( 'platform_tracks_nonce' ),
234+
// needed to communicate via the Store API.
235+
'tokenized_cart_nonce' => wp_create_nonce( 'woopayments_tokenized_cart_nonce' ),
236+
'tokenized_cart_session_nonce' => wp_create_nonce( 'woopayments_tokenized_cart_session_nonce' ),
237+
'store_api_nonce' => wp_create_nonce( 'wc_store_api' ),
238+
],
239+
'checkout' => [
240+
'currency_code' => strtolower( get_woocommerce_currency() ),
241+
'currency_decimals' => WC_Payments::get_localization_service()->get_currency_format( get_woocommerce_currency() )['num_decimals'],
242+
'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
243+
'needs_shipping' => WC()->cart->needs_shipping(),
244+
// Defaults to 'required' to match how core initializes this option.
245+
'needs_payer_phone' => 'required' === get_option( 'woocommerce_checkout_phone_field', 'required' ),
246+
'allowed_shipping_countries' => array_keys( WC()->countries->get_shipping_countries() ?? [] ),
247+
'display_prices_with_tax' => 'incl' === get_option( 'woocommerce_tax_display_cart' ),
248+
],
249+
'button' => $this->get_button_settings(),
250+
'login_confirmation' => $this->get_login_confirmation_settings(),
251+
'button_context' => $this->express_checkout_helper->get_button_context(),
252+
'has_block' => has_block( 'woocommerce/cart' ) || has_block( 'woocommerce/checkout' ),
253+
'product' => $this->express_checkout_helper->get_product_data(),
254+
'store_name' => get_bloginfo( 'name' ),
255+
]
256+
),
257+
[
258+
// placing these outside of the filter to prevent modification of the values.
259+
'stripe' => [
260+
'publishableKey' => $this->account->get_publishable_key( WC_Payments::mode()->is_test() ),
261+
'accountId' => $this->account->get_stripe_account_id(),
262+
'locale' => WC_Payments_Utils::convert_to_stripe_locale( get_locale() ),
263+
],
264+
]
265+
);
253266
}
254267

255268
/**

0 commit comments

Comments
 (0)