diff --git a/changelog/fix-issue-7607 b/changelog/fix-issue-7607 new file mode 100644 index 00000000000..2ece346eca0 --- /dev/null +++ b/changelog/fix-issue-7607 @@ -0,0 +1,4 @@ +Significance: minor +Type: fix + +Allow customers using express payment methods (eg Apple Pay, Google Pay) to create an account automatically when purchasing subscription products if the store settings allow. diff --git a/includes/class-wc-payments-payment-request-button-handler.php b/includes/class-wc-payments-payment-request-button-handler.php index 99a193ec303..414ce0fca37 100644 --- a/includes/class-wc-payments-payment-request-button-handler.php +++ b/includes/class-wc-payments-payment-request-button-handler.php @@ -118,10 +118,17 @@ public function is_authentication_required() { * @return bool */ public function is_account_creation_possible() { + $is_signup_from_checkout_allowed = 'yes' === get_option( 'woocommerce_enable_signup_and_login_from_checkout', 'no' ); + + // If a subscription is being purchased, check if account creation is allowed for subscriptions. + if ( ! $is_signup_from_checkout_allowed && $this->has_subscription_product() ) { + $is_signup_from_checkout_allowed = 'yes' === get_option( 'woocommerce_enable_signup_from_checkout_for_subscriptions', 'no' ); + } + // If automatically generate username/password are disabled, the Payment Request API // can't include any of those fields, so account creation is not possible. return ( - 'yes' === get_option( 'woocommerce_enable_signup_and_login_from_checkout', 'no' ) && + $is_signup_from_checkout_allowed && 'yes' === get_option( 'woocommerce_registration_generate_username', 'yes' ) && 'yes' === get_option( 'woocommerce_registration_generate_password', 'yes' ) ); @@ -620,11 +627,8 @@ public function has_subscription_product() { return true; } } elseif ( $this->is_checkout() || $this->is_cart() ) { - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); - if ( WC_Subscriptions_Product::is_subscription( $_product ) ) { - return true; - } + if ( WC_Subscriptions_Cart::cart_contains_subscription() ) { + return true; } } diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 07c08ef26c9..ecb5ea1088e 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -25,10 +25,12 @@ - + WC_Pre_Orders_Product WC_Subscriptions_Product WC_Subscriptions_Product + WC_Subscriptions_Cart + WC_Subscriptions_Cart