Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Hide WooCommerce Product Variations Based on User Roles?

When you run a WooCommerce store, you often juggle different product variations, but not every customer should see every option. Instead, hide WooCommerce Product Variations the smart way so customers only see what’s relevant to them.

Think of a Music Festival ticketing site: You might have three customer types.

  • Guest → someone visiting the site without a membership. They should only see the Standard Pass (regular entry).
  • Member → a loyalty club or season pass holder. They should only see the Early Bird Pass, since that discount is meant for them.
  • VIP → premium audience with special privileges. They should only see the VIP Backstage Pass, which gives access to lounges and backstage areas.

Showing all variations at once only clutters the product page, confuses customers, and increases the risk of wrong purchases. With a simple code snippet, you can hide irrelevant WooCommerce product variations and display only what matches the user’s role.

Solution: Hide WooCommerce Product Variations Based on User Roles

Let’s say your store sells a product called “Jingle Land-Music Festival” with three variation attribute values:

  • Early Bird Pass (discounted for advance booking)
  • Standard Pass (regular entry)
  • VIP Backstage Pass (includes lounge + backstage access)

Here’s how it looks in the WooCommerce product edit page:

Your store also has three user roles:

  • guest → general visitors
  • member → loyalty club or season pass holders
  • vip → premium audience

When a user logs in, WooCommerce automatically restricts the product variations so they only see the ticket type assigned to their role.

Add the following snippet to your theme’s functions.php file or via a code snippets plugin.

Note: This code snippet has been tested and works on WordPress 6.8.2 and WooCommerce 10.1.2.
add_filter( 'woocommerce_variation_is_visible', 'ts_hide_variation_by_role', 10, 4 );
function ts_hide_variation_by_role( $is_visible, $variation_id, $product_id, $variation ) {

    // Get the variation's Tickets attribute value (Early Bird, Standard, VIP)
    $tickets = $variation->get_attribute( 'pa_tickets' ); 

    // Compare with USER ROLE NAME (slug)
    if ( ( wc_current_user_has_role('guest1')      && $tickets !== 'Early Bird Pass' )
      || ( wc_current_user_has_role('member2')       && $tickets !== 'Standard Pass' )
      || ( wc_current_user_has_role('vip3')  && $tickets !== 'VIP Backstage Pass' ) ) 
    {
        return false; // hide variations that don't match the role
    }

    return $is_visible;
}

Output

Here’s an example product — a Music Festival Ticket with three variations: Early Bird Pass, Standard Pass, and VIP Backstage Pass.

When a Guest user logs in and visits the product page, they will only see the Early Bird Pass.

When a Member logs in, they will only see the Standard Pass option.

When a VIP logs in, they will only see the VIP Backstage Pass option.

Showing only the variations that matter to each user keeps your product pages simple, without extra options cluttering the page. On a similar note, you might want to make sure customers aren’t seeing options that are out of stock. For that, our guide on How to Hide Out-of-Stock Variations in WooCommerce Shop Page and Product Page walks you through a simple way to hide unavailable variations on both the shop and product pages.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Leave a Reply

Your email address will not be published. Required fields are marked *

Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible.

Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

By using our site, you acknowledge that you have read and understood our Privacy Policy and Terms & Conditions.