# 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.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, prices, wholesale, b2b
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-hide-prices-for-guests/

## Code

```php
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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Hide Prices and Purchasing From Guests" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
