I'm tying to enable the use of coupons to a range of hours in Woocommerce without success.
Based on Discount on specific products based on a daily time range in Woocommerce answer, my code is:
// Utility function that gives the discount daily period
function get_discount_period_rate(){
// Set the correct time zone (http://php.net/manual/en/timezones.php)
date_default_timezone_set('Europe/Paris');
// Set the start time and the end time
$start_time = mktime( 08, 00, 00, date("m") , date("d"), date("Y") );
$end_time = mktime( 09, 00, 00, date("m") , date("d"), date("Y") );
$time_now = strtotime("now");
}
// Set the coupon Ids that will be discounted
$wc_coupon = new WC_Coupon('integralia10'); // get intance of wc_coupon which code is "integralia10"
if (!$wc_coupon || !$wc_coupon->is_valid()) {
return;
}
$coupon_code = $wc_coupon->get_code();
if (!$coupon_code) {
return;
}
Also, I Would like to use the wc_print_notices
function to show a message when somemeone try to use the Coupon code out of time range.
Any Sugestion?