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: woocommerce
- This topic has 6 replies, 3 voices, and was last updated 4 years, 6 months ago by Vladimir.
-
AuthorPosts
-
05/12/2019 at 16:23 #6171lacheroParticipant
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/q6pfltThanks
07/12/2019 at 08:50 #6179VladimirKeymasterHi,
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=checkoutadd_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; }
22/05/2020 at 14:04 #6869[email protected]ParticipantHi
What will the code look like if we want to exclude the Payments tab but keep all of the other tabs?
24/05/2020 at 12:30 #6871VladimirKeymasterHi,
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; }
04/06/2020 at 20:26 #6900[email protected]ParticipantThanks for the good support.
04/06/2020 at 21:18 #6901[email protected]ParticipantAnd if I want to apply it to multiple user roles? I am not a coder…
05/06/2020 at 05:19 #6902VladimirKeymasterJust replace roles in the $roles array with your own roles ID:
add_filter('woocommerce_settings_tabs_array', 'change_wc_settings_tabs', 30); function change_wc_settings_tabs( $pages ) { $roles = array( 'role1', 'role2', 'role3' ); $user = wp_get_current_user(); foreach( $roles as $role ) { if ( in_array( $role, $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; }
-
AuthorPosts
- You must be logged in to reply to this topic.