Skip to content
Snippet

Hide prices for logged-out visitors in WooCommerce

Show a "Log in to see prices" message instead of the price and add-to-cart button for guests.

PHP · functions.php
add_filter( 'woocommerce_get_price_html', function ( $price ) {
	return is_user_logged_in() ? $price : '<a href="' . esc_url( wc_get_page_permalink( 'myaccount' ) ) . '">Log in to see prices</a>';
} );
add_filter( 'woocommerce_is_purchasable', function ( $purchasable ) {
	return is_user_logged_in() ? $purchasable : false;
} );
Where to put itPaste it into your child theme’s functions.php, or add it with a code-snippets plugin. Never edit the parent theme — updates overwrite it.

Last updated September 24, 2026 · Code is GPL-2.0-or-later.

Get a quote