What is the best WooCommerce hook for implementing custom coupons?

I have a plugin that allows using coupons stored on a separate system. I am using various filters (e.g., woocommerce_get_shop_coupon_data) so that any coupon code entered is also checked against a Web API to see if it’s a valid remote coupon. It’s then added to the cart and reflected in the total just like a normal WC coupon.

The issue arises when I want to update the coupon (e.g., increase usage count, decrease balance) when an order is placed. Right now I am using woocommerce_order_status_processing. But this is triggered too late and when redeeming the coupon fails, an order is placed anyway (even though I throw an exception).

What I really need is for payment and coupon redeeming to be an atomic process. But the biggest problem right now is that people can place orders with invalid coupon codes (again, these are not WC coupons!).

P.S. The coupons cannot be added to the cart if they’re invalid. The issues arises mainly when someone adds a valid coupon to two carts, then places an order for each card — the second order may have to be refused here.

Read more here: What is the best WooCommerce hook for implementing custom coupons?

Leave a Reply

Your email address will not be published. Required fields are marked *