Restrict purchase of product to group but show whole product to all

Posted in

Is there a programmatic way to hide the “buy button” to users of a group but show the rest of the content to all visitors? We are using Groups and Groups WooCommerce, but it appears we can only hide or show the entire listing, not just restrict access to actual purchase (we know this can be done with Woo Memberships, but need to use Groups due to another integration that is exclusive to Groups)

One Response to Restrict purchase of product to group but show whole product to all

  1. George September 25, 2018 at 1:06 pm #

    Hi Jill,

    The easiest way to check the user for a given group is Groups_User_Group::read( $user_id, $group_id ). If the user doesn’t belong to a group, then don’t show the add to cart button.
    Regarding WC an interesting method for this is is_purchasable(), but the tricky part resides to the fact that you should add the group conditional to all types of product templates and to the product catalog.
    I haven’t tried it myself but this is how I would implement it.

    Kind regards,
    George

We use cookies to optimize your experience on our site and assume you're OK with that if you stay.
OK, hide this message.

Affiliates · Contact · Jobs · Terms & Conditions · Privacy Policy · Documentation · Downloads · Useful Plugins · My Account

Share