WooCommerce is designed for the only shop owner by default. Yes, you may assign the ‘Shop Manager’ role more than to one user simultaneously, but all of them will have the same permissions. All of them will be the boss at your e-shop. What to do if you wish that your e-shop has multiple sellers with limited rights for editing their own selling items only? That is a seller or vendor (e.g. software developer) may input and publish at your e-shop his own items (software applications) only? Is it possible without additional programming? Read further and I show you one of the possible decisions.
Yes, you may configure WordPress and WooCommerce to work correctly with multiple vendors. Answer is simple. Woocommerce products is a custom post type. WordPress works with custom post types exactly the same way as it does that with standard posts. Thus your vendors may have the same permissions on their own selling products as standard WordPress authors have for their own posts.
We need to create the duplicate of the ‘Author’ WordPress role, but for WooCommerce products, not WordPress posts.
You may do it easily with help of the User Role Editor WordPress plugin. Step by step description of actions needed follows:
- Download and install User Role Editor plugin;
- Create new role (e.g. ‘Vendor’) as the copy of the Author role;
- Select the same list of WooCommerce capabilities from the custom capabilities list at the bottom as the Author role has at the top. Just change ‘post’ to the ‘product’ to make relation between them. In case you do not wish to give your vendors permissions to make posts, exclude all core capabilities from the new created ‘Vendor’ role, except the ‘read’ one. Finally your ‘Product Owner’ role should contain these capabilities for begin:
– read,
– upload_files,
– delete_product,
– delete_products,
– delete_published_products,
– edit_product,
– edit_products,
– edit_published_products,
– publish_products,
– read_product. - Change role of the users, you select to be the product owners, to the “Vendor” role. Go to the user profile for that;
- Create some products from the side of those users;
- Go to the ‘Products’ list and check that user with ‘Product Owner” role could edit his products only;
I recorded the short support video on the subject. It has no sound, but with process description above you will understand the show easy, I hope.
Did we resolve all problems on the declared subject? Almost Yes. Why almost? Woocommerce has ‘Prevent customers from accessing WordPress admin’ option at the ‘Settings’ page. If you turn it on, not only customers will lose access to the WordPress admin dashboard, but your new configured happy vendors too. Why it is happened?
WooCommerse plugin manages this by checking if user has ‘edit_posts’ or ‘manage_woocommerce’ capabilities.
So, the easiest way to fix the issue, just add ‘edit_posts’ capability to the ‘Vendor’ role.
2nd way needs to edit woocommerce plugin source code, and restore this modifications after every plugin update:
At file woocommerce-core-functions.php
at line #392 replace the original function with this one
392 393 394 395 396 397 398 399 400 | function woocommerce_disable_admin_bar( $show_admin_bar ) { if ( get_option('woocommerce_lock_down_admin')=='yes' && ! ( current_user_can('edit_posts') || current_user_can('manage_woocommerce') || current_user_can('edit_products')) ) { $show_admin_bar = false; } return $show_admin_bar; } } |
if you compare code you will see that I added ” || current_user_can(‘edit_products’)” condition. You may replace ‘edit_products’ with role name ‘vendor’ (lowercase), if you wish. Make the same for admin/woocommerce-core-functions.php
, at line # 256 replace original function with this version
256 257 258 259 260 261 262 | function woocommerce_prevent_admin_access() { if ( get_option('woocommerce_lock_down_admin') == 'yes' && ! is_ajax() && ! ( current_user_can('edit_posts') || current_user_can('manage_woocommerce') || current_user_can('edit_products') ) ) { wp_safe_redirect(get_permalink(woocommerce_get_page_id('myaccount'))); exit; } } |
Select variant you like better.