I want to generate woocommerce coupon code dynamically.
My requirements is that after complete the order automatically generate one coupon code in admin side woocommerce coupon code list for particular product.
So any one know my above requirement solutions then please help me.
Thanks, Ketan.
Write a function which will fire when an order has been completed or placed using the
woocommerce_order_status_completed
orwoocommerce_order_status_processing
hook. Inside the function, usewp_insert_post
to create a post of type shop_coupon. Using wp_insert_post, you can specify the title of the coupon, amount etc.You can used
woocommerce_order_status_completed
action hook for order complete. and create post with post typeshop_coupon
for coupan usingwp_insert_post
. check below code