Woocommerce hide specific content to users that are not logged in

I’m trying to hide the following content that’s inside of content-product.php to guest users (make it invisible to users that are not registered):

<?php if( get_field('___unit_price') ): ?>
<p>Unit Price: $<?php the_field('___unit_price'); ?></p>

For the life of me I can’t get it to hide. Any help would be appreciated.

Related posts

1 comment

  1. You need more conditional logic.

    <?php if( get_field('___unit_price') ): ?>
    <p>Unit Price: $<?php the_field('___unit_price'); ?></p>
    

    only checks if the get_field() function returns a value, but you also want to check if the user is logged in. Conveniently, WordPress has a function called is_user_logged_in() that checks exactly that.

    <?php if( is_user_logged_in() && get_field('___unit_price') ): ?>
    <p>Unit Price: $<?php the_field('___unit_price'); ?></p>
    <?php endif; ?>
    

Comments are closed.