Wordpress Functions - Auto Apply Black Friday and Cyber Monday Promos

add_action( 'woocommerce_before_cart', 'apply_matched_coupons' ); function apply_matched_coupons() { global $woocommerce; if ( empty( $woocommerce->cart->applied_coupons ) ) { $coupon_code = 'blackfriday'; // your coupon code here $dateStart = mktime(0, 0, 0, 11, 22, 2016); $dateEnd = mktime(0, 0, 0, 11, 28, 2016); if (time() < $dateEnd && time() > $dateStart || isset($_GET['blackfriday'])){ $woocommerce->cart->add_discount( $coupon_code ); } $cybermonday_coupon_code = 'cybermonday'; // your coupon code here $cybermondaydateStart = mktime(0, 0, 0, 11, 28, 2016); $cybermondaydateEnd = mktime(0, 0, 0, 11, 29, 2016); if (time() < $cybermondaydateEnd && time() > $cybermondaydateStart){ $woocommerce->cart->add_discount( $cybermonday_coupon_code ); } } }
This snippet goes in the Wordpress functions.php file and will auto apply a given coupon during the specified date range. In this case it is the Black Friday weekend and Cyber Monday, 2016.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.