I have a snippet for woocommerce, discounts on products every day, from time to time. But the discount is shown only for authorized users!
Help please! How show discount for all users (guest & auth)???
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)???