How to Change the WooCommerce Price via Functions.php

By |2018-10-01T06:23:59+00:00August 18th, 2014|Blog|7 Comments

Recently, we had had a project where we needed to show a discounted price on woocommerce products without editing the price in the database of our WP install. Thanks to WooCommerce’s handy hooks, this was pretty simple. Here’s our code snippet.


function return_custom_price($price, $product) {
    global $post, $blog_id;
    $price = get_post_meta($post->ID, '_regular_price');
    $post_id = $post->ID;
    $price = ($price[0]*2.5);
    return $price;
add_filter('woocommerce_get_price', 'return_custom_price', 10, 2);
In this example, we needed to raise our base price by 2.5x, but you could use this to modify the price in almost anyway you’d like.

About the Author:

Matt is a marketer and WordPress expert. Founder of Scepter, Matt oversees the larger web dev projects for the company. Seeing innovative ideas come to life is his passion, and therefore he pushes Scepter ahead to help our customers bring their projects to life.


  1. francesco January 31, 2015 at 6:21 pm - Reply

    and i i wish display “price on request” instead “free” when price is null or 0 is possibile with some variation of this code?

  2. Pixel Theme Studio March 12, 2015 at 10:15 pm - Reply

    Hello Francesco, unfortunately, you wouldn’t be able to do the price on request this way. If I get some time, I’ll try to post a tutorial of this!

  3. Jonny June 30, 2015 at 6:53 pm - Reply

    This is exactly what i have been looking for, but unfortunately it just sets all my prices to £0.00 … Any suggestions ? Thanks

  4. kiamaru August 8, 2015 at 4:07 pm - Reply

    don’t work with variation product. give price free.
    how use it with variation product.

  5. mehdi June 28, 2016 at 7:56 pm - Reply

    very tanks

  6. Akkisha August 21, 2017 at 3:48 am - Reply

    Works fine in product archieve and product pages


    If we add to cart the product
    It shows price for the product as zero

  7. alex October 20, 2017 at 9:39 pm - Reply

    I noticed made the prices zero so I looked into how to update the normal price by modifying your function

    function return_custom_price($price, $product) {
    global $post, $blog_id;

    $post_id = $post->ID;
    $price = $price * 2.5;
    return $price;
    add_filter(‘woocommerce_get_price’, ‘return_custom_price’, 10, 2);

Leave A Comment