WooCommerce Add Price Prefix

WooCommerce prices showing custom prefix text

Pre-Requisites

There are no pre-requisites in order for you to be able to implement this solution.

How To Implement This Solution?

Simply copy the pre-coded solution to your active theme’s functions.php or preferably the Code Snippets Plugin.

About this Solution

This guide allows you to add custom text as a prefix to prices on both the product archive and single product templates. You may wish to highlight to customers information about prices and adding a prefix may be an ideal way to do this.

				
					/**
 * Snippet Name:	WooCommerce Add Prefix To Prices
 * Snippet Author:	ecommercehints.com
 */

add_filter( 'woocommerce_get_price_html', 'ecommercehints_add_prefix_to_prices', 10, 2 );  
function ecommercehints_add_prefix_to_prices($price, $product) {
	$price = 'ONLY ' . $price;
    return $price;
}
				
			

Snippet Benefits

  • Add custom text prefixes to prices on the product archive and single product template
WooCommerce Conversion Rate Optimisation (CRO) eBook
100 WooCommerce Conversion Rate Optimisation Tips

2 Responses

  1. Hi, thanks for code snippet.
    Could you please advise how to make it work only for some particular category?
    We need to put Prefix only for products from one category.
    Thanks

    1. Hey Artem,
      You would need to wrap line 8 in an if statement using the is_product_category($category) or has_term( '$category', 'product_cat' )function where the argument/variable passed is either the category ID, title, or slug.
      If you need any further help getting this implemented, drop us a message here for a quote
      Cheers

Leave a Reply

If you are going to write code in the comments, please wrap it between code tags.

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

Other Recent Guides

Subscribe To Emails

Get exclusive WooCommerce tips that I only share with email subscribers

Join hundreds of other subscribers