Porchy Web Development

WooCommerce Subscriptions: not able to purchase subscription after failed payment [edited on 2021-01-27]

This is a workaround and fix for the following situation which occurs in recent versions (<3.0.12) of WooCommerce Subscriptions. When purchasing a subscription which is limited to “any” (ie a user can only have one subscription of any status), the user cannot pay for a failed order as the subscription product gets removed from their basket.

If the order is an initial purchase where the payment for the parent order for a subscription has failed, the user or support team can work around this by setting the order status to cancelled which will allow the user to purchase the product again. If the order is a resubscribe, cancelling the resubscribe order with the failed payment does not work.

Reproduce

To reproduce the parent order issue:

  • Create an order with a failed status containing a subscription product which is limited to one of any status per user.
  • In the account pages of the user whose order it is, try to pay for that order. This will fail.
  • Cancel the order and try to purchase a new one. This will succeed.

To reproduce the resubscribe issues:

  • On a subscription which has been cancelled and to which the user can resubscribe, create a resubscribe order and set the order status to failed.
  • In the account pages of the user whose order it is, try to pay for that order. This will fail.
  • Cancel the order. There is now no way to resubscribe to the subscription.

Fixes

There are two fixes necessary for this. For the issue where failed payments remove the subscription from the cart when payment is attempted again, this patch fixes it and will be included in WooCommerce Subscriptions 3.0.13 (or whatever is after 3.0.12!). (Note to self: is there a diff highlighter in Prism? Add it if so.)

As a workaround before the patched version of Woo Subs is released, cancelling the parent order allows the user to purchase a subscription again. However, this does not work for resubscribes as there is a flaw in the logic in the check.

The patch for this is here and you can also use the filter in that function to work around it as below. This is simply applying the linked patch in a filter after the WCS function has run.

Edits on 2021-01-27

There was a fatal error in the resubscribe order check as occasionally wc_get_order( $resubscribe_order_id ) returned false. I added in a check to make sure it’s an order before checking the status.

Also, I realised I wanted the limited subscription check to check on_hold and active statuses when the limitation was “any” so I’ve added that in there.

Please see the comments in the code for exactly where both of those were added.

Join the newsletter

Subscribe to get the latest content by email.

Powered by ConvertKit. If you give me your email address, you may receive emails from me (JJ) about posts on this site. You can unsubscribe at any time.

Porchy Ltd is a company registered in England, no. 12035925

VAT Registration no. 331196421

Built with WPGraphQL and Gatsby

© 2019 - 2021