Prices for logged-in customers only
Visitors who aren’t logged in see “Log in to see prices” instead of prices, and can’t add to the cart. For wholesale and trade shops.
Before you switch it on: Nothing to fill in: it stays off after installing because visitors can no longer buy. Translate the link text, then switch it on.
It arrives switched off, even when you install its whole pack with "Switch on after installing".
<?php
add_filter(
'woocommerce_get_price_html',
static function ( $html ) {
if ( is_user_logged_in() ) {
return $html;
}
return '<a class="snipfire-login-price" href="' . esc_url( wc_get_page_permalink( 'myaccount' ) ) . '">Log in to see prices</a>';
},
99
);
add_filter( 'woocommerce_is_purchasable', static fn( $purchasable ) => is_user_logged_in() ? $purchasable : false, 99 );
add_filter( 'woocommerce_variation_is_purchasable', static fn( $purchasable ) => is_user_logged_in() ? $purchasable : false, 99 );
Good to know
Page caches must skip logged-in users (most do). Prices are still in the product feed and REST API: use a membership plugin for real secrecy. Translate the link text.
In these packs
- WooCommerce: shop and product pages: Badges, price display, tabs and layout for your shop and product pages.