I created a site with buddypress and WooCommerce and everyone can upload products to the store. The idea is that if you're a friend of the author, you can buy the product.
I have customized the file simple.php WooCommerce / single-product / add-to-cart / folder and I've added this code:
global $bp;
if (friends_check_friendship( !bp_displayed_user_id(), bp_loggedin_user_id())) {
echo ' Add To Cart';
}
elseif (!friends_check_friendship( !bp_displayed_user_id(), bp_loggedin_user_id())) {
echo 'Only Friends';
}
But it does not work. This code only works if you are the administrator, and always have to be a friend of the administrator to display the "Add To Cart" button. Why is this happening?
bp_displayed_user_id()
only works on BuddyPress profile pages.Assuming the single-product page was created by a specific user, you need the author id.
Try this: