Home › Toolset Professional Support › [Resolved] Allow Woocommerce users (customer role) edit custom post type
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | - |
- | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | - |
Supporter timezone: Europe/London (GMT+00:00)
Tagged: Setting up custom types, Types plugin
Related documentation:
This topic contains 13 replies, has 2 voices.
Last updated by Nigel 6 years, 4 months ago.
Assisted by: Nigel.
Hello
We have created a CPT "Projects".
When a user orders a product we create automatically a CPT.
For some reason, the role customer cannot edit this CPT. Even when we access the post in the backend and want to change the author, it is not present in the author drop down.
Our next try was to use hidden link to edit the "customer" role and allow the to edit the CPT "Projects", but there are is no CPT visible there.
How can we achieve this, so users with the role "customer" are allowed to edit this CPT created with WP-Types?
Thanks
Aldo
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
It sounds like you need to use Access to manage the abilities of the customer role.
In my screenshot, taken from Toolset > Access Control, you can see that I am updating the rights of the customer role to be able to publish, edit, delete Project posts.
The settings are fairly self-explanatory, but you can read more about it here: See https://toolset.com/documentation/user-guides/setting-access-control/
Hi Nigel
Thanks a lot for the quick feedback.
Is there another way without Access?
I feel it’s a bit an overload to install the plugin just for this purpose.
Best,
Aldo
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Hi Aldo
WooCommerce doesn't provide any means to customise the capabilities of the customer role when it is registered, and their own documentation recommends using 3rd-party plugins if you want to modify them (https://docs.woocommerce.com/document/roles-capabilities/).
If you don't want to use a plugin then you would have to write a custom solution for that, which involves registering the post type with the capabilities specified, and then adding those capabilities to the role.
I haven't done that myself, I would use something like this as a starting point: https://wordpress.stackexchange.com/a/108375/35739
Hi Nigel
Ok, I ended up installing Access.
I set everything as you showed in the screenshot.
But I'm still not able to change the author oaf the CPT to a user with the role "customer".
Why not?
Thanks
Aldo
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Hi Aldo
I tried this myself and found that modifying permissions for WooCommerce roles doesn't appear to be working.
Our documentation describes creating custom roles for WC (rather than modifying existing roles): https://toolset.com/documentation/user-guides/custom-woocommerce-roles-admin-capabilities/
But the UI lets you try to modify WC roles, including an advanced mode in the Custom Roles tab (see screenshot).
Something doesn't add up, and I'm escalating this so that my colleagues can investigate further to establish what should work, and confirm that it does.
I'll keep you posted.
Hi Nigel
Thanks for the feedback.
As a workaround for now, is there a way to assign two roles to a WooCommerce user when he is registering?
Thanks
Aldo
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Access currently doesn't have support for multiple roles, so that may prove counterproductive.
What you could do is create a custom role in Access based on the customer role with additional permissions as required, and then assign that role to new WC users *instead* of the customer role.
There are many solutions to that if you Google, such as this one: hidden link
(You won't need to create the role programmatically, because you'll do that in Access, you just need to assign that role.)
I'll leave this as escalated in the meantime.
I made some further testing and I think there is an issue with WP Types.
I created a CPT with WP Types.
Now I create a new post with this custom post type.
The I'm only able to associate users with a role of admin or author. But none of the by me created roles appear in the author dropdown.
Why?
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
My colleague who is looking into this replied moments ago to say that he is finding problems with the users offered in that author dropdown unrelated to WooCommerce which appears to affect roles more generally.
He needs to spend more time on it, but is finishing for today (different timezone).
I suggest you leave working on this until he is able to resume testing tomorrow so that we can give you some clear advice and you don't waste time on something that may not work.
Any news on this? We would like a fix to move on 😉
Thanks
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Sorry for the delay in getting back to you, I've been discussing with my colleague, who has been looking at the core WP code responsible for generating the post author dropdown, which is set up to only display roles of contributor or above, and which won't include other roles even if they have been given publishing rights.
We need to see if we can update Access to handle this internally, but for now I spent some time reviewing the WP code responsible for generating the author dropdown and came up with a workaround for you.
You'll need to add the following code to your theme's functions.php file:
add_filter( 'wp_dropdown_users_args', 'tssupp_fix_author_dropdown' ); function tssupp_fix_author_dropdown( $query_args ){ global $pagenow; if (( $pagenow == 'post.php' ) || (get_post_type() == 'post')) { // Only modify dropdown users on a post edit screen $query_args['who'] = ''; $query_args['role__in'] = array( 'administrator', 'editor', 'author', 'contributor', 'customer' ); } return $query_args; }
Note that I have added 'customer' to the normal roles which should appear in the dropdown, and you can add others if needs be.
Please try that and let me know if it works okay.
Hi Nigel
Thanks a lot!
This looks good and does the job.
Would be great, if you could add this to Access 😉
But I still do not understand with this is WP core behavior. Should it not respect the defined roles and there settings?
Thanks
Aldo
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
I didn't get as far as determining how exactly WordPress decides what counts as an author for that dropdown, but I raised an internal ticket for the Access project to handle this ourselves, and we have a new dev cycle beginning for Access within the next week so it should hopefully be managed then.