Skip to content

Commit

Permalink
Allow customers to create an account automatically via Express Paymen…
Browse files Browse the repository at this point in the history
…t methods the subscription setting allows it (#7617)

Co-authored-by: Matt Allan <[email protected]>
  • Loading branch information
james-allan and mattallan authored Nov 7, 2023
1 parent d788b1f commit e56b4e5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-issue-7607
Original file line number Diff line number Diff line change
@@ -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.
16 changes: 10 additions & 6 deletions includes/class-wc-payments-payment-request-button-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' )
);
Expand Down Expand Up @@ -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;
}
}

Expand Down
4 changes: 3 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
</UndefinedClass>
</file>
<file src="includes/class-wc-payments-payment-request-button-handler.php">
<UndefinedClass occurrences="3">
<UndefinedClass occurrences="4">
<code>WC_Pre_Orders_Product</code>
<code>WC_Subscriptions_Product</code>
<code>WC_Subscriptions_Product</code>
<code>WC_Subscriptions_Cart</code>
<code>WC_Subscriptions_Cart</code>
</UndefinedClass>
</file>
<file src="includes/class-wc-payments.php">
Expand Down

0 comments on commit e56b4e5

Please sign in to comment.