Untitled
raw download clone
TEXT
views 35
,
size 5626 b
function products_to_thursday(){
    global $wpdb;
    global $post;
    $id = $post->ID;
    $query = "SELECT ID from wp_czwartek where ID='".$id."'";
    $result = $wpdb->query($query);
    $total_rows = $wpdb->num_rows;
    if($total_rows>0){
        return true;
    }
    else{
        return false;
    }
}

function is_store_open_thursday()
{
    $now = time();
    $datetime1 = new DateTimeImmutable('thursday 12:00:00');
    $datetime2 = $datetime1->modify('saturday 23:59:00');

    if (($now >= $datetime1->getTimestamp() && $now <= $datetime2->getTimestamp())) {
        return true;

    } else {
        return false;
    }
}

function is_store_open_friday()
{
    $now = time();
    $datetime3 = new DateTimeImmutable('friday 12:00:00');
    $datetime4 = $datetime3->modify('saturday 23:59:00');

    if (($now >= $datetime3->getTimestamp() && $now <= $datetime4->getTimestamp())) {
        return true;
    } else {
        return false;
    }
}

function is_store_open($html, $product)
{
    global $post;
    $post_id=$post->ID;
    if ((products_to_thursday()) && (is_store_open_thursday())) {
        $html = '<p>Sprzedaż została zamknięta. Zapraszamy ponownie w niedzielę. (CZWARTEK)</p>';
    } elseif ((!products_to_thursday()) && (is_store_open_friday())) {
        $html = '<p>Sprzedaż została zamknięta. Zapraszamy ponownie w niedzielę. (PIATEK)</p>';
    } else {
        if ($product && $product->is_type('simple') && $product->is_purchasable() && $product->is_in_stock() && !$product->is_sold_individually()) {
            $html = '<form action="' . esc_url($product->add_to_cart_url()) . '" class="cart" method="post" enctype="multipart/form-data">';
            $html .= woocommerce_quantity_input(array(), $product, false);
            $html .= '<button type="submit" class="button alt">' . esc_html($product->add_to_cart_text()) . '</button>';
            $html .= '</form>';

            if (products_to_thursday()) {
                $counter_content =
                    '
                    <div id="timer">
                      <span class="timer-info">Zamów w ciągu: </br></span>
                      <div class="dni">
                      <span class="days"> </span> <span class="days-text">dni</span>
                      </div>
                      <div class="godziny">
                      <span class="hours"></span> <span class="hours-text">godzin</span> 
                      </div>
                      <div class="minuty">
                      <span class="minutes"></span> <span class="text-minutes">minut</span>
                      </div>
                      <div class="sekundy">
                      <span class="seconds"></span> <span class="second-texts">sekund</span></br>
                      </div>
                      <div class="info-time">
                      <span class="timer-info-after">aby otrzymać produkt w najbliższą sobotę. </span>
                      </div>
                    </div>
                ';

                return $counter_content . $html;
            } else {
                $counter_content =
                    ' 
                    <div id="timer2"> 
                      <span class="timer-info">Zamów w ciągu: </br></span>
                      <div class="dni2">
                      <span class="days2"> </span> <span class="days-text2">dni</span> 
                      </div> 
                      <div class="godziny2">
                      <span class="hours2"></span> <span class="hours-text2">godzin</span> 
                      </div>
                      <div class="minuty2">
                      <span class="minutes2"></span> <span class="text-minutes2">minut</span>
                      </div>
                      <div class="sekundy2">
                      <span class="seconds2"></span> <span class="second-texts2">sekund</span></br>
                      </div> 
                      <div class="info-time">
                        <span class="timer-info-after">aby otrzymać produkt w najbliższą  sobotę. </span>
                    </div>
                    </div>
        ';
                return $counter_content . $html;
            }
        }
    }

    return $html;


}

add_filter('woocommerce_loop_add_to_cart_link', 'is_store_open', 10, 2);



add_filter('woocommerce_is_purchasable','conditional_purchasable_products', 20, 2);
function conditional_purchasable_products( $is_purchasable, $product ) {

    if(products_to_thursday() && is_store_open_thursday()){
        $is_purchasable = false;
    }
    elseif(!products_to_thursday() && is_store_open_friday()){
        $is_purchasable = false;
    }
    else{
        $is_purchasable = true;
    }

    return $is_purchasable;
}


// Cart and checkout validation
add_action('woocommerce_check_cart_items', 'conditionally_allowing_checkout');
add_action('woocommerce_checkout_process', 'conditionally_allowing_checkout');
function conditionally_allowing_checkout()
{
    if (is_store_open_thursday() && is_store_open_friday()) {
        // Store closed
        wc_add_notice(__("Zamówienia zostały zamknięte. Zapraszamy w niedzielę"), 'error');
    }
}

add_action('template_redirect', 'closing_shop_notice');
function closing_shop_notice()
{
    if (is_store_open_thursday() && is_store_open_friday()) {
        // Store closed notice
        wc_add_notice(__("Zamówienia zostały zamknięte. Zapraszamy w niedziele"), 'notice');
    }
}
close fullscreen
Login or Register to edit or fork this paste. It's free.