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.

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 Janies,
    On a category you will find that postid-15698 will just become post-15698 as part of a

  3. that wraps around each of the products.
  4. 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?

  5. 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

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.