Skip to content

Commit 8ade783

Browse files
committed
Merge remote-tracking branch 'origin/release/5.8.1' into trunk
2 parents 9b6c4e8 + b10dd0e commit 8ade783

File tree

6 files changed

+54
-23
lines changed

6 files changed

+54
-23
lines changed

changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
*** Changelog ***
22

3+
= 5.8.1 - 2021-11-23 =
4+
* Fix - Run filters that disable Stripe JS on cart and product pages when PRBs are disabled.
5+
36
= 5.8.0 - 2021-11-18 =
47
* Fix - Hong Kong addresses are now mapped more thoroughly to WooCommerce addresses when paying with Apple Pay.
58
* Fix - Error when changing payment method for a subscription with new checkout experience.

includes/class-wc-stripe-helper.php

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -584,21 +584,57 @@ public static function should_enqueue_in_current_tab_section( $tab, $section ) {
584584
return true;
585585
}
586586

587+
/**
588+
* Returns true if the Stripe JS should be loaded on product pages.
589+
*
590+
* The critical part here is running the filter to allow merchants to disable Stripe's JS to
591+
* improve their store's performance when PRBs are disabled.
592+
*
593+
* @since 5.8.0
594+
* @return boolean True if Stripe's JS should be loaded, false otherwise.
595+
*/
587596
public static function should_load_scripts_on_product_page() {
588-
$prb_locations = self::get_settings( null, 'payment_request_button_locations' ) ?? [ 'product', 'cart' ];
589-
if ( ! in_array( 'product', $prb_locations, true ) ) {
590-
return apply_filters( 'wc_stripe_load_scripts_on_product_page_when_prbs_disabled', true );
597+
if ( self::should_load_scripts_for_prb_location( 'product' ) ) {
598+
return true;
591599
}
592600

593-
return true;
601+
return apply_filters( 'wc_stripe_load_scripts_on_product_page_when_prbs_disabled', true );
594602
}
595603

604+
/**
605+
* Returns true if the Stripe JS should be loaded on the cart page.
606+
*
607+
* The critical part here is running the filter to allow merchants to disable Stripe's JS to
608+
* improve their store's performance when PRBs are disabled.
609+
*
610+
* @since 5.8.0
611+
* @return boolean True if Stripe's JS should be loaded, false otherwise.
612+
*/
596613
public static function should_load_scripts_on_cart_page() {
597-
$prb_locations = self::get_settings( null, 'payment_request_button_locations' ) ?? [ 'product', 'cart' ];
598-
if ( ! in_array( 'cart', $prb_locations, true ) ) {
599-
return apply_filters( 'wc_stripe_load_scripts_on_cart_page_when_prbs_disabled', true );
614+
if ( self::should_load_scripts_for_prb_location( 'cart' ) ) {
615+
return true;
600616
}
601617

602-
return true;
618+
return apply_filters( 'wc_stripe_load_scripts_on_cart_page_when_prbs_disabled', true );
619+
}
620+
621+
/**
622+
* Returns true if the Stripe JS should be loaded for the provided location.
623+
*
624+
* @since 5.8.1
625+
* @param string $location Either 'product' or 'cart'. Used to specify which location to check.
626+
* @return boolean True if Stripe's JS should be loaded for the provided location, false otherwise.
627+
*/
628+
private static function should_load_scripts_for_prb_location( $location ) {
629+
// Make sure location parameter is sanitized.
630+
$location = in_array( $location, [ 'product', 'cart' ], true ) ? $location : '';
631+
$are_prbs_enabled = self::get_settings( null, 'payment_request' ) ?? 'yes';
632+
$prb_locations = self::get_settings( null, 'payment_request_button_locations' ) ?? [ 'product', 'cart' ];
633+
634+
// The scripts should be loaded when all of the following are true:
635+
// 1. The PRBs are enabled; and
636+
// 2. The PRB location settings have an array value (saving an empty option in the GUI results in non-array value); and
637+
// 3. The PRBs are enabled at $location.
638+
return 'yes' === $are_prbs_enabled && is_array( $prb_locations ) && in_array( $location, $prb_locations, true );
603639
}
604640
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "woocommerce-gateway-stripe",
33
"title": "WooCommerce Gateway Stripe",
4-
"version": "5.8.0",
4+
"version": "5.8.1",
55
"license": "GPL-3.0",
66
"homepage": "http://wordpress.org/plugins/woocommerce-gateway-stripe/",
77
"repository": {

readme.txt

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Tags: credit card, stripe, apple pay, payment request, google pay, sepa, sofort,
44
Requires at least: 5.6
55
Tested up to: 5.8
66
Requires PHP: 7.0
7-
Stable tag: 5.8.0
7+
Stable tag: 5.8.1
88
License: GPLv3
99
License URI: https://www.gnu.org/licenses/gpl-3.0.html
1010
Attributions: thorsten-stripe
@@ -128,15 +128,7 @@ If you get stuck, you can ask for help in the Plugin Forum.
128128

129129
== Changelog ==
130130

131-
= 5.8.0 - 2021-11-18 =
132-
* Fix - Hong Kong addresses are now mapped more thoroughly to WooCommerce addresses when paying with Apple Pay.
133-
* Fix - Error when changing payment method for a subscription with new checkout experience.
134-
* Fix - Payment Requests are now updated correctly when updating items in the Cart Block.
135-
* Add - Support for WooCommerce Pre-Orders with new checkout experience.
136-
* Fix - Stripe JS is no longer loaded on cart and product pages when PRBs are disabled on those pages.
137-
* Tweak - Update the minimum required PHP version to 7.0 to reflect our L-2 support policy.
138-
* Fix - Add support for MYR (Malaysian ringgit) for Alipay.
139-
* Add - New Settings UI.
140-
* Fix - Hide payment request button when variations of a variable product are out-of-stock.
131+
= 5.8.1 - 2021-11-23 =
132+
* Fix - Run filters that disable Stripe JS on cart and product pages when PRBs are disabled.
141133

142134
[See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

woocommerce-gateway-stripe.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Description: Take credit card payments on your store using Stripe.
66
* Author: WooCommerce
77
* Author URI: https://woocommerce.com/
8-
* Version: 5.8.0
8+
* Version: 5.8.1
99
* Requires at least: 5.6
1010
* Tested up to: 5.8
1111
* WC requires at least: 5.6
@@ -21,7 +21,7 @@
2121
/**
2222
* Required minimums and constants
2323
*/
24-
define( 'WC_STRIPE_VERSION', '5.8.0' ); // WRCS: DEFINED_VERSION.
24+
define( 'WC_STRIPE_VERSION', '5.8.1' ); // WRCS: DEFINED_VERSION.
2525
define( 'WC_STRIPE_MIN_PHP_VER', '7.0.0' );
2626
define( 'WC_STRIPE_MIN_WC_VER', '5.6' );
2727
define( 'WC_STRIPE_FUTURE_MIN_WC_VER', '5.7' );

0 commit comments

Comments
 (0)