Change price of Products dynamically based on Date

A small code snippet to dynamically change the price based on products ids and on date.

Adjust the snippet to your needs and copy the functions.php of your child theme

add_filter('woocommerce_get_price','wpslash_woofood_change_price_conditionally', 10, 2);
add_filter('woocommerce_get_regular_price','wpslash_woofood_change_price_conditionally', 10, 2);
add_filter('woocommerce_get_sale_price','wpslash_woofood_change_price_conditionally', 10, 2);
function wpslash_woofood_change_price_conditionally($price, $productd){

    $product_ids_on_sale = array(220,230,240,250);  //specify product ids to apply the condition on price

    if(in_array($productd->get_id(), $product_ids_on_sale))
         if(current_time("Y-m-d") == "01-01-2020")
            return $price*2;


    return $price;