Reading list Switch to dark mode

    WooCommerce Custom Tab Product Edit Page

    Updated 15 March 2024

    WooCommerce Custom Tab Product Edit Page – In this post we see how we can add custom tab to WooCommerce product edit option tab on product edit page at admin-end. This can be very useful when we want additional data with the product. Simply, we can add custom tab according to need and perform the intended task.

    WooCommerce provides various hooks for various tasks/actions to hook our own content with existing content as WordPress do. So, for this also we gonna use hook ‘woocommerce_product_data_tabs’ and add filter to this hook.

    Let’s start with some code –

    <?php
    
    add_filter( 'woocommerce_product_data_tabs', 'wk_custom_product_tab', 10, 1 );
    
    ?>

    In above line of code, we add filter to ‘woocommerce_product_data_tabs’ hook. Second parameter is the callback function for this filter, third is the priority, fourth-one is the number of accepted arguments in callback.

    Now,  add custom tab information in the callback of above filter –

    Searching for an experienced
    Woocommerce Company ?
    Find out More
    function wk_custom_product_tab( $default_tabs ) {
        $default_tabs['custom_tab'] = array(
            'label'   =>  __( 'Custom Tab', 'domain' ),
            'target'  =>  'wk_custom_tab_data',
            'priority' => 60,
            'class'   => array()
        );
        return $default_tabs;
    }

    In above function, we add custom tab information to default tabs array with ‘custom_tab’ id. The arguments in the above array are required as label defines the name of tab, target defines using which content will add to this tab, priority defines the position of this tab in the list of default tabs, class contains the html class if want to add any.

    Using above code, custom tab will add to product edit page. Now, to add content to this tab we’ll use one other hook ‘woocommerce_product_data_panels’ and add action to this hook –

    <?php
    
    add_action( 'woocommerce_product_data_panels', 'wk_custom_tab_data' );
    
    function wk_custom_tab_data() {
       echo '<div id="wk_custom_tab_data" class="panel woocommerce_options_panel">// add content here</div>';
    }

    In above code, id of div will be same as of target defined while creating tab.

    The custom tab on product edit page will look as shown in below screenshot –

    WooCommerce Custom Tab Product Edit Page

    Reference http://hookr.io/filters/woocommerce_product_data_tabs/

    Support

    For any technical assistance, please raise a ticket or reach us by mail at [email protected]Thanks for Your Time! Have a Good Day!

    Also, Hire WooCommerce Developers for all kinds of services for web and mobile development, plugin development, mobile app, design services, and much more. If you need custom WordPress Development services then feel free to reach us and also explore our exclusive range of WordPress WooCommerce Extensions.

    Thanks for Your Time! Have a Good Day!

    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    5 comments

  • sachin sharma
  • Alex
  • Jakub Šafránek
    • Webkul Support
      • razni
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home