Apply a coupon programmatically in Woocommerce
First, create a discount coupon (via http://docs.woothemes.com/document/create-a-coupon-programatically/): $coupon_code=”UNIQUECODE”; // Code – perhaps generate this from the user ID + the order ID $amount=”10″; // Amount $discount_type=”percent”; // 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 … Read more