Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Woocommerce Orders Rest API: Add a coupon code

I have Visited The official WooCommerce Rest API documentation "Create an Order" section. I am trying to create an order via the API, but when I want to create the order with the apply coupon, I don't know how to make it.

How I will pass the coupon code as a discount when I create the order through the REST API?

In the related official documentation I don't find any request parameter to pass a coupon code or a discount.

Please suggest how to pass the coupon code when creating order via rest API in WooCommerce.

like image 695
Ajay Ghaghretiya Avatar asked Dec 24 '22 12:12

Ajay Ghaghretiya


1 Answers

You should need to add in your data array 'coupon_lines', something like:

    'coupon_lines' => [
        [
            'code' => 'mycouponcode',
            'discount' => '5',
            'discount_tax' => '0.75',
            'meta_data' => [
                [
                    'key' => 'coupon_data',
                    'value' => [
                        'id' => '1234',
                        'code' => 'mycouponcode',
                        'amount' => '10',
                        /* ... and so on ... */
                    ]
                ]
            ]
        ]
    ]

The meta_data array is all the woocommerce coupon meta data. This should work…

like image 181
LoicTheAztec Avatar answered Jan 05 '23 02:01

LoicTheAztec