Change WordPress user roles and capabilities › Forums › Restrict or Permit access inside WordPress – how to › Role-based meta panel restrict.
Tagged: Adminimize, best wordpress role manager plugin, block selected tabs, Capability Manager Enhanced, How To Manage Tabs On The Product Page, members, product data edit, product page tabs, remove tabs, role based restrict, tab editor, user role editor, User Roles and Capabilities, woocommerce metabox, woocommerce product add-ons restrict, woocommerce product addons restrict, woocommerce product addons tab, woocommerce product data restrict, woocommerce product data tab restrict, woocommerce tab manager, woocommerce tabs, wordpress user roles plugin, WPFront
- This topic has 12 replies, 2 voices, and was last updated 5 years, 1 month ago by usevinc.
-
AuthorPosts
-
10/08/2019 at 16:23 #5870usevincParticipant
Hi, I would like to restrict some parts in the product data panel on the add new product page, as I have given the example below. And I found this method as one of the many ways to do it. But I couldn’t figure out how. I’d appreciate it if you could help me with that. Sorry for my english.(Gtranslate)
Thank you for all.
I want to limit the tabs I’ve written below. Only the General tab should be available. (Advanced, Variations, Attributes, Linked Products, Shipping, Inventory)
echo do_shortcode( ‘[user_role_editor roles=”wc_product_vendors_admin_vendor, etc roles…”]’ .
/**
* Return array of tabs to show.
*
* @return array
*/
private static function get_product_data_tabs() {
$tabs = apply_filters(
‘woocommerce_product_data_tabs’,
array(
‘general’ => array(
‘label’ => __( ‘General’, ‘woocommerce’ ),
‘target’ => ‘general_product_data’,
‘class’ => array( ‘hide_if_grouped’ ),
‘priority’ => 10,
),
‘inventory’ => array(
‘label’ => __( ‘Inventory’, ‘woocommerce’ ),
‘target’ => ‘inventory_product_data’,
‘class’ => array( ‘show_if_simple’, ‘show_if_variable’, ‘show_if_grouped’, ‘show_if_external’ ),
‘priority’ => 20,
),
‘shipping’ => array(
‘label’ => __( ‘Shipping’, ‘woocommerce’ ),
‘target’ => ‘shipping_product_data’,
‘class’ => array( ‘hide_if_virtual’, ‘hide_if_grouped’, ‘hide_if_external’ ),
‘priority’ => 30,
),
‘linked_product’ => array(
‘label’ => __( ‘Linked Products’, ‘woocommerce’ ),
‘target’ => ‘linked_product_data’,
‘class’ => array(),
‘priority’ => 40,
),
‘attribute’ => array(
‘label’ => __( ‘Attributes’, ‘woocommerce’ ),
‘target’ => ‘product_attributes’,
‘class’ => array(),
‘priority’ => 50,
),
‘variations’ => array(
‘label’ => __( ‘Variations’, ‘woocommerce’ ),
‘target’ => ‘variable_product_options’,
‘class’ => array( ‘variations_tab’, ‘show_if_variable’ ),
‘priority’ => 60,
),
‘advanced’ => array(
‘label’ => __( ‘Advanced’, ‘woocommerce’ ),
‘target’ => ‘advanced_product_data’,
‘class’ => array(),
‘priority’ => 70,
),
)
);. ‘[/iscorrect]’ );
I overwrote the above example in the file “class-wc-meta-box-product-data.php”. But unfortunately it did not work. How do I make this restriction? I’m so happy to help you.
10/08/2019 at 16:27 #5871usevincParticipant[/user_role_editor]
I’m sorry the short code closure code will be like this. I copied the sample incorrectly.
I’m waiting for your help to solve the problem, thank you.
12/08/2019 at 03:37 #5872VladimirKeymasterThere is no need to edit woocommerce source code. Use a [user_role_editor] shortcode is not a good idea. It works for the post/page content output only.
Try to use this solution a starting point.
12/08/2019 at 04:33 #5873usevincParticipantOh, my God … I searched in the forum with the words “role-based restriction” and “product data tabs” but I couldn’t find it. That’s a great plugin, brother. Thank you! 😉 =)
12/08/2019 at 04:59 #5874usevincParticipantEverything looks great, Vladimir. However, I cannot remove the woocommerce product add-ons tab. I added it to the bottom of the tabs to be restricted, but it didn’t work. What should I do, I’d appreciate it if you could help. THANK YOU! =)
unset ($ tabs [ ‘woocommerce-product-addons’]);
And I tried that.
unset ($ tabs [ ‘add-ons’]);
12/08/2019 at 16:13 #5875VladimirKeymasterWooCommerce product editor page does not have ‘Addons’ tab by default.
Try to look at the ‘Addons’ link HTML source. What class does it use? Try to use tab ID from the begin of class name, similar to the links above. I suppose it may be simple ‘addons’.12/08/2019 at 18:25 #5876usevincParticipantI’ve reviewed Product Add-ons and woocommerce plug-in files. I’ve tried every possible and more name I’ve listed below. But unfortunately it doesn’t work. I don’t know what the problem is, I can’t figure it out. Help me please. 🙁
unset($tabs[‘wc_pao_params’]);
unset($tabs[‘wc_pao’]);
unset($tabs[‘woocommerce_product_addons’]);
unset($tabs[‘woocommerce-product-addons’]);
unset($tabs[‘product_page_addons’]);
unset($tabs[‘product_addons’]);
unset($tabs[‘product_add-ons’]);
unset($tabs[‘product_add_ons’]);
unset($tabs[‘_product_addons’]);
unset($tabs[‘global_product_addon’]);
unset($tabs[‘addons’]);
unset($tabs[‘addon’]);
unset($tabs[‘add-ons’]);
unset($tabs[‘Add-ons’]);
unset($tabs[‘_wc_pao_addon’]);
unset($tabs[‘_wc_pao_addon_value’]);13/08/2019 at 02:53 #5877VladimirKeymasterOK. Can you tell me what plugin adds ‘Addons’ tab to the product attributes meta box? I need reproduce it myself to see what id it uses.
13/08/2019 at 02:56 #5878VladimirKeymasterIf it’s a paid plugin “Product Add-ons” from WooCommerce, can you share its copy with me via Google drive or DropBox? I use such software for investigation purpose only and at my local development environment.
13/08/2019 at 07:30 #5879usevincParticipantOf course!
13/08/2019 at 07:34 #5880usevincParticipantI’m sending the Gdrive link I’ve authorized for your email address to your “[email protected]” email address. Thank you for your time and effort, Vladimir. =)
14/08/2019 at 05:00 #5882VladimirKeymasterTry to add this line to your code:
remove_action( 'woocommerce_product_write_panel_tabs', array( $GLOBALS['Product_Addon_Admin'], 'tab' ) );
“Product addons” hooks its code somewhere later when ‘woocommerce_product_data_tabs’ filter executed. Thus ‘addons’ tab is not available for manipulation at that moment.
14/08/2019 at 08:07 #5884usevincParticipantYes it all works great in the end. Thank you so much for all your support, Vladimir. =)
Finally, some of the wordpress plug-ins I’ve used as a WordPress User Role Editor before. Adminimize, User Roles and Capabilities, Members, Capability Manager Enhanced, WPFront. But none of them had as detailed and quality product support as the User Role Editor Pro plugin. If you like the User Role Editor plugin and you want to buy it, you can click on one of the links to User Role Editor Pro or WordPress User Roles And Capabilities Manager. Thank you again for everything, Vladimir. 🙂
add_filter('woocommerce_product_data_tabs', 'block_wc_product_tabs'); function block_wc_product_tabs($tabs) { if (!current_user_can('wc_product_vendors_admin_vendor', 'wc_product_vendors_manager_vendor', 'wc_product_vendors_pending_vendor', 'shop_manager', 'customer', 'subscriber', 'employer', 'editor', 'contributor', 'author')) { // replace role/roles ID with your own return $tabs; } remove_action( 'woocommerce_product_write_panel_tabs', array( $GLOBALS['Product_Addon_Admin'], 'tab' ) ); //If you do not use WooCommerce product add-ons, delete this line starting with the "remove_action" section. // If you want to restrict in the following woocommerce tabs, add "//" at the beginning of the line. Example: // unset ($ tabs ['general']); unset($tabs['general']); unset($tabs['inventory']); unset($tabs['shipping']); unset($tabs['linked_product']); unset($tabs['attribute']); unset($tabs['variations']); unset($tabs['advanced']); unset($tabs['wc_pao_params']); return $tabs; }
-
AuthorPosts
- You must be logged in to reply to this topic.