Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Vladimir Garagulya

    (@shinephp)

    Hi,

    The workaround is to add ‘edit_posts’ to the ‘Factory Manager’ role. WooCommerce has the code with this comment:
    “Prevent any user who cannot ‘edit_posts’ (subscribers, customers etc) from accessing admin”

    Thread Starter popsantiago

    (@popsantiago)

    Hey Vladimir,

    I tried it and it fixed it. But (as every time ?? ) i don’t want my Factory Manager can create posts…

    Any advise to fix it differently ?

    Thanks

    Plugin Author Vladimir Garagulya

    (@shinephp)

    WooCommerce manage this with code:

    /**
    	 * Prevent any user who cannot 'edit_posts' (subscribers, customers etc) from accessing admin
    	 */
    	public function prevent_admin_access() {
    
    		$prevent_access = false;
    
    		if ( 'yes' === get_option( 'woocommerce_lock_down_admin', 'yes' ) && ! is_ajax() && ! ( current_user_can( 'edit_posts' ) || current_user_can( 'manage_woocommerce' ) ) && basename( $_SERVER["SCRIPT_FILENAME"] ) !== 'admin-post.php' ) {
    			$prevent_access = true;
    		}
    
    		$prevent_access = apply_filters( 'woocommerce_prevent_admin_access', $prevent_access );
    
    		if ( $prevent_access ) {
    			wp_safe_redirect( wc_get_page_permalink( 'myaccount' ) );
    			exit;
    		}
    	}

    so add to your theme functions.php file following code:

    add_filter('woocommerce_prevent_admin_access', 'allow_admin_for_fm_role', 10, 1);
    function allow_admin_for_fm_role($prevent_access) {
       if (current_user_can('factory_manager')) {
         $prevent_access = false;
       }
    
       return $prevent_access;
    }

    Thread Starter popsantiago

    (@popsantiago)

    Hi Vladimir !
    You are my hero of the day ??
    Your snippet make the job !
    So really thank to you
    Have a nice day (like me now !)
    Pop

    hi Vladimir,
    I want to customize a role who can approve order after its placed and also track which user approved the order.

    Can you please help me with this.

    Thanks.

    I mean admin should be able to track which user approved the order.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom role & Woocommerce’ is closed to new replies.