Categories
Woocommerce

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 help of a WordPress developer for your website, get in touch now!.

Follow me on Twitter : @geekz

Leave a Reply

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