WooCommerce: Add Custom Product Fields (e.g. RRP) Without a Plugin

The manufacturer’s suggested retail price (MSRP), or the recommended retail price (RRP), is the price at which the manufacturer recommends that the retailer sells the product at. 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        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 5
 * @community     https://businessbloomer.com/club/
 */
 
// -----------------------------------------
// 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_product', 'bbloomer_save_RRP' );
 
function bbloomer_save_RRP( $product_id ) {
    global $typenow;
    if ( 'product' === $typenow ) {
        if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
        if ( isset( $_POST['rrp'] ) ) {
            update_post_meta( $product_id, 'rrp', $_POST['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 custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce Visual Hook Guide: Single Product Page
    Here’s a visual hook guide for the WooCommerce Single Product Page. This is part of my “Visual Hook Guide Series“, through which you can find WooCommerce hooks quickly and easily by seeing their actual locations (and you can copy/paste). If you like this guide and it’s helpful to you, let me know in the comments! […]
  • WooCommerce: Disable Variable Product Price Range $$$-$$$
    You may want to disable the WooCommerce variable product price range which usually looks like $100-$999 when variations have different prices (min $100 and max $999 in this case). With this snippet you will be able to hide the highest price, and add a “From: ” prefix in front of the minimum price. At the […]
  • WooCommerce: Hide Price & Add to Cart for Logged Out Users
    You may want to force users to login in order to see prices and add products to cart. That means you must hide add to cart buttons and prices on the Shop and Single Product pages when a user is logged out. All you need is pasting the following code in your functions.php (please note: […]
  • WooCommerce: Hide Prices on the Shop & Category Pages
    Interesting WooCommerce customization here. A client of mine asked me to hide/remove prices from the shop page and category pages as she wanted to drive more customers to the single product pages (i.e. increasing the click-through rate). As usual, a simple PHP snippet does the trick. I never recommend to use CSS to “hide” prices, […]
  • WooCommerce: Add Custom Field to Product Variations
    Adding and displaying custom fields on WooCommerce products is quite simple. For example, you can add a “RRP/MSRP” field to a product, or maybe use ACF and display its value on the single product page. Easy, yes. Unfortunately, the above only applies to “simple” products without variations (or the parent product if it’s a variable […]

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

67 thoughts on “WooCommerce: Add Custom Product Fields (e.g. RRP) Without a Plugin

  1. Hey! thanks for posting the code.

    is it possible to use the code multiple times to get multiple fields?

    have a page where we want to fill in the price 4 times (catalog mode)

    1. Of course. However, use the exact same functions though, and write 4 fields inside each one (you can’t reuse the same PHP function 4 times).

  2. Hi, how can I add a filed in add product page to user set sale price with percent, I means if regular price was 1000$ for example , he just type 10% and automatically sale price calcuteed.

  3. Hi Rodolfo!

    After i Update to woocommerce 6.9 (and 6.9.1) the RRP price is fatal error.

    Fatal error: Uncaught Error: Call to a member function get_type() on null in /wp-content/themes/bricks-child/functions.php:93 Stack trace: #0 [internal function]: display_RRP_price() #1 /wp-content/themes/bricks/includes/integrations/dynamic-data/providers/provider-wp.php(585): call_user_func_array() #2 /wp-content/themes/bricks/includes/integrations/dynamic-data/providers/provider-wp.php(552): Bricks\Integrations\Dynamic_Data\Providers\Provider_Wp->get_echo_callback_value() #3 /wp-content/themes/bricks/includes/integrations/dynamic-data/providers.php(180): Bricks\Integrations\Dynamic_Data\Providers\Provider_Wp->get_tag_value() #4 /wp-content/themes/bricks/includes/integrations/dynamic-data/providers.php(137): Bricks\Integrations\Dynamic_Data\Providers->get_tag_value() #5 /hom in /wp-content/themes/bricks-child/functions.php on line 93

    1. Try add a check on $product:

      if ( $product && $product->get_type() <> 'variable' && // ETC.
      
  4. Hi Rodolfo,

    Great article. I have successfully used this guide to add RRP to my site.
    However, I do have an issue. Every time I change the stock with ‘quick edit’, the RRP field clears itself completely.

    Is there a way I can have the RRP field I have just defined appear in quick edit with the value that was already assigned to it at import? (and obviously not to reset itself after I save any other field in the quick edit options).

    Best regards.

    1. Good point Andrei. Actually, in order to have the custom field appear under Quick Edit / Bulk Edit there is much more code to write, so for now I’ll fix the “reset” bug on quick edit – see latest version of the snippet. Thank you!

      1. Works perfectly fine!
        Thank you, Rodolfo!

        1. However, now I cannot edit the RRP field inside the Product Page.
          I can upload it when loading the CSV file, but if I try to edit the RRP on a Product Page it does not change (if it is empty I cannot assign a value… and if it has a value I cannot change it)

  5. i am using elementor page builder and am unable to get this code to show in the single product for elementor

    1. Hi Loyal, not sure about Elementor sorry

  6. Hi, this is brilliant. Is there a line of code I can add to cross out (strikethrough) the RRP price?

  7. Thank you for the snippet!

    The value I added in the RRP field (e.g. 5,99) is displayed without the decimals on the product page (e.g. 5,00). Is there a way to fix this? The problem is different from the decimal problem in the other posts.

    Thank you in advance!

    1. Not fully sure but someone else had this same issue and solved it in the previous comments. Give it a read and let me know

  8. Hello Rodolfo,
    Thanks for the script. I am using it for a while now, but i ran into a problem with adding attributes to products (using WP All Import). Somehow this clears the value from this field for al products that i change (with the setting that only added attributes should be created and nothing else touched.)
    I ideas how this can be prevented?
    Thanks! Henny

    1. Hi Henny, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  9. Thank you for this. is there a way to set a default value? for example when the field is created save default value as 1 instead of an empty field

    1. Hello Luna, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  10. Hi there!

    I’ve just used this in a test store I’m making for my girlfriend and it looks great but I’d like to show it on the search and category pages too? Has anyone asked / talked about this being extended to the category and search layout at all?

    All the best

    Ben

  11. Hello,

    I’m using this great hack for some time. It’s working fine but suddenly it started to round numbers after decimal point to zero. All my rrp’s are now incorrect. I’ve edited some products and reentered rrp fields but nothing changed…

  12. Thank you for this… added successfully. Had to change two lines to show MSRP instead of RRP, and it was good to go.

    However, I have a lot of products to edit, and even though this is a really nice addition to make the store nicer, it requires editing products singularly, a lot of time.

    How to add this to the “quick edit” to enable easier editing of multiple items from the product list page instead of having to open each one individually?

    Is that a viable +plus for this snippet?

  13. Hello,
    I have 2 issues/questions:
    1. When I export products I don’t see the attribute.
    2. How can I add this field everywhere, not only on the single product page?

    1. Hey Volodya, the field should be there in the export… try the default WooCommerce exporter. For the rest, unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

  14. It works with one currency. Is there an easy way to add the price they way the regular price or sale price is with the Currency Switcher.

    1. Hello Paul, thanks so much for your comment! Yes, this is possible – unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

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

  16. 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!

      1. Nice ๐Ÿ™‚

        1. Hi, nice solution from Willem Willem-Jan Meijer, thanks

          I’ve found better using floatval() function instead of str_replace().
          I needed to do this because I am making some maths after saving the field.

          So just replaced:

          //$_POST=str_replace(',','.',$_POST);

          for this:

           $val = floatval($_POST['rrp']);
          

          Cheers !

            1. The provided code is not complete and missing the variable which need to be replaced.
              You’re not checking the whole $_POST for comma’s but just [‘rrp’.] Without this I got an error 500 when saving.

              $_POST['rrp']=str_replace(',','.',$_POST['rrp']);

              Hope to be helpful 5 years after this message!

  17. 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 ๐Ÿ™‚

  18. 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? ๐Ÿ™‚

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

  19. 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)?

  20. 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        Get CustomizeWoo.com FREE
     * @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 ๐Ÿ™‚

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

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

      1. 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 ๐Ÿ™‚

  23. 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 ๐Ÿ™‚

  24. 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 ) ) {
      
      1. 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!

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

  25. 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!

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

    1. Thank you so much Conrad ๐Ÿ™‚

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

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