If you’re running a wholesale store, members-only shop, or simply want users to log in before making a purchase, hiding product prices and the “Add to Cart” button for non-logged-in users is a smart move.

This feature is often required when:

  • You want to limit purchases to approved customers
  • You offer special pricing to logged-in members
  • You run a B2B eCommerce store where pricing should be hidden from the public

This tutorial provides a lightweight code snippet and a plugin alternative no heavy WooCommerce plugins required.

What Happens When the User is Logged Out?

When implemented, this customization does the following:

Hides all product prices on:

  • Shop pages
  • Product pages
  • Related product widgets

Replaces prices with a “Login to see prices” message
Removes the Add to Cart button from all templates
Makes products non-purchasable for guests

PHP Snippet: Hide Price & Add to Cart for Logged Out Users

Paste the following snippet into your theme’s functions.php file or use a code snippet manager plugin:

/**
 * @snippet       Hide Price & Add to Cart for Logged Out Users
 * @author        Your Name / Business Bloomer (Modified)
 * @compatible    WooCommerce 9+
 */

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

function custom_hide_price_addcart_logged_out( $price, $product ) {
    if ( ! is_user_logged_in() ) {

        // Replace price with login message
        $price = '<div class="login-to-see-price"><a href="' . esc_url( get_permalink( wc_get_page_id( 'myaccount' ) ) ) . '">' . __( 'Login to see prices', 'your-textdomain' ) . '</a></div>';

        // Remove Add to Cart from shop and single product pages
        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 );

        // Disable purchasing
        add_filter( 'woocommerce_is_purchasable', '__return_false' );
    }

    return $price;
}

Result for Logged-Out Visitors:

  • Price will show: “Login to see prices”
  • No Add to Cart buttons
  • They must log in before they can view prices or buy

Where to Place the Code?

Use any one of the following methods:

Option 1: Child Theme’s functions.php

Recommended if you’re using a child theme:

wp-content/themes/your-child-theme/functions.php

Option 2: Code Snippets Plugin

Use a plugin like “Code Snippets” for safe, plugin-independent storage of your code:

  • No risk of theme updates overwriting your code
  • Easily enable/disable

Troubleshooting: What If It Doesn’t Work?

If the code doesn’t take effect:

  1. Switch to the Storefront theme to rule out theme conflicts
  2. Deactivate all plugins except WooCommerce
  3. Test again with just the snippet
  4. Ensure WooCommerce is updated to the latest version

Some themes override WooCommerce templates — if so, this snippet may need adjustment or be overridden in your custom theme’s woocommerce/ folder.

Conclusion

Requiring login before showing product prices or allowing purchases is a common WooCommerce customization especially for B2B, private, or wholesale stores.

With this guide, you’ve learned how to:

  • Hide prices and Add to Cart buttons for guests
  • Redirect users to the login page
  • Use a lightweight plugin alternative (if coding isn’t your thing)

Want more WooCommerce tips like this? Bookmark this blog and explore more below!