Do you have the need to increase your WooCommerce prices across the entire product range? A possible scenario that you may face is moving from plus
postage to free postage or from free postage to plus postage. As any store owner knows, there’s no such thing as a free meal, and this also applies to postage costs. To offer “Free” postage you normally include the cost of postage into the product price, allowing the sell price to absorb delivery costs. But imagine having to price dozens, hundreds or even thousands of products. Such a task would take hours to complete, but thanks to this very simple snippet, you can increase (or decrease) the prices with just a few lines of code in your functions file.
Copy the below code to the functions.php file of your child theme, custom functions plugin or site specific plugin.
/*
** Snippet increase prices across entire website
** Author John Cook
** https://wcsuccessacademy.com/?p577
** Tested with WooCommerce 3.8.1
*/
add_filter( 'woocommerce_product_get_price', 'wc_success_academy_increase_price', 10, 2 );
function wc_success_academy_increase_price( $price ){
return $price + 6; // + 6 is the value to increase the price by. To decrease by 6 use - 6
}
That’s it. Just a few small lines of code and you can increase your prices across the board. You can further expand on the code to make it apply to specific categories only or apply a different price for each category on your site.
Important: This function will not change the price displayed against the product in admin. Old prices will be displayed until manually updated, but prices the customer sees and pays will be changed.
I have been working with WordPress and WooCommerce since 2012 and have developed a deep knowledge of the content management system. Since 2012, I have developed several plugins and designed dozens of websites utilising different frameworks, CMS’s and programming languages. I am proficient in PHP, Python, Java, C, C++, R and JavaScript with limited experience in Go, Kotlin and Swift.
Educationally, I have a Master’s degree in cyber security a Bachelor’s (Hons, First Class) in Applied Research and a Graduate Certificate in Data Science. I’m currently undertaking PhD studies investigating IoT cybersecurity. I recently graduated with First Class Honours and Masters of Information Technology, receiving the Executive Dean’s Award for studies undertaken in the 2021 and 2022 academic years. I have worked in the information technology industry for the past 11 years primarily as a software/web developer specific to design, optimisation, network management and security. My research interests are in the areas of Internet of Things (IoT), 5G and Beyond Networks, information security for wireless networks and software development.
Google Scholar ID: https://scholar.google.com.au/citations?user=0KvpwNEAAAAJ&hl=en
ORCID: https://orcid.org/0000-0001-8113-1296
Stay In Touch