woocommerce / woocommerce-subscriptions-do-not-reduce-stock-on-renewal

Don't reduce a product's inventory for renewal orders processed by WooCommerce Subscriptions.
GNU General Public License v3.0
7 stars 2 forks source link

Increase on cancellation? #2

Closed petertwise closed 7 years ago

petertwise commented 7 years ago

Anyone know what hook to use to increase an item's stock by one when an active subscription for that item is canceled?

james-allan commented 7 years ago

@squarecandy there are quite a few hooks you can use. You can find them all here https://github.com/Prospress/woocommerce-subscriptions/blob/master/includes/class-wc-subscription.php#L544-L550

The woocommerce_subscription_status_updated action is triggered on every status change so you would need to check which status the subscription is changing to. The new status is the 2nd argument.

If you only specifically need active to cancelled status transitions you can use the dynamic hook woocommerce_subscription_status_active_to_cancelled.

petertwise commented 7 years ago

Thanks James!

The link above is broken - here's the one I found working in case anyone else stumbles upon this: https://github.com/wp-premium/woocommerce-subscriptions/blob/master/includes/class-wc-subscription.php

do_action( 'woocommerce_subscription_status_' . $this->status_transition['from'] . '_to_' . $this->status_transition['to'], $this ); This is awesome - mirrors the core {old_status}to{new_status} hook nicely.