A common WooCommerce request is “How do I add text before the price” or “Can I put text before the price when the product is on sale?”, so I decided to write a plugin to make that easier for people that don’t like getting dirty with code and function files and all that good stuff.

Possible Uses For Text Before The Price Include Displaying RRP, MSRP, SRP and Sale Price

The main use case for this plugin was to display RRP (recommended retail price), MSRP (manufacturer’s suggested retail price) or SRP (suggested retail price) and sale price, but really you can use it to display any text.

If you don’t want to use my plugin, that’s cool I guess, two ways you can do it:

  1. Write some PHP in your functions file, or
  2. Write some CSS in your style file

Option 1: Add Text Before The Regular And/Or Sale Price With Code

Here are three snippets of code you can use:

  • First example give you the ability to add text before the regular price and sale price. You can change “RRP:” or “Sale Price:” to what you require
  • Second example will allow you to change the text before the “Regular Price” only. You can change “RRP:” to what you require
  • Third example allows you to change the text before the “Sale Price” only. You can change “Sale Price:” to what you require

Add text before regular price and sale price

function bd_rrp_sale_price_html( $price, $product ) {
  if ( $product->is_on_sale() ) :
    $has_sale_text = array(
      '<del>' => '<del>RRP: ',
      '<ins>' => '<br>Sale Price: <ins>'
    );
    $return_string = str_replace(array_keys( $has_sale_text ), array_values( $has_sale_text ), $price);
  else :
    $retun_string = 'RRP: ' . $price;
  endif;

  return $return_string;
}
add_filter( 'woocommerce_get_price_html', 'bd_rrp_sale_price_html', 100, 2 );

Add text before regular price only

function bd_rrp_price_html( $price, $product ) {
  $retun_string = 'RRP: ' . $price;
  return $return_string;
}
add_filter( 'woocommerce_get_price_html', 'bd_rrp_price_html', 100, 2 );

Add text before sale price only

function bd_sale_price_html( $price, $product ) {
  if ( $product->is_on_sale() ) :
    $return_string = str_replace( '<ins>', '<ins><br>Sale Price: ', $price);
    return $return_string;
  else :
    return $price;
  endif;
}
add_filter( 'woocommerce_get_price_html', 'bd_sale_price_html', 100, 2 );

Option 2: Use CSS To Add Text Before The Price

As all themes are a little different this exact CSS might not work, but hopefully you will get the idea on how you can do it and then apply it to the right selector on your theme. This technique uses the ::before selector that was introduced in CSS2, read all about it here.

Add text before the price on a product that is not on sale

.amount::before {
  content: 'RRP:';
  margin-right: 5px;
}

Add text before the sale price (ins) and before the regular price (del)

del .amount::before,
ins .amount::before {
  margin-right: 5px;
}

del .amount::before {
  content: 'RRP:';
}

ins .amount::before {
  content: 'Now:';
}

And of course if you need to change the content you add for a specific product or category, you can using different CSS selectors, you might find some handy hints at the holy grail for WordPress info – Codex: Post Class

  1. Your plugin is great. We moved to a Word Press MultiUser setup and with for some reason the plugin no longer worked?! 🙁

    We were able to follow your instructions above.

    Wanted a line break and added this:

    del .amount::after {
    content: “\000A”;
    white-space: pre;
    }

      • Quick question though….I put the words Starting at before my product prices and it worked fine. But I just realized that I have free products on my site too and obviously I don’t want the site to show Starting at for those items.

        What code could I add to my files in order to hide Stating at for some products only?

        Thanks for your help!

        • I did add this code in custom css :

          .postid-15698 .price:before {
          content:”Starting at: “;
          }

          and it works perfect BUT the “Starting at” only apperas in the product page itself and not on the shop page showing all my products. Is there a way to add the code for this specific product on the shop page?

          Thank again!

  2. Hi if we were to add a shortcode like this [block id=”outofcali-free-tax”] before price, how would that be?
    I tried content ” [block id=”outofcali-free-tax”]” but it failed.
    Any suggestion?

  3. Hi Bradley,

    My name is Nandakumar and I have an ecommerce affiliate portal running on Woocommerce. I wanted to change the Regular Price to something like Regular Price (MRP) and after the price is given, I wanted to have text “Inclusive of All Taxes” to be displayed after. I went through your article. It is very informative, but I am not sure to which functions file I need to changes, as I find many and where exactly the fucntions files and the css style sheet is located. Your help will be greatly appreciated.

    Regards,
    NandaaK

  4. I’m running the snippet in my functions and was wondering – how can I make it so the text only displays on single product pages but not main shop pages? I messed around with is_product() but couldn’t figure out how to implement it correctly.

    • Hi Ben
      Did you try is_single() and the product id? For example, if your WooCommerce product has an id of 17 and you want to add RRP, try doing it this way:

      function bd_rrp_price_html( $price, $product ) {
      if ( is_single( '17' ) ) :
      $retun_string = 'RRP: ' . $price;
      return $return_string;
      endif;
      }
      add_filter( 'woocommerce_get_price_html', 'bd_rrp_price_html', 100, 2 );

      • I want to add the labels to every product but I only want them displayed on the actual product page, not on the main shop page or category pages. Does that make sense?

        • Hi Ben,
          Oh right, my mistake, sorry about the confusion. So the last example without the id should do it, try the following and let me know how you go.

          function bd_rrp_price_html( $price, $product ) {
          if ( is_single() ) :
          $retun_string = 'RRP: ' . $price;
          return $return_string;
          endif;
          }
          add_filter( 'woocommerce_get_price_html', 'bd_rrp_price_html', 100, 2 );

          • Thank you so much for the quick response! I tried adding that but it didn’t work out correctly, could you show me where to insert it into my snippet?

            function bd_rrp_sale_price_html( $price, $product ) {
            if ( $product->is_on_sale() ) :
            $has_sale_text = array(
            '' => 'MSRP: ',
            '' => 'Dealer: '
            );
            $return_string = str_replace(array_keys( $has_sale_text ), array_values( $has_sale_text ), $price);

            else :
            $return_string = 'Dealer: ' . $price;
            endif;

            return $return_string;
            }

            add_filter( 'woocommerce_get_price_html', 'bd_rrp_sale_price_html', 100, 2 );

          • That didn’t really translate properly but it’s the first snippet you posted earlier with my edit for the labels/titles.

          • Hi Ben, Alright I think this might be what you are after, if the page is not a single product it just displays the price as normal, if it is a product and on sale it displays MSRP and Dealer and if it is a single product (not on sale) it displays Dealer.

            function bd_rrp_sale_price_html( $price, $product ) {
            if ( ! is_single() ) :
            $price = $price;
            elseif ( is_single() && $product->is_on_sale() ) :
            $has_sale_text = array(
            '' => 'MSRP: ',
            '' => '
            Dealer:
            '
            );
            $price = str_replace(array_keys( $has_sale_text ), array_values( $has_sale_text ), $price);
            else :
            $price = 'Dealer: ' . $price;
            endif;
            return $price;
            }
            add_filter( 'woocommerce_get_price_html', 'bd_rrp_sale_price_html', 100, 2 );

            oh crap, hopefully you read this after I fix the strikethrough text in the code. sorry about that.

    • Bradley Davis says:

      Hi Omar,

      Not via the plugin, I will add this to the suggested list of features.

      You could do this with some of the code examples above, with CSS you will probably find the tag gets added to the body tag so you could include that in the CSS selector and with PHP you do this with the has_tag I think.

      With tags I guess the one thing you will need to pay attention to is if a product has two or more tags.

      Cheers
      Brad

  5. Why I am having error while running this code

    function cw_change_product_price_display( $price ) {
    $price .= ‘ At Each Item Product’;
    return $price;
    }
    add_filter( ‘woocommerce_get_price_html’, ‘cw_change_product_price_display’ );
    add_filter( ‘woocommerce_cart_item_price’, ‘cw_change_product_price_display’ );

    I am trying to change the pricing on display but it gives me an unknown error. Can you please guide me how to change pricing? or Is there any alternative method to do this? I have seen this code here https://www.cloudways.com/blog/change-woocommerce-price-display/

    • Hi Luka,
      When you say “base price” are you referring to a composite product or something similar? I would say yes it is, however I do not have a composite product setup to test this out for you.

Leave a Reply

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.