Incompability with WooCommerce Subscriptions: Problem with user_has_cap
-
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 inview-subscription.php
which displays certain user actions like “Cancel” when a user views its subscriptions (URL is likemy-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 afterGroups_WordPress::user_has_cap
but is never executed. It looks likeGroups_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 beforeGroups_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
- The topic ‘Incompability with WooCommerce Subscriptions: Problem with user_has_cap’ is closed to new replies.