Hide Prices and Purchasing From Guests
Shows a "Log in to see prices" link instead of prices and disables purchasing until the visitor logs in. Common for wholesale and B2B shops.
Opens WPIDE on
Code
add_filter( 'woocommerce_get_price_html', function ( $price ) {
if ( is_user_logged_in() || is_admin() ) {
return $price;
}
return '<a class="wpide-login-for-price" href="' . esc_url( wc_get_page_permalink( 'myaccount' ) ) . '">Log in to see prices</a>';
}, 99 );
add_filter( 'woocommerce_is_purchasable', function ( $purchasable ) {
return is_user_logged_in() ? $purchasable : false;
}, 99 );
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.