Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #5870
    usevinc
    Participant

    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)

    https://ibb.co/41zVyGC

    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.

    https://ibb.co/41zVyGC

    #5871
    usevinc
    Participant

    [/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.

    #5872
    Vladimir
    Keymaster

    There 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.

    #5873
    usevinc
    Participant

    Oh, 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! 😉 =)

    #5874
    usevinc
    Participant

    Everything 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’]);

    #5875
    Vladimir
    Keymaster

    WooCommerce 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’.

    #5876
    usevinc
    Participant

    I’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’]);

    #5877
    Vladimir
    Keymaster

    OK. 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.

    #5878
    Vladimir
    Keymaster

    If 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.

    #5879
    usevinc
    Participant

    Of course!

    #5880
    usevinc
    Participant

    I’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. =)

    #5882
    Vladimir
    Keymaster

    Try 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.

    #5884
    usevinc
    Participant

    Yes 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;
    }
Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.