• You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

    Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

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

karakym

Member
Aug 29, 2018
54
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)???
 
this part of the snippet doesn't have anything to do with users
you would need to provide the full script
 
  • Angry
Reactions: karakym

Forum statistics

Threads
79,392
Messages
1,140,986
Members
248,062
Latest member
pandiyarajanbcommdu
AdBlock Detected

We get it, advertisements are annoying!

However in order to keep our huge array of resources free of charge we need to generate income from ads so to use the site you will need to turn off your adblocker.

If you'd like to have an ad free experience you can become a Babiato Lover by donating as little as $5 per month. Click on the Donate menu tab for more info.

I've Disabled AdBlock