woocommerce create coupon programmatically

/**
* Create a coupon programatically
*/
$coupon_code = 'UNIQUECODE'; // Code
$amount = '10'; // Amount
$discount_type = 'fixed_cart'; // Type: fixed_cart, percent, fixed_product, percent_product

$coupon = array(
'post_title' => $coupon_code,
'post_content' => '',
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'shop_coupon');

$new_coupon_id = wp_insert_post( $coupon );

// Add meta
update_post_meta( $new_coupon_id, 'discount_type', $discount_type );
update_post_meta( $new_coupon_id, 'coupon_amount', $amount );
update_post_meta( $new_coupon_id, 'individual_use', 'no' );
update_post_meta( $new_coupon_id, 'product_ids', '' );
update_post_meta( $new_coupon_id, 'exclude_product_ids', '' );
update_post_meta( $new_coupon_id, 'usage_limit', '' );
update_post_meta( $new_coupon_id, 'expiry_date', '' );
update_post_meta( $new_coupon_id, 'apply_before_tax', 'yes' );
update_post_meta( $new_coupon_id, 'free_shipping', 'no' );


Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
how to setup woocommerce coupon wordpress woocommerce Coupon woocommerce coupon how to use sell coupon codes woocommerce add coupon code via ajax woocommerce woocommerce coupon template woocommerce coupon message how do coupon work for woocommerce how to work coupon code in woocommerce how to use coupons woocommerce get coupons woocommerce programmatically create coupon programatically woocommerce_get_shop_coupon_data woocommerce coupon code template generate coupon woocommerce php wooocommerce create a coupon edit woocommerce coupon code woocommerce generate coupon code create custom coupon code programmatically woocommerce coupon code in woocommerce programmatically add custom coupon woo programmatically how to create coupon code in woocommerce woocommerce add coupon to cart programmatically woocommerce add couponto cart programmatically apply coupon programmatically after registration woocomerce woocommerce apply coupon to registration custom code woocommerce create coupon programatically woocomemrce coupon apply programatically custom coupon woocommerce custom coupon. woocommerce woocommerce programmatically create coupon item create custom coupon type woocommerce create custom coupon woocommerce add coupon code in woocommerce woocommerce add discount programmatically add coupon code woocommerce woocommerce generate coupon for purchase woocommerce generate coupon how to add a coupon to woocommerce how to create a coupon in woocommerce how to generate coupon code in woocommerce add coupon woocommerce how to add coupon code in woocommerce where to make coupons in woocommerce woocommerce add coupon how to add coupon code in wordpress woocommerce how make coupons in woocommerce add coupons woocommerce woocommerce programmatically apply coupon woocommerce programmatically add coupon woocommerce sell coupon codes woocommerce coupon on registration woocommerce edit coupon code box wordpress woocommerce coupon code woocommerce custom discount programmatically woocommerce generate coupon code programmatically woocommerce coupon automatic coupon free woocommerce coupon automatic coupon WooCommerce coupon restrictions programmatically woocommerce generate discount code woocommerce use coupon button create coupon php woocommerce woocommerce make coupons woocommerce coupon by tag programmatically woocommerce add coupon programmatically how to create coupon for tag woocommerce create coupon woocommerce woocommerce change coupon code text woocommerce create coupon Woocommerce plugin coupon codes create coupon code woocommerce woocommerce add coupon programmatically woocommerce custom add coupon woocommerce custom add coupon code woocommerce create coupon code programmatically woocommerce coupon codes woocommerce how to add coupon in woocommerce woocommerce how to define coupon code wordpress apply coupon programmatically woocommerce woocommerce add coupon automatically coupon code in woocommerce coupon link woocommerce woocommerce coupon code woocommerce apply coupon programmatically woocommerce coupon programmatically apply coupon code programmatically woocommerce woocommerce coupon apply coupon in woocommerce woocommerce create coupon programmatically
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source