18

I am developing an application using WooCommerce rest API v3. Now I'm trying to integrate coupons from my WooCommerce website to my application. I'm creating order and applying coupons like this

"coupon_lines":[{
    'code'=>'coupon1',
    'amount'=>'1.00'
}]

I've set a usage limit per user in woocommerce website.

When I ordered directly from the website, usage restrictions are applied correctly. i.e, a user cannot use a coupon when a limit is reached. But when I make an order via REST API, the restrictions are not applied.

Additionally, I got a reply from another forum stating that coupon apply feature is not yet available via rest API. But, 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 anyone tell me where should I write this action definition so that it shouldn't get overwritten when updating WooCommerce?

Krupal Panchal
  • 1,428
  • 2
  • 8
  • 22
SatheeshCK17
  • 449
  • 3
  • 14
  • 1
    I got reply from another forum stating that coupon apply feature is not yet available via rest api.But, 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 anyonetell me where should I write this action definition so that it shouldn't get overwritten when updating woocommerce. – SatheeshCK17 Apr 10 '16 at 04:45
  • Write it in a separate plugin file. – Jack Robson Aug 30 '18 at 18:42

2 Answers2

1

you need to add "coupon_lines" to your order object as stated here Every order should have and "coupon_lines" array containing "id","code","amount" for you desired coupon.

https://woocommerce.github.io/woocommerce-rest-api-docs/v3.html#view-customer-orders

'coupon_lines' => [
    [
        'id' => 55,
        'code' => free50,
        'amount' => '10.75',
    ]
]
Gulshan kumar
  • 193
  • 1
  • 7
0

Can you please add coupons id and after check?

"coupon_lines":[{
        'id' => '',
        'code'=>'coupon1',
        'amount'=>'1.00'
}]
Purvik Dhorajiya
  • 3,880
  • 3
  • 28
  • 40