Are you looking for a way to add extra text to the WooCommerce price?
This post aims to provide a solution for adding extra HTML content to add text to the WooCommerce price field.
WooCommerce Add Extra Text to Price
It is worth mentioning that WooCommerce only displays the product’s price on the product page along with the currency symbol.
However, this information might not be enough depending on the online store you are running.
For example, you might want to add some extra details like “per kg” after the price.
This might seem a bit complicated, but you will be surprised how it is very easy to achieve this.
How to Add Extra Text to WooCommerce Price Field
We will be using a custom PHP code snippet to add extra text to the WooCommerce price field in this post.
A plugin can achieve this, but having many plugins can bloat your site.
You also need to create a child theme. This will ensure that your changes are not lost during an update.
Let us get right into it.
Steps to Add Extra Text to WooCommerce Price Field
Here are the simple steps you need to follow:
- Log into your WordPress site and access the Dashboard as the admin user.
- From the Dashboard menu, click on Appearance Menu > Theme Editor Menu.
- When the Theme Editor page is opened, look for the theme functions file to add the function that will add “per kg” text next to the WooCommerce price.
- Add the following code to the PHP file:
add_filter( 'woocommerce_get_price_html', 'njengah_add_extra_price_content', 10, 2 ); add_filter( 'woocommerce_get_variation_price_html', 'njengah_add_extra_price_content', 10, 2 ); function njengah_add_extra_price_content($price, $product) { return ($price) . " per kg"; }
Conclusion
That’s all you need to do to add text to the WooCommerce price.
However, you should be careful when editing the functions.php file. This is because if you make any mistake, an error will be displayed on your site.
We recommend using this method for a quick fix or a store with few products or products that share a common way to calculate the price.
This method adds text to every product page.
If you want an advanced per-product approach, you should use a plugin.
We hope that this tutorial helped you to solve your problem.
Joe is an experienced full-stack web developer with a decade of industry experience in the LAMP & MERN stacks, WordPress, WooCommerce, and JavaScript – (diverse portfolio). He has a passion for creating elegant and user-friendly solutions and thrives in collaborative environments. In his spare time, he enjoys exploring new tech trends, tinkering with new tools, and contributing to open-source projects. You can hire me here for your next project.
Similar Articles
- How to Customize WooCommerce Product Pages
- How to Hide Price When Out of Stock In WooCommerce
- How to Add Video In Product Image WooCommerce
- How to Add Google Analytics to WooCommerce
- How to Add New Tab WooCommerce, Product Page
- How to Check if a User is Logged In to WordPress
- How to Translate WooCommerce Checkout Page
- How to Hide Any Tab My Account Page WooCommerce
- What is the Best Payment Gateway for WooCommerce
- How to Replace Price with Text Call for Price in WooCommerce
- How to Add WooCommerce Products to a Page
- How to Add Text Before the Price in WooCommerce » Add Text Before Price
- How to Customize WooCommerce Product Pages With Elementor Pro
- How to Set Up WooCommerce Buy One Get One
- How to Keep WooCommerce Description Tab Open by Default
- How to Customize Product Category Page In WooCommerce
- How to Integrate MailChimp With WooCommerce