Not possible in the rest API “apply” coupons, you can save the coupons lines, but will not try to calculate or check if is valid.
In the future it will be possible, of course, but not for now.
Thread Starter
ponnus
(@ponnus)
Thankyou for the reply.
While looking through the code of ‘create_order’ api endpoint, I found that the webhook for applying coupon is called there.
do_action( 'woocommerce_order_add_coupon', $this->id, $item_id, $code, $discount_amount, $discount_amount_tax );
in add_coupon(). But i didn’t find the add_action(‘woocommerce_order_add_coupon’,…). Can you tell me where should I write this action definition so that it shouldn’t get overwritten when updating woocommerce.
Thank you
@ponnus not sure what do you mean.
While looking through the code of ‘create_order’ api endpoint, I found that the webhook for applying coupon is called there.
We don’t trigger webhooks when applying coupons on orders using the REST API.
do_action( ‘woocommerce_order_add_coupon’, $this->id, $item_id, $code, $discount_amount, $discount_amount_tax );
in add_coupon().
This hooks is there for you hook anything, you can read more how to work with hooks here: https://codex.ww.wp.xz.cn/Plugin_API/Action_Reference
Can you tell me where should I write this action definition so that it shouldn’t get overwritten when updating woocommerce.
Not sure yet, but if you want hook and/or change some things, you definitely should create a plugin to do it.
Hello Claudio,
Can you tell us when it will be possible to apply “coupons” since this will be core to our integration with woocommerce.
Kindly
It actually seems to be too much tricky and/or redundant to add logic for something that is already implemented out of REST…
-
This reply was modified 9 years, 8 months ago by
enricodeleo.