Hide Price & Add to Cart for Logged Out Users in Woocommerce

In order to hide Prices and Add to Cart for unregistered users on shop page and single product page and also show specific message “Login to see prices” instead of price or add to cart button on the single product page or Shop page. Let’s do this. Paste this code in your theme’s functions.php file of your active child theme (or theme).

Save the file and log out from admin panel to check the changes on the front-end:

Hide-Price-Add-to-Cart-for-unregistered-users

// Hide price and add-to-cart button for guest users
add_action( 'init', function() {

    // Hide price
    add_filter( 'woocommerce_get_price_html', function( $price ) {
        if ( ! is_user_logged_in() ) {
            return '';
        }
        return $price;
    });

    // Hide add to cart button
    add_filter( 'woocommerce_is_purchasable', function( $purchasable, $product ) {
        if ( ! is_user_logged_in() ) {
            return false;
        }
        return $purchasable;
    }, 10, 2 );

});
Scroll to Top