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);
OR
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!
Hello.
and i i wish display “price on request” instead “free” when price is null or 0 is possibile with some variation of this code?
regards
francesco
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!
This is exactly what i have been looking for, but unfortunately it just sets all my prices to £0.00 … Any suggestions ? Thanks
hi
don’t work with variation product. give price free.
how use it with variation product.
regards
very tanks
Works fine in product archieve and product pages
But
If we add to cart the product
It shows price for the product as zero
Hi,
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);
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.
Hello Guys
This is nice post but what about the variable product price ???
Hello, is there a way in which I can add additional Custom Fields and Product Fees on the checkout section of the page.
For Example:
If a customer add a Bluetooth speaker at Cart/Checkout , based on the product category SPEAKERS, it will calculate and show the Additional Fees like CUSTOM DUTIES, AIR FREIGHT SERVICES, FUEL SURCHARGE, VAT ON LOCAL HANDLING, ONLINE TAX on the order section
Hi Rudy, you can try these plugins to address tax fees: https://codecanyon.net/item/woocommerce-tax-control/22103225 or https://codecanyon.net/item/woocommerce-tax-manager-wtm/17357403
Hello,
i have set this snippet to change price by tag like this:
function return_custom_price($price, $product) {
if ( has_term( ‘test’, ‘product_tag’ ) ) {
global $post, $blog_id;
$product = wc_get_product( $post_id );
$post_id = $post->ID;
$price = ($price*2.5);
return $price;
}
else {
return $price;
}
}
add_filter(‘woocommerce_get_price’, ‘return_custom_price’, 10, 2);
It works on shop and single product page but not in cart and checkout. Can You help me please?
Hi, I found your post very helpful but I need to improve it adding another step…can you help me? I need to check a price value(gold,platinum, etc.) using an official website and use this value to create the final price of the product with something like that: (gold price)*(weight)*(constant) = price .
Can you help me?
Best regards
how can i change sale and regular price both with custom prices