This PR handles two issues related to the mixed checkout.
When a simple product is added to cart with an existing subscription product and subscription rules avoid to have both types, Add to cart Ajax call gets a 500 response. The error is caused by trying to use non-existing function redirect_ajax_add_to_cart in WC_Subscriptions_Cart_Validator class.
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
When mixed checkout is disabled, and a subscription is in the cart when another product type is added, the customer is provided with a notice A subscription has been removed from your cart. Products and subscriptions can not be purchased at the same time. But when a subscription is added to the cart that already contains another product, no notice is provided.
Addressed this in https://github.com/Automattic/woocommerce-subscriptions-core/pull/606/commits/152cb9d7a5bcd717e8c107c8d181a301a1196b72, 6fdf3be,now showing a notice on the page when the other products are removed from the cart because of adding a subscription.
How to test this PR
Issue #130
Disabled mixed checkout from WooCommerce > Settings > Subscriptions.
Create a variable subscription. On the product edit page's Advance section, limit the subscription to one active subscription at a time.
As a shopper, add the variable subscription to the cart.
Now add another simple product to the cart.
The simple product should be added to the cart without any error.
Issue #560
Disabled mixed checkout from WooCommerce > Settings > Subscriptions.
As a shopper, add a subscription to the cart.
Now add another simple product to the cart. You should see the following notice on the page.
Clear the cart and add a subscription again.
Now add a second subscription to the cart. You should see the following notice on the page.
Clear the cart and add one or a couple of simple products to the cart.
Now add a subscription to the cart. You should see the following notice on the page.
Fixes #130 #560
Description
This PR handles two issues related to the mixed checkout.
In
WC_Subscriptions_Cart_Validator
class we were usingredirect_ajax_add_to_cart
as the callback which does not exist. This function is replaced byadd_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 theadd_to_cart_ajax_redirect
as the callback. I could not reproduce this issue but usingadd_to_cart_ajax_redirect
directly as the callback makes more sense here.A subscription has been removed from your cart. Products and subscriptions can not be purchased at the same time
. But when a subscription is added to the cart that already contains another product, no notice is provided. Addressed this in https://github.com/Automattic/woocommerce-subscriptions-core/pull/606/commits/152cb9d7a5bcd717e8c107c8d181a301a1196b72, 6fdf3be,now showing a notice on the page when the other products are removed from the cart because of adding a subscription.How to test this PR
Issue #130
Advance section
, limit the subscription to one active subscription at a time.Issue #560