Posted on

How to Hide Price & Add to Cart Button in WooCommerce?

Know who needs to hide prices on their WooCommerce store and how they can do it via some code.

WooCommere hide price

Last updated on March 24, 2023

Hiding product prices and Add to Cart button in WooCommerce is actually a marketing gimmick. And it reaps rewards too.

But who should do it, why to do it and how to do it?

In this blog, we’ll share some code snippets to hide prices in WooCommerce for all visitors, or based on some conditions like logged-in status, and some other scenarios!

When to hide prices on your WooCommerce store?

There may be some situations wherein it makes sense to hide prices and Add to Cart button:

  • Wholesalers – You want to hide the price from retail customers while still allowing wholesale customers to see the prices. This is an example of showing prices only to the registered users.
  • Catalogs and pre-product launches – If you’re coming up with new products or a store, then you just want to build some buzz by showcasing your product catalog, without the price and Add to Cart button.
  • Out-of-stock items – You want to hide the prices for products that aren’t in stock and you’re not sure when they will be available next.
  • List building – Interested shoppers will contact the store for the price. This can be a way to build email lists or create a more personal connection with potential customers.
  • Offline purchases – Some sellers use the website only for marketing and advertisement of genuine products. The actual products are available at physical stores only.
  • Members-only – Create a members-only store where registered shoppers must log in to see the prices of your special membership packages. We recommended using the WooCommerce Memberships plugin to create and sell membership products on your store.

Now that we know who needs to hide prices and why, let’s take a look at how to hide them.

WooCommerce hide price – Code snippets for different scenarios

Since WooCommerce doesn’t include this feature, you need to use code snippets or some plugins.

And adding code snippets is risky. So we suggest you refer to this doc on safely adding code to your functions.php file.

Hide prices on the product pages

add_filter( 'woocommerce_get_price_html', 'storeapps_remove_price' );
function storeapps_remove_price( $price = ''){
return '';
}

Hide prices on the WooCommerce shop page only

remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );

Hide prices on all pages except WooCommerce cart and checkout page

add_filter( 'woocommerce_variable_sale_price_html', storeapps_remove_prices', 9999, 2 );

add_filter( 'woocommerce_variable_price_html', 'storeapps_remove_prices', 9999, 2 );

add_filter( 'woocommerce_get_price_html', 'storeapps_remove_prices', 9999, 2 );

function storeapps_remove_prices( $price = '', $product ) {
if ( ! is_admin() ) $price = '';
return $price;
}

Hide prices for out-of-stock items

You may want to hide prices for out-of-stock products on the shop, categories, archives, loops and single product page.

add_filter( 'woocommerce_get_price_html', 'storeapps_hide_price_if_out_stock_frontend', 9999, 2 );

function storeapps_hide_price_if_out_stock_frontend( $price = '', $product ) {
if ( is_admin() ) return $price; // return if admin dashboard
return ( ! $product->is_in_stock() ) ? apply_filters( 'woocommerce_empty_price_html', '', $product ) : $price;
}

Hide prices for logged-out users

When you want to force users to log in to view prices and add products to the cart.

add_filter( 'woocommerce_get_price_html', 'storeapps_hide_price_addcart_not_logged_in', 9999, 2 );

function storeapps_hide_price_addcart_not_logged_in( $price = '', $product ) {
if ( is_user_logged_in() ) {
return $price;
}
$price = '<div><a href="' . get_permalink( wc_get_page_id( 'myaccount' ) ) . '">' . __( 'Login to see prices', 'storeapps' ) . '</a></div>';
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
return $price;
}

Hide prices for specific products (new launches)

You only want to hide the prices for your new launches having product IDs 303 and 609, but display the prices for the rest of the products.

add_filter( 'woocommerce_get_price_html', 'storeapps_hide_price_product_ids', 10, 2 );

function storeapps_hide_price_product_ids( $price = '', $product ) {
$hide_for_products = array( 303, 609 ); // Specify a list of product ids for which prices have to be hidden
return ( in_array( $product->get_id(), $hide_for_products ) ) ? '' : $price;
}

Hide prices for specific product categories

add_filter( 'woocommerce_get_price_html','storeapps_hide_price_on_taxonomy' );

function storeapps_hide_price_on_taxonomy( $price = '' ) {
global $product;
$hide_for_categories = array( 'posters' ); // Hide for these category slugs / IDs
return ( has_term( $hide_for_categories, 'product_cat', $product->get_id() ) ) ? '' : $price; // Don't show a price when it's in one of the categories else return the original price
}

Conclusion

Hiding prices and Add to Cart buttons help you stay in control over the products, particularly for wholesale stores, catalog sites and other cases mentioned in this blog.

We hope you find this ‘WooCommerce hide prices’ article useful. Any feedback or queries, share them below.

2 thoughts on “How to Hide Price & Add to Cart Button in WooCommerce?

  1. I am missing an option to hide prices everywhere for everyone. This is needed when you want to show what the business offers, but need people to enquire to get quotes.

    1. Hi Rik,

      Use all the code snippets in the above article to hide prices everywhere for everyone.

      Alternatively, there are plugins available to hide prices automatically. We haven’t tried any plugin yet, so can’t recommend which one is the best.

Leave a Reply

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.