skip to Main Content

WooCommerce add to cart products with customized price using hooks

Many times we want to sell the product with the custom price. So if you have many products and you want to set custom price only for 10 products for 1 hours. it’s hard to change price of the product from WooCommerce admin panel.

We can change the price of the product without changing the code of core module or without editing the price for the product from WooCommerce admin panel using WordPress Hooks.

So let’s see how we can use WooCommerce Hooks for changing the price of the product.

Just copy below code on functions.php file.

add_filter('woocommerce_get_price','change_price', 10, 2);
add_filter('woocommerce_get_regular_price','change_price', 10, 2);
add_filter('woocommerce_get_sale_price','change_price', 10, 2);

function change_price($price, $productd){
     if($productd->id == '1'){
        $price = "150";
     return $price;

So, As per above example, we set the “150” price for the product that has 1 id. So using above example you can set price without editing product or change the WooCommerce code.

If you face any issue after using above code please write comment below.


I am a web designer and developer part-time blogger. Write something on some free time. Find my every day thought here :)

Leave a Reply

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

Back To Top