• I created Customer Support -role for WooCommerce with Members plugin.

    Role has capabilities to edit orders etc. Everything else works fine. The Role has access only on WooCommerce -related tools in the WordPress Dashboard.

    But…
    I noticed that Role requires “Edit Posts” -capability to create new Orders from the WP Dashboard.

    I narrowed it down and it seems the problem lies in WordPress core-files:
    wp-admin/includes/plugin.php
    Near line ~2132

    foreach ( array_keys( $_wp_submenu_nopriv ) as $key ) {
    			if ( isset( $_wp_submenu_nopriv[ $key ][ $pagenow ] ) ) {
            die('--THE PROBLEM LIES HERE-- key:['.$key.']['.$pagenow.']<pre>'.print_r($_wp_submenu_nopriv,true).'</pre>');
    				return false;
    			}
    			if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[ $key ][ $plugin_page ] ) ) {
    				return false;
    			}
    		}

    This outputs:
    –THE PROBLEM IS HERE– key:[edit.php][post-new.php]

    which implies because role has no capabilities to add new posts, it overrides ability to create shop_orders.

    If I comment that line out, orders can be created with my new role and the members plugin still restricts access to everything I’ve wanted.

    Still, is there a possibility to programmatically “remove” these core-restrictions, because I can’t modify wordpress core files because that would create monthly extra work.

Viewing 3 replies - 1 through 3 (of 3 total)
  • @temposaur Helping write and troubleshoot custom code isn’t something we’re able to help with ourselves, but I will go ahead and leave this request open in case someone from the community would like to lend a hand. ??

    That said, I do believe that WooCommerce orders are simply a custom post type (that is to say, just a special type of post) so the ability for custom user roles to create orders also depends on those users being able to create posts.

    I think that’s why WooCommerce’s own “Shop Manager” role grants the permissions it does:

    https://github.com/woocommerce/woocommerce/blob/master/includes/class-wc-install.php#L1119

    Anyway, hopefully someone can come along and give you some tips here!

    Thread Starter temposaur

    (@temposaur)

    Yeah, Shop Manager would be almost perfect Role for this, but we don’t want them to access posts/pages and WooCommerce Settings.

    It is weird that without 'edit_posts'=> true capability they can edit orders without any problem, but they just can’t create new ones without it.

    Thread Starter temposaur

    (@temposaur)

    Ok, I’ve narrowed down to WooCommerces “registering order type” (woocommerce/includes/class-wc-post-types.php):

    'show_in_menu' => current_user_can( 'edit_others_shop_orders' ) ? 'woocommerce' : true,

    It seems when displaying orders unden ‘woocommerce’ it handles the capabilities different. When replacing the ‘woocommerce’ to just ‘true’ everything works like it should and I’m able to use “customer support” -role like I want and show them only orders and products. But… Obviously the Orders move under WooCommerce to their own menu item in the Dashboard.

    • This reply was modified 3 years, 2 months ago by temposaur.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Members + WooCommerce’ is closed to new replies.