Remove tab if no content

I’m using the following code to rename my product tabs including the “Additional Information” tab which contains variable attributes.

[php]//Rename Product Tabs

function rename_products_tab($tabs) {
//Renames The default ‘Description’ tab
$tabs[‘description’][‘title’] = ‘Features’;
// Rename the additional information tab
$tabs[‘additional_information’][‘title’] = __( ‘Details’ );

return $tabs;
}
add_filter( ‘woocommerce_product_tabs’, ‘rename_products_tab’);[/php]

But if a product doesn’t have any additional information or variable attributes then I get the following error message.

call_user_func() expects parameter 1 to be a valid callback, no array or string given in .../wp-content/plugins/woocommerce/templates/single-product/tabs/tabs.php on line 35

Everything works fine if I don’t rename the “additional information” tab and remove this:

[php]// Rename the additional information tab
$tabs[‘additional_information’][‘title’] = __( ‘Details’);[/php]

But I’m trying to find a way to keep the renaming code and fix the problem. Is there an if statement that could remove the tab if no content exists?

I don’t know WP much, but it sounds like you need to check to see if the key exists?

if(isset($tabs[‘additional_information’][‘title’]) ) {

}

Sponsor our Newsletter | Privacy Policy | Terms of Service