1. Knowledge Base
  2. WooCommerce Product Table
  3. Advanced Usage

How to hide prices unless the user is logged in

There are 2 ways to hide the prices from WooCommerce Product Table from guest users, so that only logged in users can see them.

Option 1 – Use the Catalog Visibility Options plugin

WooCommerce Product Table works nicely with the official Catalog Visibility Options extension. You can use it to hide the price for logged in users.

If you use this plugin to hide the price, then the ‘Price’ column in WooCommerce Product Table will be empty unless the user is logged in. If a guest user clicks on a link to the single product page, the price will not appear on the single product page either.

Some notes on using the plugins together

  • The variation dropdowns still appear in the add to cart column for logged out users, even when Purchases are disabled. This is because the variations are listed for information only, and can’t be purchased. If you don’t want this, then you can disable the variation dropdowns in WooCommerce Product Table.
  • It is important to disable the caching option in WooCommerce Product Table to ensure that the price is shown or hidden correctly for each individual user.
  • The Catalog Visibility Options lets you add some text to appear where the price would normally be displayed. For example, the following screenshot shows some text which can appear in place of the add to cart buttons if these are hidden from logged out users.
WooCommerce Catalog Visibility Table Plugin

Option 2 – Add some custom code

The following code can be used to hide the price from WooCommerce Product Table for guest users. Logged in users will see the product prices as usual (assuming you have included the Price column in the table).

function wcpt_hide_price_unless_logged_in( $price ) {
    if ( !is_user_logged_in() ) {
        return 'Login to see prices';
    }
    return $price;
}
add_filter( 'wc_product_table_data_price', 'wcpt_hide_price_unless_logged_in' );

Please note:

  • This code snippet will hide the price but not the add to cart buttons. If you want to prevent people from purchasing, then it’s only worth using if your product table does not contain an add to cart column. If you have an add to cart column then it’s best to use the Catalog Visibility Options plugin mentioned above, as this can hide the add to cart buttons as well as the prices. 
  • This is advanced usage and does not fall under our standard plugin support. If you don’t know how to use the below code, please ask your developer or post a job on Codeable to find a suitable WordPress expert. 
  • These instructions will only hide the prices from the product table, and not other places on your site such as the single product page, cart, checkout, and order confirmation emails. You would need to write some additional custom code to do this. 
Need professional assistance?
We've partnered with Codeable to provide our customers with expert help if required.

Option 3 – Hide the price from everyone

The above options will hide the price from logged out users only. If you prefer, then you can hide the price from ALL users as follows:

  • Remove the price column from your product tables.
  • When you set up your products, ensure that you do not fill in the price field. Alternatively, if you wish the products to be purchasable but without displaying prices, then you should set the price to 0.00 and ask your developer to add some custom CSS to hide the price columns from the cart and checkout pages, as well as the order confirmation emails.
Still need help?
If searching the knowledge base hasn't answered your question, please contact support.

Related Articles