WPSlash Licences

Change price of Products dynamically based on Date

Change price of Products dynamically based on Date – code snippet guide from WPSlash
Published
Updated
Reading time
1 minutes
Written by
WPSlash team

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

Code
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;
}
All guides

FoodMaster (formerly WooFood)12 min read

Best Store Address Setup for Pickup

Compare single-address, multi-location, and directions-first pickup setups to reduce wrong-door visits and simplify checkout.

The plugins these guides are about

FoodMaster for restaurants, courier vouchers for the Greek market, marketplace sync and store tools, all for WooCommerce.

Browse plugins30-day money-back on every plugin