1. Home
  2. Knowledge Base
  3. WooCommerce Product Table
  4. Advanced Usage
  5. How to hide prices unless the user is logged in

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 – Install a free plugin

WooCommerce Product Table integrates with the free Hide Price Until Login WordPress plugin.

If you use this option, then the ‘Price’ column in WooCommerce Product Table will be empty unless they are 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.

WooCommerce Product Table also works with the ‘Hide Price According to Role of User’ option. The price column in the table will be empty unless you are logged into the correct user level.

If you use the ‘Hide Price using Password Features’ option then the prices will NOT be hidden in the product table. This is because this feature only works on the single product page – if you click through to the single product page, then the price will be hidden until you enter a password. If you create a product table without a Price column then there will be no prices in the product table, but if you do create a price column then the price will appear for everyone.

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 that 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. Alternatively, get in touch if you’d like a quote from our customisations service. 

Was this article helpful?

Related Articles