Skip to content

Commit 900cc45

Browse files
committed
leverage isBnplAvailable for cart block
1 parent 68a42c2 commit 900cc45

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

client/cart/blocks/product-details.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,13 @@ const ProductDetail = ( { cart, context } ) => {
9292
country,
9393
paymentMethods,
9494
currencyCode,
95+
isBnplAvailable,
9596
} = window.wcpayStripeSiteMessaging;
9697

98+
if ( ! isBnplAvailable ) {
99+
return null;
100+
}
101+
97102
const amount = parseInt( cartTotal, 10 ) || 0;
98103

99104
const options = {

includes/class-wc-payments-payment-method-messaging-element.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ public function init() {
146146

147147
if ( $product ) {
148148
$script_data['isBnplAvailable'] = WC_Payments_Utils::is_any_bnpl_method_available( array_values( $bnpl_payment_methods ), $country, $currency_code, $product_price );
149+
} else {
150+
$script_data['isBnplAvailable'] = WC_Payments_Utils::is_any_bnpl_method_available( array_values( $bnpl_payment_methods ), $country, $currency_code );
149151
}
150152

151153
// Create script tag with config.

includes/class-wc-payments-utils.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,13 +856,18 @@ public static function get_bnpl_limits_per_currency( $payment_method ) {
856856
* @param float $price Product price.
857857
* @return bool True if any BNPL method is available, false otherwise.
858858
*/
859-
public static function is_any_bnpl_method_available( array $enabled_methods, string $country_code, string $currency_code, float $price ): bool {
859+
public static function is_any_bnpl_method_available( array $enabled_methods, string $country_code, string $currency_code, ?float $price = null ): bool {
860860
$price_in_cents = $price;
861861

862862
foreach ( $enabled_methods as $method ) {
863863
$limits = self::get_bnpl_limits_per_currency( $method );
864864

865865
if ( isset( $limits[ $currency_code ][ $country_code ] ) ) {
866+
// If no price provided, just check country/currency availability.
867+
if ( null === $price_in_cents ) {
868+
return true;
869+
}
870+
866871
$min_amount = $limits[ $currency_code ][ $country_code ]['min'];
867872
$max_amount = $limits[ $currency_code ][ $country_code ]['max'];
868873

0 commit comments

Comments
 (0)