Running a restaurant delivery website, I would like to create sale products based on "days of the week".
Tuesday 5 products Wednesday 10 products Saturday 6 products
For example, if Tuesday and product id is on sale, then sales price should be shown. I tried re-using this but can't find a topic about adding the sales price.
// Utility conditional function that check if day is tuesday (returns boolean)
function is_tuesday() {
// Set Your shop time zone (http://php.net/manual/en/timezones.php)
date_default_timezone_set('Europe/London');
// If the current day is "tuesday" return true (else retun false)
return ( date('w') == 2 ) ? true : false;
}
// check if day is wednesday (returns boolean)
function is_wednesday() {
date_default_timezone_set('Europe/London');
return ( date('w') == 3 ) ? true : false;
}
// check if day is saturday (returns boolean)
function is_saturday() {
date_default_timezone_set('Europe/London');
return ( date('w') == 6 ) ? true : false;
}
// Utility function (setting your product IDS in the array)
function tuesday_products() {
// HERE your product IDs in the array (need to be coma separated)
return array( 37 );
}
function wednesday_products() {
return array( 38,66,42 );
}
function saturday_products() {
return array( 321,87 );
}
// Enable sales price for specific items on conditional days only
add_filter( 'woocommerce_product_get_price', 'enable_specific_products_on_tuesday', 10, 2 );
add_filter( 'woocommerce_product_variation_get_price', 'enable_specific_products_on_tuesday', 10, 2 );
function enable_specific_products_on_tuesday( $purchasable, $product ) {
// Enable sales price for specific defined items only on tuesday
if( ! is_tuesday() && in_array( $product->get_id(), tuesday_products() ) )
$sale_price = $product->get_sale_price();
}