How to Hide Prices For Not Logged In Customers/Guests

Table Of Contents

    Some shop owners would like to hide the prices in their shop from guests users to make it exclusive for logged-in customers only, such as your wholesalers.

    Unfortunately, we don’t have this feature in our plugins by default. But fortunately, there is an easy workaround to do this by using the custom snippet below:

     

    add_action( 'init', 'wwp_hide_price_add_cart_not_logged_in' );
    
    function wwp_hide_price_add_cart_not_logged_in() {
        if ( !is_user_logged_in() ) {
            remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
            remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
            remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
            remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
            add_action( 'woocommerce_single_product_summary', 'wwp_print_login_to_see', 31 );
            add_action( 'woocommerce_after_shop_loop_item', 'wwp_print_login_to_see', 11 );
        }
    }
    
    function wwp_print_login_to_see() {
        echo '<a href="' . get_permalink(wc_get_page_id('myaccount')) . '">' . __('Login to see prices', 'theme_name') . '</a>';
    }
    

     
    Just simply to add this snippet to your theme/child theme’s functions.php or you can also use the Code Snippets plugin to add this to your site.