• Resolved Tommy O.

    (@tommyo)


    Hello,

    I’m having an issue with Woocommerce shortcodes when activating the Groups plugin.

    I’ve installed WordPress 4.8.1 (default 2017 theme) and Woocommerce 3.1.1, and created:
    10 products that should be public (no restriction at all).
    10 that should be visible to group A.
    10 that should be visible to group B.
    10 that should be visible to groups A and B.

    After installing and activating Groups 2.3.0, i’ve:
    * Created ‘Group A’ and ‘Group B’.
    * Created 2 new users, and assigned one to ‘Group A’ and the other to ‘Group B’.
    * Set access restrictions on the products as described above.

    What happens:
    On the Woocommerce ‘Shop’ page the products are displayed properly:
    – 10 products when logged out.
    – 30 products when logged in, with each user seeing the products matching their assigned group.

    On a page that displays all products, using the shortcode – [products ids=”1, 2, 3, 4, 5 …”] (listing all products in the store), i’m seeing 30 products correctly when logged in as a user of group A, but only 20 when logged in as a user of group B.
    I’ve verified that all products and users are set-up correctly, and while this is happening, the ‘Shop’ page shows the correct number of products – 30 (for each user).

    This is also having an effect on the Elegant Themes – Divi Theme i’m trying to install with the shop, which relies on shortcodes, and as a result doesn’t display products correctly in it’s front page ‘Shop’ module. It isn’t showing products that the user should have access to, based on their group.

    WC shortcodes list:
    https://docs.woocommerce.com/document/woocommerce-shortcodes/
    I’ve also tried to use other shortcodes from the list, with similar results.

    Any help would be greatly appreciated, as i’ve tried to reinstall / deactivate / wipe everything a few times, with no success so far.

    Thank you.

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter Tommy O.

    (@tommyo)

    I’m attaching screenshots of the Groups plugin settings, WP users that are used, and the Woocommerce products list (with access control settings):

    View post on imgur.com

    Plugin Author Kento

    (@proaktion)

    Hi Tommy,

    I’ve set up the following to check:

    Groups: A, B
    Products: Test A, Test B each restricted to the respective groups and another product “Test” which is not restricted and “Test A B” which is restricted to groups A and B.
    Users: A couple of users, a and b, one belongs to group A, the other to group B

    I’ve used the [products ids=”…”] shortcode to render the four products on a page.

    My admin (who belongs to groups A and B) is shown all three products.
    User a who belongs to group A sees products Test, “Test A” and “Test A B”
    User b who belongs to group B sees products Test, “Test B” and “Test A B”

    So this example is working fine … I can’t really see why your second user would only see a reduced set of products. Which products does the user who can only see 20 products see?

    Thread Starter Tommy O.

    (@tommyo)

    Hi Kento,

    I’m attaching screenshots of what the users are seeing.
    User ‘student’ is in group ‘Students’ (Group A).
    User ‘alumni’ is in group ‘Alumni’ (Group B).

    student is seeing 20 products (missing 10 from group ‘Students’):

    View post on imgur.com

    alumni is seeing 30 products correctly:

    View post on imgur.com

    Here you can see the setting for the WP users, Woocommerce products and Groups settings:

    View post on imgur.com

    You might have to create some more products to replicate this issue, as it seems to be inconsistent and doesn’t always happen.
    Sometimes the problem occurs with the ‘student’ user, sometimes it happens with the ‘alumni’ user and sometimes it works correctly for both.

    Plugin Author Kento

    (@proaktion)

    Ok thanks that’s very odd. You don’t happen to have any caching for logged in users activated? That could mess things up … if it doesn’t happen always, it could be the cause.

    Thread Starter Tommy O.

    (@tommyo)

    Hi,

    I’ve tried clearing my local cache, and we don’t have any server side caching plugins or tools as far as i can see.
    After clearing it, products visibility remained the same as before.

    I’ve also tried to create 1 of each product the same way you did, with new groups, users and products, but i’m having the same problem again for both users. this time they can’t see any of the products that have access restrictions on them. only the one that is public (no group restrictions).

    By the way, my server specifications (if this might have anything to do with the problem) are:
    PHP 5.6.31
    MySQL 5.5.55

    Plugin Author Kento

    (@proaktion)

    Thanks for that, have you checked if there are any issues with PHP memory limits? If you’d like us to have a look at your site, please email support at itthinx dot com with a link to this conversation.

    Thread Starter Tommy O.

    (@tommyo)

    PHP memory limit is set to 256 MB. We’ve had no issues with it so far.

    I’ve sent an email with login details to your support email.

    Thank you

    Plugin Author Kento

    (@proaktion)

    Ok perfect, but we haven’t received the email. Could you please resend it to itthinx at gmail dot com? Looks like the mail server hasn’t received it.

    Thread Starter Tommy O.

    (@tommyo)

    I’ve resent the email to both addresses.

    Plugin Author Kento

    (@proaktion)

    Ok thanks, got it.

    Plugin Author Kento

    (@proaktion)

    I’ve tried a few variations on your all-products page, and got odd results .. I think now I know why.

    I’ve taken a look at how this [products] shortcode is implemented, it uses transients to store results for a particular shortcode instance based on some parameters, among them the product IDs that have been passed to the shortcode. If you have a look at your all-products page and check the results it produces for the shortcode where only IDs of unrestricted products are included – under “Products not assigned to groups” and “Products not assigned to groups, using a different order” – it will show all products the user is allowed to view, even if their IDs are not passed to the shortcode. I think the shortcode is accessing the same transient although the parameters are different. To me this is a bug in the shortcode and I wouldn’t use it.

    A possible solution if you still want to use it, group the products like I’ve done on your page. Imagine products 123 and 234 belong to one group while products 345 and 456 belong to another group. As you can see on your all-products page, this seems to work:

    [products id="123,234"]
    [products id="345,456"]

    You could display some additional info conditionally using [groups_member] :

    [groups_member group="Students"]Hey Students, here are your products: [products id="123,234"][/groups_member]
    [groups_member group="Alumni"]Dear Alumni, we have these fine products exclusively for you: [products id="345,456"][/groups_member]

    I hope that this helps you, I’ll mark this as resolved with the above solution (although I still would rather recommend to look for other ways instead of using that shortcode).

    Please feel free to ask if you need further help.

    • This reply was modified 8 years, 9 months ago by Kento. Reason: marking code
Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Groups access control doesn’t work for all users’ is closed to new replies.