How to Add Extra Text to Price WooCommerce

WooCommerce Add Extra Text to PriceAre 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:

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. From the Dashboard menu, click on Appearance Menu > Theme Editor Menu.
  3. 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.
  4. 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"; }
  1. This is the outcome:add extra text

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.

Similar Articles