How to display product images to logged-in users only in WooCommerce

2019 / 01 / 24

At first, you will need a child theme for your parent theme.

Open functions.php of your child theme and add the following code:

remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );

// conditional logic function for logged-in users
function logged_in_images(){
    // if user is Logged-in, display original product image
    if ( is_user_logged_in() ) {
        echo woocommerce_show_product_images(); 
    // if user is not logged in, display the placeholder image instead
    else {
        echo '<img src="https://via.placeholder.com/150">';
add_action( 'woocommerce_before_single_product_summary', 'logged_in_images', 20 );

Be sure to change the placeholder with your own default image which you want to select.

Hi, I am a full-stack web developer with 5+ years of experience in working with different web technologies. Do you want to ask something? just send me a message through the contact form. Please visit my portfolio at hamzamehmood.com. Thanks