Hide WooCommerce Prices for Non-Logged-In Users

Sometimes you want to encourage users to register or log in before seeing product prices on your WooCommerce store. This snippet hides all product prices for visitors who aren’t logged in and displays a custom message instead. It’s a simple way to increase user registration and protect your pricing information.

<?php

// WP Snippet Press – WooCommerce snippet
// Hide product prices for non-logged-in users

add_filter( 'woocommerce_get_price_html', 'wpsnippetpress_hide_price_for_guests' );

function wpsnippetpress_hide_price_for_guests( $price ) {
    if ( ! is_user_logged_in() ) { // Check if user is logged in
        return '<span class="wpsp-login-msg">Login to see price</span>'; // Replace price with message
    }
    return $price; // Show normal price for logged-in users
}
PHP

Usage:

Hide product prices for visitors who aren’t logged in to encourage account creation.

Benefits:

  • Encourages User Registration – Visitors must log in to see pricing.

  • Protects Product Information – Prevents competitors or bots from easily scraping prices.

  • Lightweight & Safe – Uses a small code snippet; no additional plugins required.

Frequently Asked Questions

Yes. Change the text inside to whatever you prefer.
Yes. This applies to all product types and all pages (shop, product archive, single product).
Yes. You can add a conditional check with has_term() or is_product_category() to target specific categories.

Related Links

Related Snippets

Display Gravity Forms Entries for the Logged-In User
Display Gravity Forms submissions for logged-in users on the frontend using a simple shortcode. Learn...
Disable WordPress Emoji Script Site-Wide
Disables WordPress emoji script site-wide to improve performance....
Picture of Kishan D
Kishan D
I’m a web developer who builds with WordPress, WooCommerce, and Shopify, and I enjoy exploring React and creating gaming & tech content.

SHARE POST

Leave a Reply