Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

PHP Customization for WooCommerce + Groups Plugin WordPress

  • REFUNDED

Hello,

I'm designing a site for a client who will be selling professional eyelash extension supplies. Some of the things she's selling are tweezers, which she can sell to anyone. Some of them are the lashes and adhesive, which she can only sell to licensed cosmetologists. She needs people to send her their information, so that she can verify their license status, and then she was going to manually check each order and only process it if they had verified with her already, but that seems messy for her. I devised a way to bring a certain amount of automation to the process, but need some custom PHP to pull it off, and I'm still learning my way around PHP.

The site is going to run on WooCommerce. They have an extension called "Groups for WooCommerce" which is a bridge between the Groups plugin (which grants permissions to restricted content based on if WP users are a member of specified groups), and the WooCommerce account stuff. The idea is that we'll use Gravity Forms for people to submit their license verification stuff for her, and then once they've been approved she'll add them to an "Approved" group and they'll get an account on her site that will allow them to purchase the cosmetologist-only supplies.

The annoying thing about the Groups plugin is that you can restrict access to an entire product, but that it makes that product completely invisible to everyone who isn't part of that group, and logged into their account. That won't work because we need people to be able to view the product and see the price in order to incentivize people to send in their credentials and get approved to buy from her. What I need is to make sure people who haven't been approved can't BUY the product, which means having the access restriction only apply to the 'add to cart' button itself, not the whole product.

I basically need a PHP if-statement that I can put around the 'add to cart' button that will only allow it to show up if people are logged in and part of the "Approved" group. It also needs to take into account a product category, perhaps called "Restricted", so that the if-statement only applies to those products that verify approval. If they are not logged in and don't have access to the product, instead of the add to cart button just not showing up, in an ideal world it would present a little blurb saying "You can only purchase this product if you're a licensed cosmetologist. Click here to verify your status. If you've already been verified, click here to login." or something.

So basically- I need a few lines of PHP to put around the 'add to cart' button in WooCommerce that will:

-IF the product is in the "Restricted" category, verify that someone is a member of the "Approved" group.
-IF they are, then display the add to cart button
-IF they are NOT, then display blurb asking for verification or login

Thank you!

-Kaitlin

Answers (1)

2013-02-20

Plugarized answers:

Try this shortcode

[groups_member group="Aproved"]
****cart button is here*****
You can only purchase this product if you're a licensed cosmetologist
[/groups_member]


Basically thats a shortcode from the woocommerce groups plugin.

<strong>Shortcodes</strong>
<blockquote>Limit content visibility
These shortcodes are used to limit the visibility of the content they enclose:
[groups_member]
[groups_non_member]
[groups_can]
[groups_can_not]
Example:
[groups_member group="Gold"]
Only members of the Gold group can see this.
[/groups_member]</blockquote>


Kaitlin comments:

Thank you, LatinUnit! I'm going to put up the development site tomorrow evening so I'll be able to test answers then.

Unfortunately, that in and of itself won't accomplish what I need, because it has to take into account if the product is in a specific category, and then display the button (if they're in the approved group) or display a notice that they have to be a cosmetologist.


Plugarized comments:

<strong>Well lets start with all members who belong to the Approved group can see the cart button</strong>

$user_id = get_current_user_id();
$group = Groups_Group::read_by_name( 'Aproved' );
if ( Groups_User_Group::read( $user_id, $group->group_id ) ) {
// code for cart
}


<strong>Now, perhaps the "Restricted" category is a custom post type/taxonomy therefore the code would look like</strong>

$user_id = get_current_user_id();
$group = Groups_Group::read_by_name( 'Aproved' );
if ( Groups_User_Group::read( $user_id, $group->group_id ) && is_singular( array( 'product', 'restricted' ) ) ) {
// code for cart
}


Perhaps something like this could work.


Plugarized comments:

Else display a message

<?php
$user_id = get_current_user_id();
$group = Groups_Group::read_by_name( 'Aproved' );

if ( Groups_User_Group::read( $user_id, $group->group_id ) && is_singular( array( 'product', 'restricted' ) ) ) {
// code for cart
} else {
echo "You can only purchase this product if you're a licensed cosmetologist";
}

?>


Kaitlin comments:

Didn't work at all- thank you for trying though...