Menu Close

WooCommerce: Add Prefix / Suffix to Product Prices

default

Sometimes you may want to add a prefix or a suffix to your prices. It could be something like “From…”, “Only…”, “…tax free” and so on.

The first good news is this is very easy to do with a WooCommerce filter (remember, filters change the value of an existing variable, while actions add content). The second good news is that you don’t need to know PHP, just copy/paste my snippet or install a mini-plugin. Enjoy!

woocommerce-add-prefix-suffix-price
WooCommerce: add prefix & suffix to product prices

WooCommerce Tax Settings: Add Suffix to Prices

Did you now there is a handy setting under WordPress Dashboard > WooCommerce > Settings > Tax > Tax Options > “Price display suffix”? If you have taxes enabled in your WooCommerce store, cool.

You can also use two placeholders: {price_including_tax} and {price_excluding_tax}. Which means, you can use this setting alone (and no coding) to show something like:

In the image example, I’m using “ex VAT {price_including_tax} inc VAT” in the WooCommerce settings as suffix. Easy peasy!

The only problem is in the display – WooCommerce suffix is wrapped in a “small” HTML tag, and therefore the whole “ex VAT {price_including_tax} inc VAT” string is smaller in font size than the price. This is why PHP is more useful than WooCommerce product price suffix settings in this case…

PHP Snippet 1: Add Suffix to WooCommerce Prices

/**
 * @snippet       Adds suffix to WooCommerce prices
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 7
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
  
add_filter( 'woocommerce_get_price_suffix', 'bbloomer_add_price_suffix', 99, 4 );
 
function bbloomer_add_price_suffix( $html, $product, $price, $qty ){
    $html .= ' suffix here';
    return $html;
}

PHP Snippet 2: Add Prefix to WooCommerce Prices

And if you wish to prepend some text or dynamic content before prices, here’s a way to add a prefix as well.

/**
 * @snippet       Adds prefix to WooCommerce prices
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 7
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
  
add_filter( 'woocommerce_get_price_html', 'bbloomer_add_price_prefix', 99, 2 );
 
function bbloomer_add_price_prefix( $price, $product ){
    $price = 'Prefix here ' . $price;
    return $price;
}

Mini-Plugin: Business Bloomer WooCommerce Add Prefix And Suffix to Product Prices

You don’t feel confident with coding? You need more control over your product price display? You don’t want to purchase yet another bloated, expensive plugin? Great!

Business Bloomer WooCommerce Add Prefix And Suffix to Product Prices is a mini WooCommerce plugin, without the usual hassles. One feature. Lifetime license. No annoying subscriptions. 1 plugin file. A few lines of code. No banners. No up-sells. No WP notifications. Use it on as many websites as you like. Lifetime support. 1-page documentation. No settings dashboard.

Settings screenshot:

Quick demo:

As you can see the plugin is pretty straight forward. Enter a custom prefix and/or suffix. See the magic happen. Simple!

Advanced Plugin: WooCustomizer

If you’d love to code but don’t feel 100% confident with PHP, I decided to look for a reliable plugin that achieve the same result.

As usual, I’ve chosen a WooCommerce plugin vendor based on marketplace reputation, dedicated support quality, code cleanliness, long-term reliability and – probably almost as importantly – where the “people behind” the plugin are active supporters of the WordPress ecosystem.

And in this case, price suffix is one of the features of WooCustomizer, a plugin built for everyone who wants to fully customize their WooCommerce store without coding (e.g. edit buttons, badges, tabs, pages, stock display, checkout fields).

But in case you hate plugins and wish to code (or wish to try that), then keep reading 🙂

View Source
Posted in WooCommerce Tips