Hide a specific product variation for unlogged users in WooCommerce

Hide a specific product variation for unlogged users in WooCommerce on your child site.

Snippet Type

Execute on Child Sites

Snippet

add_filter( 'woocommerce_variation_is_visible', 'hide_specific_product_variation', 10, 4 );
function hide_specific_product_variation( $is_visible, $variation_id, $variable_product, $variation ) {
    // Here define the variation(s) ID(s) to hide
    $variations_ids_to_hide = array('139');
    
    // For unlogged user, hide defined variations
    if( ! is_user_logged_in() && in_array($variation_id, $variations_ids_to_hide ) ) {
        return false;
    }
    return $is_visible;
} 

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.