Change WordPress user roles and capabilities Forums Give user access to plugin – how to Need to give a user access to specific page on WooCommerce

Tagged: 

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #6171
    lachero
    Participant

    Hey, How do I grant access only to the “Payments” page on WooCommerce? wp-admin/admin.php?page=wc-settings&tab=checkout
    http://prntscr.com/q6pflt

    Thanks

    #6179
    Vladimir
    Keymaster

    Hi,

    Setup this code as Must Use plugin or add it to your active Theme. It leaves only 2 tabs at WC->Settings page: General and Payments. And replace ‘orders_manager’ role ID with your own one.
    In order to leave Payments only, you need apply more programming efforts, replace link of WC-Settings menu from default one to
    wp-admin/admin.php?page=wc-settings&tab=checkout

    
    add_filter('woocommerce_settings_tabs_array', 'change_wc_settings_tabs', 30);
    
    function change_wc_settings_tabs( $pages ) {
        
    
        $user = wp_get_current_user();
        if ( in_array( 'orders_manager', $user->roles ) ) {
            //unset( $pages['general']);      // General
            unset( $pages['products']);     // Products
            unset( $pages['tax']);          // Tax
            //unset( $pages['checkout']);       // Payments
            unset( $pages['account']);        // Accounts & Privacy
            unset( $pages['email']);          // Emails
            unset( $pages['advanced']);       // Advanced
        }
      
      return $pages;
    }
    
    #6869
    swatkins@fthcm.org
    Participant

    Hi

    What will the code look like if we want to exclude the Payments tab but keep all of the other tabs?

    #6871
    Vladimir
    Keymaster

    Hi,

    Comment lines with tabs to leave, and uncomment lines with tabs you wish to hide/remove.

    
    add_filter('woocommerce_settings_tabs_array', 'change_wc_settings_tabs', 30);
    
    function change_wc_settings_tabs( $pages ) {
        
    
        $user = wp_get_current_user();
        if ( in_array( 'orders_manager', $user->roles ) ) {
            //unset( $pages['general']);      // General
            //unset( $pages['products']);     // Products
            //unset( $pages['tax']);          // Tax
            unset( $pages['checkout']);       // Payments
            //unset( $pages['account']);        // Accounts & Privacy
            //unset( $pages['email']);          // Emails
            //unset( $pages['advanced']);       // Advanced
        }
      
      return $pages;
    }
    
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.