WooCommerce hide price until logged in

Table of Contents

Many WooCommerce stores especially wholesalers offer their products to a wide range of customers. Those online shops need to enable WooCommerce hide price until logged in which functionality displays prices only to the logged-in users and hides them from guests. 

In other words, some businesses need to make reviewing prices and ordering products possible for the visitors who create accounts on their websites and log in.

By default, there is no option in WooCommerce to hide price until login. So, if you are in a similar situation and looking for a solution to hide price until login WooCommerce, do not worry! At the end of this post, you can use two below methods to solve this problem:

Let’s explore how you can let visitors browse your WooCommerce products, but only display prices and add-to-cart buttons for logged-in users.

Use Cases for WooCommerce hide price until login

Before going through the step-by-step guide, let’s review popular use cases of WooCommerce hide prices for guest users. 

Prevent the general public from ordering products from Wholesalers 

As a Wholesale store, your target is not selling products to the general public. Instead, you just want wholesale customers to buy from your shop. Adding the WooCommerce hide price until login feature helps you display your inventory to all visitors without displaying prices unless the pre-approved wholesale users register to your website. They can see prices or order from your shop just after logging in.

Allow approved customers to purchase products from manufacturers 

If you have run an online store as a manufacturer to publish details of your products on your websites, it is important to only let approved resellers order products from your site. So, you can enable WooCommerce hide prices until logged-in feature and don’t allow guests to see your product prices.

Let members buy from membership websites

The members-only stores are other types of businesses that need to force visitors to join a club or buy a membership before placing an order. Displaying products without prices encourages potential customers to pay for membership or subscribe to create an account, then see the prices and buy products.

Sell products only to B2B customers 

One of the most common reasons for WooCommerce hide prices from guest users is to let only B2B customers purchase products.

Collect customer Leads

WooCommerce hide prices until login is also important for retailers when they want to convince potential customers to register and submit information like their email addresses or phone numbers to create accounts. Collecting such information can increase the lead and enable store managers to run further marketing campaigns like email marketing to sell more products to the registered users.

How to set WooCommerce hide price until logged in?

For any reason you may need to hide prices in WooCommerce and force users to log in in order to see prices and add products to the cart, you can follow the below step-by-step guide. By using one of the below methods, you can hide product prices on the shop and single product pages when a user is logged out.

Method 1: Set WooCommerce hide price for guests programmatically

This is a technical method that needs coding knowledge. Although there is no requirement to install any third-party plugin in this method, we recommend you use this method by taking the following points into consideration:

  • If you have no experience in coding, ask an expert to apply the codes on your website. 
  • Back up your WordPress data before applying the code to restore the data in case of any problem. 
  • Create a child theme and add the code to it instead of applying code to the main theme.

To enable WooCommerce hide price until login feature programmatically, you just need:

  • Go to Appearance > Theme File Editor.
  • Open the functions.php file.
  • Paste the following PHP snippet in the functions.php file of the created child theme.
  • Click on “Update File.”
/** 
* @snippet       Hide Price & Add to Cart for Logged Out Users 
* @testedwith    WooCommerce 7 
*/  
add_filter( 'woocommerce_get_price_html', 'it_hide_price_not_logged_in', 9999, 2 ); 
function it_hide_price_not_logged_in( $price, $product ) {   
   if ( ! is_user_logged_in() ) {       
      $price = '<div><a href="' . get_permalink( wc_get_page_id( 'myaccount' ) ) . '">' . __( 'Login to see prices', 'text-domain' ) . '</a></div>';       
      add_filter( 'woocommerce_is_purchasable', '__return_false' );   
    }   
return $price;
}

By applying this PHP Snippet, the product prices will be hidden from WooCommerce shop, single product pages, widgets, etc. unless the users logging into your WordPress site.

Hide price for users who logged in

You can also use the following code if you want to hide prices and show a message for guests:

add_filter('woocommerce_get_price_html', 'hide_price_initially_for_guests', 10, 2);
function hide_price_initially_for_guests($price, $product) {
    if (!is_user_logged_in()) {
        // Return a custom message for guests
        return __('Price will be revealed once you log in', 'text-domain');
    }
    return $price;
}

By applying this code, when guest users visit your website, they will see “Price will be revealed once you log in” instead of the price.

Show result of hide price for logged in users rule

Method 2: Hide price until login with WooCommerce role-based pricing plugin

The second method for hiding prices until logged in is using the WooCommerce role-based pricing plugin. With this powerful tool, you are able to display product prices to the users who registered on your website. It has also a lot of flexible options for displaying different prices to different user roles.

To hide the price until log in with WooCommerce role-based pricing, you just need to follow the four simple steps:

Step 1: Install WooCommerce Role Based plugin

The first step is to install and activate the plugin on your website. 

To install the plugin, go to Plugins > Add New > Upload Plugin. Then select the ZIP file of the plugin and click Install Now button.

Install role based plugin for woocommerce

To use the amazing features of the plugin you need to buy a license and activate it by navigating to the below address:

WordPress Dashboard > iThemeland > License

Select license menu

You need to insert the license key in the form and press the Activate button.

Activate plugin license

Now you are ready to use this plugin for WooCommerce hide prices until login.

Step 2: Set rules for WooCommerce hide product prices from guest users

Once you have activated the WooCommerce role-based pricing on your WordPress website, go to the plugin main page by clicking on the iThemeland > Role Based Pricing menu.

The plugin will lead you to the Rules page which is useful when you want to set rules to show different prices to the different user roles.

Then, you need to click on the Hide Price tab and mark Enable Hide Price & Add to cart option as illustrated below:

Enable hide price and add to cart option using role based plugin

After enabling the mentioned option, the plugin will show you some items allowing you to effectively hide prices for guest users or other user roles.

To hide prices until login in WooCommerce, try to mark the following items:

  •  Hide for guest users  
  •  Hide Price  
Set hide price for guest users rule

Now, you just need to click on the Save Settings button to hide all product prices for guest users.

Step 3: Show a custom message instead of product prices

When you enable the WooCommerce hide price option, plain text will show to the guest users by default. However, you can insert a custom text in the Price Text field to display it instead of the product price to the guests.

For example, in the screenshot below, we insert “Contact us” as the custom message in the text box to be displayed instead of product prices.

Show custom text instead of product price setting

Finally, press the Save Settings button for WooCommerce hide price until logged in, and display the custom message to the guests.  

Step 4: Check the front-end pricing preview for guest users and logged-in users

Once you apply the rule to hide prices for visitors and guests, the product prices will be removed from the main WooCommerce shop and product single pages.

So, if guest users visit your website, they are only able to see some product details, including the product image, variations, and the custom message you added instead of product prices.

 So, the single product page will look like this for guests:

Show result of hide price for guest users

In order to view product prices and proceed to the cart page, visitors will have to log into their accounts.

When customers log into their accounts, they can see regular or sale prices and they are also able to add products to their cart and proceed to the checkout page as illustrated below:

Show result of hide price for logged in users
Role Based Pricing for WooCommerce Banner

Advantages of WooCommerce hide prices for guest users

The advantages of WooCommerce hiding prices until logged in, are different for online businesses based on the reason that makes them enable this function on their websites. However, we can count some of the most advantages, here:

  • It can help store managers display product prices to the registered users only. So, public visitors are prompted to create an account and register on their websites.
  • It helps gather customer information to increase the number of registered users and sell products more efficiently.
  • It can meet the requirements of some online businesses like service-based websites or B2B business models that need to create an exclusive store to ask customers to request a quote before purchase. 
  • It is possible for luxury online shops to offer special or exclusive services to their customers who are subscribing to their clubs and increase perceived value from them. 
  • It is beneficial for manufacturers or entrepreneurs who are working in specific market niches to hide their product prices from competitors. 

Conclusion

In this post, we have explained two possible methods for WooCommerce hide price until logged in. Both methods are helpful and enable you to achieve your goal. However, we recommend you use the WooCommerce role-based pricing plugin. With an easy-to-use interface and flexible options for creating rules to show different prices to specific users’ roles or hiding prices for them, it can help you to easily manage your online store based on your needs.

References

businessbloomer