Hide product description for non-logged users in WooCommerce

if ( ! function_exists( 'wpcb_hide_product_description_for_non_logged_users' ) ) {
    /*
     * wpcb_hide_product_description_for_non_logged_users.
     *
     * @see https://wpcodebook.com/snippets/hide-product-description-for-non-logged-users-in-woocommerce/
     */
    function wpcb_hide_product_description_for_non_logged_users( $content ) {
        return ( is_product() && ! is_user_logged_in() ? 'You must be logged in to see the product description.' : $content );
    }
    add_filter( 'the_content', 'wpcb_hide_product_description_for_non_logged_users', PHP_INT_MAX );
}

You can add this snippet to your (child) theme's functions.php file.

No comments yet.

Leave a Reply