woocommerce
woocommerce copied to clipboard
Creating coupon with exiting code via REST API
Prerequisites
- [X] I have carried out troubleshooting steps and I believe I have found a bug.
- [X] I have searched for similar bugs in both open and closed issues and cannot find a duplicate.
Describe the bug
When creating a new coupon via RET API with an existing coupon code, the behaviour is different from the interface.
In both cases, an error message showed that "Coupon code already exists", but in the interface, let create a new coupon, but REST API refused to create it.
Expected behavior
Let REST API call create a new coupon with existing code.
Actual behavior
The REST API refused to create a new coupon with an exiting code.
Steps to reproduce
- Create coupon either in the interface or via REST API
- Create a new coupon with the same code via REST API
WordPress Environment
I happy to send it privately, but not publicly.
As a WC extension developer, I know this behaviour come from plugins/woocommerce/includes/rest-api/Controllers/Version1/class-wc-rest-coupons-v1-controller.php
Isolating the problem
- [X] I have deactivated other plugins and confirmed this bug occurs when only WooCommerce plugin is active.
- [X] This bug happens with a default WordPress theme active, or Storefront.
- [X] I can reproduce this bug consistently using the steps above.
Thanks, we see the same however we are going to review to determine the best course of action.
I'd also be interested to know: what is the advantage in your specific case of creating a duplicate (in terms of the coupon code itself, even if the discount amount varies, etc), vs re-using the existing coupon code and adjusting it as needed?
Hi,
The advantage would be the same behaviour as in the admin area, no matter the reason. Strictly speaking, I also think this difference is a "usability bug".
For background information:
We are the developer of the WooCommerce Zapier extension, and our users usually aren't as technical. So they expect that the result would be the same if they do the same task in the admin area or via Zapier automation. As the plugin part of our integration is mostly thin automation on top of WooCommerce services, in this case, the core action is just calling the appropriate REST API endpoint.
I had to mention that our users can add a step to their automation to delete the existing coupon before creating a new one as a workaround.