Restrict WooCommerce Category Access based on BuddyPress Group


I currently have a WooCommerce shop set up with multiple categories and products that are aimed at B2C. I also have BuddyPress set up with a number of groups with members.

How would I split the WooCommerce shop up so we have the B2C shop with its categories and then a B2B shop side that only members of a particular BuddyPress group can access?


  • B2C shop with its categories and products can be accessed by all.

  • B2B shop with its categories and products can only be accessed by
    users in the “Apple” group.

My initial thinking was to have a “B2B” category with the BuddyPress group as a subcategory, eg. “Apple”.

BuddyPress Groups: Apple, Banana, Strawberry

B2C Shop

--Category 1  
--------Product A  
--Category 2  
--------Product B  
--Category 3  
--------Product C 

B2C Shop

--**Apple Group**  
---Category 2  
--------Product D  
--------Product E  

Banana Group

---Category 3  
--------Product F  

Strawberry Group

---Category 3  
--------Product G  

I’ve been able to set up the above hierarchy and I can retrieve the logged-in user’s group using the following code:

if ( !is_product_category() ) {

    $group_ids =  groups_get_user_groups( bp_loggedin_user_id() ); 

    foreach( $group_ids["groups"] as $id ) { 
        $group = groups_get_group( array( 'group_id' => $id) ); 
        echo "<div class='col1 alignCenter padAll marBottom bgGrey clear'>
        <a href='[URL]/category/trade/".$group->name."'>[IMAGE]<br>".$group->name." Trade Shop</a>

I’m unsure how I would restrict other users from simply entering the URL of another group’s category.

, , gromey 3 years 2019-10-31T06:38:34-05:00 0 Answers 86 views 0

Leave an answer