WooCommerce Custom Tab Product Edit Page
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.
If you require expert assistance or want to develop custom unique functionality, hire WooCommerce Developers for your project
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 –
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 –
Reference http://hookr.io/filters/woocommerce_product_data_tabs/
For any technical assistance kindly raise a ticket or reach us by email at support@webkul.com. Thanks for Your Time! Have a Good Day!
Also, discover various solutions to add more features and enhance your online store by visiting the WooCommerce plugins.