wordpress

How to Control VIP Membership Banner Visibility in WooCommerce with Custom Code

The Problem: Inconsistent VIP Banner Display 🤔

In our previous article (How to Build a VIP Membership Site on WordPress & WooCommerce), we implemented a membership system using WordPress, WooCommerce, and subscription models. However, we identified a user experience issue:

The VIP promotion banner appeared inconsistently across different user scenarios:

  • Displayed on regular products for non-members ✅

  • Still visible on VIP product pages for members ❌

  • Appeared for upgraded VIP members viewing any products ❌

This created confusion and diminished the premium experience for paying VIP members.

The Solution: Conditional Banner Display Logic 🎯

After thorough testing, we developed a PHP-based solution that controls banner visibility based on two critical factors:

  1. Product type (VIP vs. regular products)

  2. User membership status (logged-in VIP members vs. non-members)

Implementation Code Snippet

/**
 * Controls VIP promotional banner display based on user membership and product type
 * @return void
 */
function display_vip_banner_based_on_role() {
    // Default to showing banner
    $show_banner = true;

    // Get current product data
    global $product;
    
    // Check if current product is a VIP membership product
    if ($product) {
        $product_url = get_permalink($product->get_id());
        $product_name = $product->get_name();
        
        // Hide banner on VIP product pages
        if ($product_url === 'https://www.wolzq.com/product/wordpress-plugins-vip-subscription' || 
            $product_name === 'VIP Membership Purchase') {
            $show_banner = false;
        }
    }

    // Check user membership status for logged-in users
    if ($show_banner && is_user_logged_in()) {
        $user_id = get_current_user_id();
        
        // Verify active membership using YITH Membership function
        if (function_exists('yith_wcmbs_user_has_membership') && yith_wcmbs_user_has_membership($user_id)) {
            $show_banner = false;
        }
    }

    // Display banner only for non-members viewing regular products
    if ($show_banner) {
        $banner_html = '
        <div style="background-color: #fff3cd; border-left: 4px solid #ffc107; padding: 10px 15px; margin: 0px 0; border-radius: 4px;">
            <p style="margin: 0; font-weight: bold; color: #856404;">🚀 SMARTER DEAL: <a style="color: #d10000; font-weight: bold;" href="https://www.wolzq.com/product/wordpress-plugins-vip-subscription">Get UNLIMITED Access with VIP Subscription →</a></p>
        </div>';
        echo $banner_html;
    }
}
add_action('woocommerce_product_meta_start', 'display_vip_banner_based_on_role', 25);

Implementation Steps for WordPress WooCommerce Sites 📋

Step 1: Install Code Snippets Plugin

First, install and activate the Code Snippets plugin, which allows safe PHP code implementation without modifying theme files.

Step 2: Create New Snippet

  1. Navigate to: Snippets → Add New

  2. Paste the provided code

  3. Set execution location: Run snippet everywhere

  4. Activate the snippet

Step 3: Woodmart Theme Integration (Optional)

For Woodmart theme users:

  1. Navigate to: Woodmart Theme Settings → Single Product → Custom Content

  2. Insert shortcode or custom HTML to trigger the code snippet

  3. Save changes

Expected Behavior After Implementation ✅

Scenario 1: Non-Logged-In Users

  • Regular products: VIP banner visible

  • VIP products: No banner displayed

Scenario 2: Logged-In Non-Members

  • Regular products: VIP banner visible

  • VIP products: No banner displayed

Scenario 3: VIP Members

  • All products: No banner displayed (premium experience maintained)

Best Practices for WordPress Membership Sites 🔧

  1. Use reliable membership plugins: YITH Membership, MemberPress, or WooCommerce Memberships

  2. Test user roles thoroughly: Always verify functionality across all user types

  3. Implement caching considerations: Ensure membership checks work with caching systems

  4. Maintain code documentation: Comment your customizations for future maintenance

Conclusion 🏁

This implementation provides a sophisticated solution for controlling promotional content visibility based on user membership status—an essential feature for any WordPress membership site or WooCommerce subscription business.

The custom code approach offers flexibility beyond what most themes and plugins provide natively, allowing for precise control over the user experience for both regular customers and premium VIP members.

Pro Tip: Always test custom code implementations on a staging site before deploying to production, and consider adding error logging to handle any unexpected behaviors.