• Resolved kimnikita0909

    (@kimnikita0909)


    How can i close or open coupon depending on the time and date of delivery, which are indicated on the checkout page

    I HAVE FUNCTIONS ON FUNCTION.PHP, WHICH CHECK DIFFERENT CONDITIONS FOR THE COUPON TO WORK, but i want add new condition that would check the date and time of food delivery

    function isWeekend() {
    
    $a = date(‘w’,strtotime(“now”));
    
    if($a == 0 || $a == 6) {
    
    return true;
    
    }
    
    else {
    
    return false;
    
    }
    
    }
    
     
    
    function isChill($date){
    
    $holydays = [
    
    ‘09.05’ => ‘День Победы’,
    
    ‘01.01’ => ‘Новый год’,
    
    ‘08.03’ => ‘8 марта’,
    
    ‘23.02’ => ’23 февраля’,
    
    ‘14.02’ => ‘День влюбленных’,
    
    ‘01.05’ => ‘1 марта’,
    
    ‘04.11’=>’День единства’,
    
    ‘12.06’=>’День россии’];
    
    $datte = date(“d.m”, $date);
    
    # Получаем текущую дату (день и месяц)
    
    if (isset($holydays[$datte])) {
    
    return true;
    
    }
    
    return false;
    
    }
    
     
    
    function time_range_coupon_id( $coupon_id ) {
    
    // For specific coupon ID’s only, several could be added, separated by a comma
    
    // $specific_coupons_ids = array(10700,10700);
    
     
    
    // Coupon ID in array, so check
    
    if ($coupon_id==”12160″ ) {
    
    // Set the correct time zone (http://php.net/manual/en/timezones.php)
    
    date_default_timezone_set( ‘Europe/Moscow’ );
    
     
    
    // Set the start time and the end time to be valid
    
    $start_time = mktime( 12, 00, 00, date( ‘m’ ), date( ‘d’ ), date( ‘y’ ) );
    
    $end_time = mktime( 17, 00, 00, date( ‘m’ ), date( ‘d’ ), date( ‘y’ ) );
    
    $time_now = strtotime( ‘now’ );
    
    if (isWeekend($time_now)== true)
    
    {
    
    return false;
    
    }
    
    if(isChill($time_now)==true){
    
    return false;
    
    }
    
    // Return true or false
    
    if ($start_time <= $time_now && $end_time >= $time_now) {
    
    return true;
    
    }
    
    else {
    
    return false;
    
    }
    
    }
    
     
    
    // Default
    
    return true;
    
    }
    
     
    
    // Is valid
    
    function filter_woocommerce_coupon_is_valid( $is_valid, $coupon, $discount ) {
    
    // Get coupon ID
    
    $coupon_id = $coupon->get_id();
    
     
    
    // Call function, return true or false
    
    return time_range_coupon_id( $coupon_id );
    
    }
    
    add_filter( ‘woocommerce_coupon_is_valid’, ‘filter_woocommerce_coupon_is_valid’, 10, 3 );

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author WP Scripts

    (@wpscripts)

    Hello @kimnikita0909 ,

    Thanks for using our plugin. We are not sure what you want to achieve. Could you please create a ticket with what exactly you want to achieve with proper screenshots or video so that we can help you?

    You can create a ticket here

    Thanks and regards,

Viewing 1 replies (of 1 total)

The topic ‘Coupons and time’ is closed to new replies.