$coupon_code, 'post_type' => 'shop_coupon', 'post_status' => 'publish', 'post_excerpt' => 'This is a dummy coupon' ) ); // Update meta update_post_meta( $coupon_id, 'discount_type', 'fixed_cart' ); update_post_meta( $coupon_id, 'coupon_amount', '1' ); update_post_meta( $coupon_id, 'individual_use', 'no' ); update_post_meta( $coupon_id, 'product_ids', '' ); update_post_meta( $coupon_id, 'exclude_product_ids', '' ); update_post_meta( $coupon_id, 'usage_limit', '' ); update_post_meta( $coupon_id, 'usage_limit_per_user', '' ); update_post_meta( $coupon_id, 'limit_usage_to_x_items', '' ); update_post_meta( $coupon_id, 'expiry_date', '' ); update_post_meta( $coupon_id, 'apply_before_tax', 'no' ); update_post_meta( $coupon_id, 'free_shipping', 'no' ); update_post_meta( $coupon_id, 'exclude_sale_items', 'no' ); update_post_meta( $coupon_id, 'product_categories', array() ); update_post_meta( $coupon_id, 'exclude_product_categories', array() ); update_post_meta( $coupon_id, 'minimum_amount', '' ); update_post_meta( $coupon_id, 'maximum_amount', '' ); update_post_meta( $coupon_id, 'customer_email', array() ); update_post_meta( $coupon_id, 'usage_count', '0' ); return new WC_Coupon( $coupon_code ); } /** * Delete a coupon * * @param $coupon_id * * @return bool */ public static function delete_coupon( $coupon_id ) { wp_delete_post( $coupon_id, true ); return true; } }