• gerd.neumann

    (@gerdneumann)


    There’s a incompatibility of Groups with the WooCommerce Subscriptions plugin.

    WooCommerce Subscriptions adds the following filter to check whether a user can “cancel” a subscription (in wcs-user-functions.php):
    add_filter( 'user_has_cap', 'wcs_user_has_capability', 15, 3 );

    To explain (in case you have the Subscriptions plugin and want to reproduce): This is called from wcs_get_all_user_actions_for_subscription function in view-subscription.php which displays certain user actions like “Cancel” when a user views its subscriptions (URL is like my-account/view-subscription/<subscription-id>/).

    The problem is, that when the Groups plugin is installed, then this ‘wcs_user_has_capability’ function never gets called. Here’s the list of registered filters for ‘user_has_cap’ (I checked with the php debugger):

    1. WC_Subscriptions_Product::user_can_not_delete_subscription GETS CALLED
    2. wc_customer_has_capability GETS CALLED
    3. Groups_WordPress::user_has_cap GETS CALLED
    4. wcs_user_has_capability THIS NEVER GETS CALLED

    wcs_user_has_capability should be run after Groups_WordPress::user_has_cap but is never executed. It looks like Groups_WordPress::user_has_cap does some magic stuff – maybe overriding something? – so that the filter after it are not called anymore, but I have no idea why and how.

    If I change the filter registration in the Subscriptions plugin to a lower priority of 10 instead of 15 then the ‘Cancel’ button is shown as it should be:
    add_filter( 'user_has_cap', 'wcs_user_has_capability', 10, 3 );

    Now it works because the 'wcs_user_has_capability' is run before Groups_WordPress::user_has_cap. Here’s the new prio order which works:

    1. wcs_user_has_capability
    2. WC_Subscriptions_Product::user_can_not_delete_subscription
    3. wc_customer_has_capability
    4. Groups_WordPress::user_has_cap

    Is this a bug in the Groups plugin? To me it looks like this.

    Or should the Subscriptions plugin need to do something special? (the Subscription plugin add this filter because it wants to check whether the user has the 'edit_shop_subscription_status' permission.)

    Best,
    Gerd

Viewing 7 replies - 1 through 7 (of 7 total)
  • gregs.legs

    (@gregslegs)

    I’m having the same problem. Changing the priority in Subscriptions plugin fixed it for me too (thanks) But as you say, it does look like a bug in Groups.

    Greg

    thenbrent

    (@thenbrent)

    Hi @gerdneumann,

    Thanks for the excellent bug report. Unfortunately, it looks like I’ll need some more information to reproduce this issue – I haven’t been able to reproduce it with my setup.

    If you haven’t already, can you please create a ticket at WooCommerce.com? If you have created a ticket, can you please let me know the ticket ID and I’ll take a look.

    We should be able to get this sorted for you very quickly once I can reproduce it.

    Brent

    Thread Starter gerd.neumann

    (@gerdneumann)

    Thanks @thenbrent,

    ticket ID is 495035 (https://woocommerce.com/my-account/tickets/?id=495035). The WooCommerce staff was also not able to reproduce this (whereas we can 100% reproduce it, and @gregslegs obviously too). Maybe some particular setting is required for the bug to trigger?! Please let me know if you need anything more, e.g. maybe a screenshot of my Groups settings page or similar?

    Thread Starter gerd.neumann

    (@gerdneumann)

    I did a fresh install of Groups by activating the checkbox “Delete all Groups plugin data on deactivation” under Groups > Options and then deactivating plus activating again afterwards. Then with the fresh install the bug did not occur. That’s why you could not reproduce obviously.

    So I looked at my Groups settings. The described issue only occurs when activating the checkbox "Administrators override all access permissions derived from Groups capabilities" under Groups > Options. No other changes are needed using a fresh Groups install.

    Can you reproduce now?

    thenbrent

    (@thenbrent)

    @gerdneumann thanks a bunch! I’ve reproduced this now.

    Reading the Groups documentation, it is recommended to turn administrator access overrides off, use it for debugging purposes only . That makes it sounds like it will be safe to disable that setting until we are able to find a fix with @itthinx.

    • This reply was modified 8 years ago by thenbrent.
    rtysmith

    (@rtysmith)

    Woo is now recommending the same fix:

    Thank you for your update on this! I’ve done a bit of research on that topic, and it turned out that the Groups plugin was overriding any user roles added through Subscriptions. Because of this, the users could not cancel or change payment methods on their subscriptions, as the privileges for them to do so were accidentally reset.

    In order to fix this, I’ve disabled the Administrator Access Override setting on the Groups > Options page:

    Yes, Woo now recommends this fix… But I just discovered it creates another problem.

    Upon setting up a new site, I installed Subscriptions and Woocommerce first, then installed Groups. I turned off the “Administrator Access Override” to avoid issues with users cancelling subscriptions. I then set Permissions in the Groups > Options for administrators to be able to edit:

    Access Group
    Administer Groups
    Administer Groups plugin options

    …as well as some other site roles. However, upon going to any page or post with an account other than the site super-admin, the Groups metabox tells me that I “cannot administer groups.” I cannot “quick-add” new Groups, or apply them to pages/posts etc.

    When I turn on the “Administrator Access Override,” the capability for another administrator account to edit the settings in this metabox returns.

    I definitely need a fix for this, because we can’t run a Membership site with Subscriptions and also have multiple administrators of Groups…

    Any recommendations from those of you digging into this issue deeper, or plugin authors, is very welcome.

    Highest Regards,
    Adam Apollo

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Incompability with WooCommerce Subscriptions: Problem with user_has_cap’ is closed to new replies.