How to Change the WooCommerce Price via Functions.php

2019-05-10T00:57:27+00:00By |Blog, Web Development|9 Comments

Update March 2019: We wanted to make this post even more useful, and therefore added a section that explains how to edit the price on variable and simple products. The price editor location is different for each product type, which can sometimes cause confusion. We have also read your comments and updated the code so that the price should no longer show zero. Let us know if you have any trouble!

Understanding how to change product prices in WooCommerce makes it possible for you to run your store competitively, improving your ROI.  As we’ll explain below, you can change individual products or run a bulk price change on variable products. But when you need to raise the base price of all your WooCommerce products, this can be a tedious task. That’s why we want to share this nifty code that we created to help.

How to Change the WooCommerce Price via Functions.php

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 WordPress 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);


function return_custom_price($price, $product) {
    global $post, $blog_id;
    $product = wc_get_product( $post_id );
    $post_id = $post->ID;
    $price = ($price*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.

How to Add Custom Price to WooCommerce Products Without Coding

Normally, you can change product prices in WooCommerce without needing to add any codes. There are two places you’ll find the price editor, and its location depends on whether the product is simple or variable. 

Simple products have no variations. What you see is what you get. Variable products have some variations, such as different colors or sizes, and the price may change according to the variation.

Here’s how to change product prices in WooCommerce:

  • For both types of products, start from your dashboard and click on the “Products” navigation menu on the left hand side. From there, choose the product you want to edit. Scroll down to the WooCommerce Product Data section.
  • For simple products with a single variation, the price editor will be on the first tab.
  • For a WooCommerce variable product price change, click on the Variations tab. From there, you can either click on each individual variation to change to price, or use the bulk editor to do a bulk price increase for all variations.

Are you taking full advantage of WooCommerce to get the most out of your store? Check out our post on 5 Tips to Optimize Your WooCommerce Store Performance.

Have any other WooCommerce pricing tips or tricks to share? Leave a comment below. Want to hand off the maintenance of your WooCommerce store to an experienced team? Get in touch!

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

  8. Cathy Habas April 24, 2019 at 2:50 pm - Reply

    Hi everyone, thank you for your comments! We have updated the code to address the issue of the price showing up as zero. Let us know if you continue to run into problems.

  9. Anant Prajapati May 14, 2019 at 6:23 pm - Reply

    Hello Guys

    This is nice post but what about the variable product price ???

Leave A Comment