Posted on

WooCommerce: Add RRP / MSRP to Products (Without a Plugin)

The manufacturer’s suggested retail price (MSRP), or the recommended retail price (RRP), it’s the price at which the manufacturer recommends that the retailer sell the product. You might have seen this in an ad, on a magazine, on a price tag: “RRP: $50. Our price: $39!”.

WooCommerce entrepreneurs can take advantage of this “marketing trick” too. The only problem is: how do we show this “extra field” on the single product page AND in the product edit page, so that the website owner can add this easily?

WooCommerce: Display RRP/MSRP on the Single Product Page
WooCommerce: Display RRP/MSRP on the Single Product Page
WooCommerce: add RRP/MSRP field input @ product edit page
WooCommerce: add RRP/MSRP field input @ product edit page

PHP Snippet: Add RRP/MSRP @ WooCommerce Single Product Page


/**
 * @snippet       Display RRP/MSRP @ WooCommerce Single Product Page
 * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
 * @sourcecode    https://businessbloomer.com/?p=20727
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 3.4.5
 */

// -----------------------------------------
// 1. Add RRP field input @ product edit page

add_action( 'woocommerce_product_options_pricing', 'bbloomer_add_RRP_to_products' );		

function bbloomer_add_RRP_to_products() {		    
woocommerce_wp_text_input( array( 
'id' => 'rrp', 
'class' => 'short wc_input_price', 
'label' => __( 'RRP', 'woocommerce' ) . ' (' . get_woocommerce_currency_symbol() . ')',
'data_type' => 'price', 
) 
);		
}

// -----------------------------------------
// 2. Save RRP field via custom field

add_action( 'save_post', 'bbloomer_save_RRP' );

function bbloomer_save_RRP( $product_id ) {
	if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
		return;
	if ( isset( $_POST['rrp'] ) ) {
		if ( is_numeric( $_POST['rrp'] ) )
			update_post_meta( $product_id, 'rrp', $_POST['rrp'] );
	} else delete_post_meta( $product_id, 'rrp' );
}

// -----------------------------------------
// 3. Display RRP field @ single product page

add_action( 'woocommerce_single_product_summary', 'bbloomer_display_RRP', 9 );

function bbloomer_display_RRP() {
    global $product;
	
	if ( $product->get_type() <> 'variable' && $rrp = get_post_meta( $product->get_id(), 'rrp', true ) ) {
		echo '<div class="woocommerce_rrp">';
		_e( 'RRP: ', 'woocommerce' );
		echo '<span>' . wc_price( $rrp ) . '</span>';
		echo '</div>';
	}
}

Where to add this code?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such delicate files - if you need more guidance, please take a look at my free WooCommerce Customization video tutorial.

Does this snippet still work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free videos, tutorials and tips!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP
  • woocommerce-customize-shop-page-PHP
  • woocommerce-advanced-customization
  • how-to-edit-woocommerce-cart
  • woocommerce-customize-checkout-page-PHP
  • woocommerce-email-customization
  • woocommerce-conditional-logic

Rodolfo Melogli

Author, WooCommerce expert, WordCamp speaker and Internet marketer, Rodolfo Melogli has worked as a WooCommerce freelancer since 2011. He helps entrepreneurs and developers overcome their WooCommerce nightmares :) Rodolfo is the organiser of WordCamp Dublin, the Dublin WooCommerce Meetup, the Dublin Ecommerce Meetup and the Dublin WordPress Meetup. He enjoys interacting with people, travelling and chasing tennis & soccer balls. Of course, he loves pizza too.

32 thoughts on “WooCommerce: Add RRP / MSRP to Products (Without a Plugin)

  1. Hi Dear,
    Thank you for snippet it is great.
    I have one question, how to add shortcode to display RRP:.
    I try with:

    function bbloomer_display_RRP() {
        global $product;
         
    if ( $product-&gt;get_type()  'variable' &amp;&amp; $rrp = get_post_meta( $product-&gt;get_id(), 'rrp', true ) ) {
           echo '';
           _e( 'RRP: ', 'woocommerce' );
           echo '' . wc_price( $rrp ) . '';
           echo '';
       }
    	}
    
    add_shortcode('msrp','bbloomer_display_RRP');
    

    But no success.
    Thank you

    1. Sejkan – thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  2. Hi Rodolfo,
    Thanks for this nice piece of code.
    Just one issue: The price is not saved when i use decimals (i.e. 29,50) only round numbers work (i.e. 29)
    Any ideas how this can be prevented?

    Thanks!
    Henny

    1. Hey Henny – thanks so much for your comment! Have you tried entering “29 DOT 50” as opposed to “29 COMMA 50”?

    2. Ran into the same problem. Database does not accept COMMA or decimals are dropped, Input form does not accept DOT.

      Here is my fix, tested and working:

      Replace the lines

          if ( isset( $_POST['rrp'] ) ) {
              if ( is_numeric( $_POST['rrp'] ) )
                  update_post_meta( $product_id, 'rrp', $_POST['rrp'] );
          } else delete_post_meta( $product_id, 'rrp' );
      }
      

      by

        if ( isset( $_POST['rrp'] ) ) {
      	if ( is_string( $_POST['rrp'] ) )
      		$_POST=str_replace(',','.',$_POST);
      		update_post_meta( $product_id, 'rrp', $_POST['rrp'] );
         } else delete_post_meta( $product_id, 'rrp' );
      

      Happy to help and thanks for the code!

    3. Nice ๐Ÿ™‚

  3. Hello Rodolfo Melogli,

    Very nice and simple code, however some of the functions need to be updated with newer versions of WC, I find the follow worked with no errors:

     if ( $product->get_type() <> 'variable' && $rrp = get_post_meta( $product->get_id(), 'rrp', true ) ) {
            echo '<div class="woocommerce_rrp">';
            _e( 'RRP: ', 'woocommerce' );
            echo '<span>' . wc_price( $rrp ) . '</span>';
            echo '</div>';
        }
    

    I hope this helps

    Josh

    1. Brilliant, thanks so much ๐Ÿ™‚

  4. Hi Rodolfo,
    This is a really good code snippet – but how do I edit it to display for variable products? Is it possible? Seems a bit odd only for it to work on single products.
    Hope you can help,
    Andy

    1. Hey Andy, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

    2. OK, so what can you offer for me to get this sorted? ๐Ÿ™‚

    3. Thank you Andy! If you’d like to get a quote, feel free to contact me here. Thanks a lot! ~R

  5. Hi

    I’m using this and I’m getting an error where all RRP prices I have setup/typed works for a short while, but then they all dissapear :/ It’s a lot of work typing them for each product when they dissapear. So Im hoping there is a solution?

    I’ve only edited the name RRP to my local equivalent: ‘Vejl. Pris’.

    1. Matt, thanks for this! Could you try with a different theme and no plugins activated (but WooCommerce)?

  6. I have been looking for this snippet for ages…. Thanks a lot!

    Just wondering how can I get the MSRP to be hidden for guests? I am using this code snippet for hiding the regular price –

    
    /**
     * @snippet       Hide Price &amp; Add to Cart for Logged Out Users
     * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
     * @sourcecode    https://businessbloomer.com/?p=299
     * @author        Rodolfo Melogli
     * @testedwith    WooCommerce 2.4.12
     */
     
    add_filter('woocommerce_get_price_html', 'bbloomer_show_price_logged');
     
    function bbloomer_show_price_logged($price){
    if(is_user_logged_in() ){
    return $price;
    }
    else
    {
    add_action( 'woocommerce_single_product_summary', 'bbloomer_print_login_to_see', 31 );
    add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_print_login_to_see', 11 );
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
    remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
    }
    }
     
    function bbloomer_print_login_to_see() {
    echo '<a href="' . get_permalink(woocommerce_get_page_id('myaccount')) . '" rel="nofollow">' . __('Call Us to See Prices', 'theme_name') . '</a>';
    }
    
    

    Would this work – ?

    
    function bbloomer_show_price_logged($RRP){
    if(is_user_logged_in() ){
    return $RRP;
    }
    else
    {
    add_action( 'woocommerce_single_product_summary', 'bbloomer_print_login_to_see', 31 );
    add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_print_login_to_see', 11 );
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
    remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
    }
    }
    
    
    1. Hey Tewodros, thanks for your comment! I can’t offer premium support to free subscribers, sorry – other than that, no this won’t work like that. I suggest you take a look at “conditional logic”: https://businessbloomer.com/conditional-logic-woocommerce-tutorial/ and https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/. Let me know ๐Ÿ™‚

  7. Hey Rodolfo, thanks for the great php snippet (and for the others as well)!
    I would like to use it to display unit of measure for my products (eg. price/kg), so I would like to place it under (and not above) the price. Could you help me doing it? Thank you!

    1. Hey Rodolfo!
      Don’t bother yourself about the issue, I managed to find a solution! It might be not as elegant as a snippet, but it works. If you’re interested, I can tell you what I did:
      I wanted to show the unit price, but I have variable products (with different package weights), so unit price differed at each variation.
      I inserted unit price value in variable description, and then edited the /wp-content/plugins/woocommerce/templates/single-product/add-to-cart/variation.php file, and exchanged the order of description and price sections. So now the description (as unit price) appears after the actual price.
      To avoid the one-by-one insertion of these values, I created a calculating table in excel, where I import data from, so it somehow dinamically changes as price (and sales) changes.
      Maybe some day, when I have learned php and jscript a bit more, I will write a snippet for this. (because modifying woocommerce files is not OK for long-term)
      Keep up the good work, you’re my favourite magician! ๐Ÿ™‚
      Regards:
      Sanya

    2. Nice Sanya, well done!

  8. Hey Rodolfo really nice snippet. Although I need some more help to use it for my need. I want to use it to show the difference between store price and web price. First of all I want to display rrp in category page for every product. Second, I want to show it in variable products and be able to add a new price label in every variation. The last thing I wnat to add is a simple text before the regular price so that the customers know that this is the actual price they will pay. So it would be like: Store price: $50. Web price: $39. This would be displayed in category page for each product and in product page for both simple and variable products. Thank you very much!

    1. I managed to add a prefix “Web price” in regural prices and show rrp price in product loops. Although I do not know how to add a custom price field (rrp) for each variation and show it in product loop and single product page.

    2. Hey Konstantinos, thanks for your comments! Yes, this snippet only works for simple products, so unfortunately I can’t extend the code here in the blog comments for free. Hope this is understandable ๐Ÿ™‚

  9. Thanks for all code you provide! Is it possible to implement MSRP for variable products?

    1. Hey Lawrence, thanks for your comment! Technically this is possible by just removing this part inside the function:

      $product->product_type <> 'variable' &&
      

      Let me know ๐Ÿ™‚

  10. Hi, I am not a programmer.
    Is it good to replace the line

     if ( $product->product_type <> 'variable' ) { 

    with

     if ( $product->product_type <> 'variable' && get_post_meta( $product->id, 'rrp', true )!='' ) { 

    ?
    Because I want to hide the RRP at frontend when not setting RRP for some product.

    1. Amos, thanks so much for your comment and yes, you’re almost correct there. You also helped me improve my snippet so I thank you very much ๐Ÿ™‚ The correct PHP is:

      if ( $product->product_type <> 'variable' && get_post_meta( $product->id, 'rrp', true ) ) {
      
    2. Glad that I can contribute! But you are the first one who deserves to be appreciated! Thank you for sharing so many awesome and helpful snippets!

    3. Ah, excellent! Thank you very much ๐Ÿ™‚

  11. I had a go at doing this a couple of months ago, but I also displayed the saving on RRP. It’s easy to do on a simple product, just echoing the result of a simple calculation. Variable product? Not so much. You actually have to make an edit to the single-product/add-to-cart/variation.php template just to display the RRP and even then I couldn’t get it to display the savings properly. It’s still a work in progress.

    1. Andy, thanks for your comment and great idea there! If and when you finish your project don’t hesitate to reach out and I will give you the chance to share your code here. Thanks a million!

  12. Great snippet Rudolfo, will come in handy indeed. Keep up the great work!

    1. Thank you so much Conrad ๐Ÿ™‚

Questions? Feedback? Support? Leave your Comment Now!
If you're writing code, please wrap it between: [php] code_here [/php]

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

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