[Snippet]Woocommerce daily discount in time, help please!!!

karakym

Member
Aug 29, 2018
53
12
8
USSR
I have a snippet for woocommerce, discounts on products every day, from time to time. But the discount is shown only for authorized users!

PHP:
function get_discount_period_rate(){
    date_default_timezone_set('Europe/Kiev');
    $rate = 0.65; // 35%
    $start_time = mktime( 11, 00, 00, date("m")  , date("d"), date("Y") );
    $end_time   = mktime( 22, 59, 59, date("m")  , date("d"), date("Y") );
    $time_now   = strtotime("now");
    return $start_time <= $time_now && $end_time > $time_now ? $rate : false;
}
add_filter( 'woocommerce_product_variation_get_sale_price', 'periodic_discount_prices', 99, 3 );
add_filter( 'woocommerce_product_variation_get_price', 'periodic_discount_prices', 99, 3 );
add_filter( 'woocommerce_variation_prices_sale_price', 'periodic_discount_prices', 99, 3 );
add_filter( 'woocommerce_variation_prices_price', 'periodic_discount_prices', 99, 3 );
add_filter( 'woocommerce_product_get_sale_price', 'periodic_discount_prices', 99, 3 );
add_filter( 'woocommerce_product_get_price', 'periodic_discount_prices', 99, 3 );
function periodic_discount_prices( $price, $product, $parent = 0 ){
    $discounted_products = array( 8710 );
    if( get_discount_period_rate() && in_array( $product->get_id(), $discounted_products ) ){
        $price = $product->get_regular_price() * get_discount_period_rate();
    }
    return $price;
}

Help please! How show discount for all users (guest & auth)???
 

italomg

New member
Jun 13, 2018
8
0
1
this part of the snippet doesn't have anything to do with users
you would need to provide the full script
 
  • Angry
Reactions: karakym

About us

  • Our community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day to make sure our community is one of the best.

Quick Navigation

User Menu