Automattic / woocommerce-subscriptions-core

Subscriptions core package for WooCommerce
Other
80 stars 29 forks source link

Fix issue with disabled mixed checkout #606

Closed Mayisha closed 2 months ago

Mayisha commented 2 months ago

Fixes #130 #560

Description

This PR handles two issues related to the mixed checkout.

PHP Fatal error:  Uncaught TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, class WC_Subscriptions_Cart_Validator does not have a method "redirect_ajax_add_to_cart" in C:\xampp\htdocs\testsubscriptions\wp-includes\class-wp-hook.php:307

In WC_Subscriptions_Cart_Validator class we were using redirect_ajax_add_to_cart as the callback which does not exist. This function is replaced by add_to_cart_ajax_redirect, handled by the deprecation handler class. In https://github.com/Automattic/woocommerce-subscriptions-core/pull/606/commits/118ef402104c54fbef89f2b788294954ee416259, I am now directly using the add_to_cart_ajax_redirect as the callback. I could not reproduce this issue but using add_to_cart_ajax_redirect directly as the callback makes more sense here.

How to test this PR

Issue #130

  1. Disabled mixed checkout from WooCommerce > Settings > Subscriptions.
  2. Create a variable subscription. On the product edit page's Advance section, limit the subscription to one active subscription at a time.
  3. As a shopper, add the variable subscription to the cart.
  4. Now add another simple product to the cart.
  5. The simple product should be added to the cart without any error.

Issue #560

  1. Disabled mixed checkout from WooCommerce > Settings > Subscriptions.
  2. As a shopper, add a subscription to the cart.
  3. Now add another simple product to the cart. You should see the following notice on the page.

sub for prod

  1. Clear the cart and add a subscription again.
  2. Now add a second subscription to the cart. You should see the following notice on the page.

subs

  1. Clear the cart and add one or a couple of simple products to the cart.
  2. Now add a subscription to the cart. You should see the following notice on the page.

product message