In this article, I will show you how to customize WooCommerce tabs. I will start by adding the tab because it contains almost everything we need to know.
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
$tabs['description_tab'] = array(
'title' => __( 'Description Tab', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_description_tab_content'
);
return $tabs;
}
function woo_description_tab_content() {
$id = get_the_ID();
echo 'My content go here. Post ID = '.$id;
}
To add tab you have to add a function in the filter woocommerce_product_tabs. In my case, this is the function called woo_new_product_tab. Here you can edit the variable tabs and add an array with three parameters = title, priority and a callback as shown in the code above. The callback function makes the echo of the information that we need. In the function woo_description_tab_content (the callback function) we can take the ID of the post/product and display exact information about it.
//Remove tab
function woo_new_product_tab( $tabs ) {
unset($tabs['description_tab']);
return $tabs;
}
//Rename
function woo_new_product_tab( $tabs ) {
$tabs['description_tab']['title'] = 'My New Title';
return $tabs;
}
//Change priority
function woo_new_product_tab( $tabs ) {
$tabs['description_tab']['priority'] = 20,
return $tabs;
}
//Customize content
function woo_new_product_tab( $tabs ) {
$tabs['description_tab']['callback'] = 'my_new_woo_description_tab_content';
return $tabs;
}
With the same filter (woocommerce_product_tabs ) you can remove, change order, customize or rename tabs. It can be done easily (example above) by modifying the parameters in the array. To remove this tab we just need to unset the array which describes it.
Leave A Comment