Advertisement
olie480

WOOCOMMERCE: Create a Coupon Programatically

Nov 18th, 2013
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 KB | None | 0 0
  1. $coupon_code = 'UNIQUECODE'; // Code
  2. $amount = '10'; // Amount
  3. $discount_type = 'fixed_cart'; // Type: fixed_cart, percent, fixed_product, percent_product
  4.  
  5. $coupon = array(
  6. 'post_title' => $coupon_code,
  7. 'post_content' => '',
  8. 'post_status' => 'publish',
  9. 'post_author' => 1,
  10. 'post_type' => 'shop_coupon'
  11. );
  12.  
  13. $new_coupon_id = wp_insert_post( $coupon );
  14.  
  15. // Add meta
  16. update_post_meta( $new_coupon_id, 'discount_type', $discount_type );
  17. update_post_meta( $new_coupon_id, 'coupon_amount', $amount );
  18. update_post_meta( $new_coupon_id, 'individual_use', 'no' );
  19. update_post_meta( $new_coupon_id, 'product_ids', '' );
  20. update_post_meta( $new_coupon_id, 'exclude_product_ids', '' );
  21. update_post_meta( $new_coupon_id, 'usage_limit', '' );
  22. update_post_meta( $new_coupon_id, 'expiry_date', '' );
  23. update_post_meta( $new_coupon_id, 'apply_before_tax', 'yes' );
  24. update_post_meta( $new_coupon_id, 'free_shipping', 'no' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement