WooCommerce reviews + tutorials

The WooCommerce MSRP Pricing plugin allows you to set an MSRP price for your products and display it on the product page. But what if you want the MSRP displayed on the category/catalog/shop pages? The following is one solution, which will display the MSRP just before the regular product price in the catalog pages. You may need to do a little CSS style tweaking of the displayed MSRP price, depending on your theme and the look you want to achieve, but hopefully the example here will be enough to get you started. You can add this to your theme’s functions.php in the usual manner (theme-name/functions.php), or perhaps to your custom site plugin:

add_action( 'woocommerce_after_shop_loop_item_title', 'loop_item_msrp_price', 9 );

/**
 * Display the MSRP price in the product loop
 */
function loop_item_msrp_price() {
  global $product;

  // MSRP pricing enabled?
  $msrp_enabled = get_option( 'woocommerce_msrp_status', 'never' );

  if ( $msrp_enabled == 'never' ) return;

  // is the MSRP price set?
  $msrp = get_post_meta( $product->id, '_msrp_price', true );

  if ( empty( $msrp ) ) return;

  // MSRP label
  $msrp_label = get_option( 'woocommerce_msrp_description' );

  // display the MSRP price
  echo '
' . ( $msrp_label ? esc_html__( $msrp_label ) . ': ' : '' ) . '' . woocommerce_price( $msrp ) . '
'; }

Note: the above solution currently only supports simple products. It will not display an “MSRP From: $X” for variable products, not that it’s impossible to do so, it would just take some more code.

Published by Justin Stern

Justin is one of our co-founders, and is our resident overengineer. He likes to write developer tutorials and make black magic happen in our plugins. He thinks that writing code is a lot easier than writing words.

2 Comments

  1. Hi Justin

    Great post could you contact me on how to display this for the variable products as well please.

    Thanks

    Jay

    • I think the latest version of the MSRP plugin actually has an option to display the price on the catalog page, so it may very well take care of doing this now, even for the variable products. I’m not 100% sure as I haven’t tried it out, just someone mentioned it to me the other day

Hmm, looks like this article is quite old! Its content may be outdated, so comments are now closed.