Skip to content

Instantly share code, notes, and snippets.

View LiamBailey's full-sized avatar
💭
Build With Heart - Codeable.io

Liam Bailey LiamBailey

💭
Build With Heart - Codeable.io
View GitHub Profile
@thenbrent
thenbrent / products-plus-subscriptions.md
Last active December 27, 2015 17:19
Allowing Subscriptions & Products to be purchased in the same checkout.

Things that will need to be done:

  1. Unhook the WC_Subscriptions::maybe_empty_cart() and replace it with a similar function that doesn't empty the cart when a subscription is added (but does still call WC_Subscriptions::remove_subscriptions_from_cart() if the cart contains a subscription (WC_Subscriptions_Cart::cart_contains_subscription())
  2. You probably also want to remove the redirection to the checkout page immediately after a subscription is added to the cart. To do that, remove the WC_Subscriptions::add_to_cart_redirect() function from the 'add_to_cart_redirect' hook, or if you want to redirect to the cart page, use similar code to this: https://gist.github.com/thenbrent/7254424
  3. Make sure the totals are calculated correctly. This is the hard part. More details below.
  4. Make sure order line items show up correctly after purchase - I don't think you'll need to change anything here, hopefully it will just work.

To understand how totals are calculated, refer to the following functions:

  • `