'Reorder, rename and hide empty product tabs - woocommerce
I would like to reorder, rename all tabs, and add the "hide if empty function" for the additional_information_tab by adding the functions in the Child theme (functions.php folder). The code below has been found. "reorder" + "rename" works properly. Only the "hide function" doesn't work properly -> syntax error, unexpected token ">". Could someone help me with: if empty hide the additional_information tab? Your help is very much appreciated!
/*** Reorder product data tabs*/
add_filter( 'woocommerce_product_tabs', 'woo_reorder_tabs', 98 );
function woo_reorder_tabs( $tabs ) {
$tabs['additional_information']['priority'] = 5; // Additional information first
$tabs['description']['priority'] = 10; // Description second
return $tabs;
}
/*** Rename product data tabs*/
add_filter( 'woocommerce_product_tabs', 'woo_rename_tabs', 98 );
function woo_rename_tabs( $tabs ) {
$tabs['additional_information']['title'] = __( 'Product Data' ); // Rename the additional information tab
$tabs['description']['title'] = __( 'Download datasheet' ); // Rename the description tab
return $tabs;
}
//if additional_information empty -> hide it
add_action('woocommerce_single_product_summary', 'woocommerce_product_additional_information_tab', 25);
function woocommerce_product_additional_information_tab() {
global $product;
if ($product - > has_attributes() || $product - > has_dimensions() || $product - > has_weight()) { // Check if product has attributes, dimensions or weight
return $tabs;
wc_get_template('single-product/tabs/additional-information.php');
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
