How to add text before or after price in WooCommerce

You can use the WooCommerce filter woocommerce_get_price_html and woocommerce_cart_item_price to add a string before or after the price in WooCommerce product and cart pages.

Here is the code that you can copy and paste in your active theme’s functions.php file:

function wptips_custom_html_addon_to_price( $price, $product ) {
 $html_price_prefix = '<span class="price-prefix">prefix</span>'; // custom prefix html that you want to add before price
 $html_price_suffix = '<span class="price-suffix"> suffix</span>'; // custom suffix html that you want to add after price

 if ( !empty( $price ) ) {
	 $price = $html_price_prefix . ' ' . $price . ' ' . $html_price_suffix;
	  return $price;
	} else {
	  return $price;
add_filter( 'woocommerce_get_price_html', 'wptips_custom_html_addon_to_price', 999, 2 );
add_filter( 'woocommerce_cart_item_price', 'wptips_custom_html_addon_to_price', 999, 2 );

You can use the above simple code snippet in your active theme, or use the code in a custom plugin to add text next to the price in WooCommerce. You can also add a prefix or suffix HTML or TEXT to the price on the product page and cart page as well.

By Murali Kumar

I am a Full Stack Web Developer with over 12 years of experience. I love WordPress & WooCommerce.

If you need the help from a WordPress developer for your website, get in touch now!.

Twitter : @geekz
YouTube : @wptipsofficial

3 replies on “How to add text before or after price in WooCommerce”

Some products on the website have prices, while others do not have prices marked. I want to add text after the products have prices. If the products do not have prices, the text will not be displayed. What should I do?

If variation is not selected i have a price span like ^^from 2$^^. Under this price span I would like to create a custom text A.
But when I select a variation( doesnt matter which one) I would like to change this text to a text B.
Is that possible? Thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *