I'm trying to create a coupon via the woocommerce rest api: https://woocommerce.github.io/woocommerce-rest-api-docs/#create-a-coupon
I can create coupons fine, but it seems the expiration date is always unset.
e.g. posting
{
"code": "IGNME",
"description": "IGNORE ME",
"discount_type": "percent",
"amount": 5,
"date_expires": "2024-03-21T19:23:00",
"date_expires_gmt": "2024-03-21T18:23:00"
}
Would return;
...
"date_expires": null,
"date_expires_gmt": null,
...
Checking on the site and there is no expiration date aswell. I tried date/time different formats but could not get a valid one.
How can I create woocommerce coupon with an expiration date using the rest api?
I'm not sure why, but apparently setting date_expires
in a meta field works, like in this sample:
curl -X POST https://.../wp-json/wc/v3/coupons -u XXX:YYYYY -H "Content-Type: application/json" -d '{ "code": "...", "discount_type": "percent", "amount": "10", "meta_data": [{"key": "date_expires", "value": "2024-03-12T08:00:00"}]}'