WPSlash

Change price of Products dynamically based on Date

Tuesday October 27, 2020

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;
}

Leave a Comment

Your email address will not be published. Required fields are marked *

Related Articles

WooFood

How to Disable Coupons for Delivery Orders in WooCommerce

If you’re running a WooCommerce-powered restaurant or food delivery service, you might want to restrict certain coupon codes for delivery orders while keeping them valid for pickup orders. This ensures better control over discounts, prevents misuse, and improves your store’s pricing strategy. Why Restrict Coupons for Delivery Orders? Offering coupons is a great way to attract customers, but in food […]
June 20, 2023
WooFood

How to Automatically Re-Enable Disabled Products in WooFood Once a Day

If you’re running a WooCommerce-powered restaurant ordering system using WooFood, you might have products that automatically get disabled due to stock limits or availability settings. To ensure a smooth customer experience, you can automate the re-enabling process using a scheduled WordPress cron job. This method allows you to reset all product availability once a day, ensuring your menu stays active without manual intervention. Why […]
March 8, 2023
WooFood

How to Add Live Product Search to WooFood in WooCommerce

Enhancing the user experience of your WooCommerce-powered restaurant ordering system is crucial, and adding a live product search feature can significantly improve navigation. This feature allows customers to quickly find food items in your WooFood-powered menu without manually browsing through categories. In this article, we’ll show you how to integrate a live product search above the accordion menu in WooFood using a simple jQuery script and PHP snippet. […]
December 29, 2022