Home / Archive / MemberPress: WooCommerce – Show Specific WooCommerce Product Based on MemberPress Subscription
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: WooCommerce – Show Specific WooCommerce Product Based on MemberPress Subscription

This code snippet will show the specific WooCommerce product only to users who have an active MemberPress subscription for a specific membership.

The sample code will show the Woo product with the ID of 222 to users with active subscriptions to the MemberPress membership with the ID of 1234.

Code Preview
php
<?php
function always_display_products($visible, $prd_id) {
	// Get current user object
	$user = get_current_user();
	// Get current user's active subscriptions
	$active_subs = $user->active_product_subscriptions('ids');
	
	// Check if the user has a specific subscription (ID 1234) and the current product ID is 222
	if (!empty($active_subs) && in_array(1234, $active_subs) && $prd_id == 222) {
		$visible = true;  // Make the product visible
	}
	return $visible;
}
add_filter('woocommerce_product_is_visible', 'always_display_products', 11, 2);

Comments

Add a Comment