Re-ordering product tabs

Hey,

I tried to use this filter in functions.php to start reordering single product tabs :

/**
 * Reorder product data tabs
 */
add_filter( 'woocommerce_product_tabs', 'woo_reorder_tabs', 98 );
function woo_reorder_tabs( $tabs ) {

	$tabs['reviews']['priority'] = 5;			// Reviews first
	$tabs['description']['priority'] = 10;			// Description second
	$tabs['additional_information']['priority'] = 15;	// Additional information third

	return $tabs;
} 

But it returns some errors:

Notice : Undefined index: title in /home/xxx/public_html/xxx/wp-content/themes/pro/woocommerce/single-product/tabs/tabs.php on line 49

Notice : Undefined index: callback in /home/xxx/public_html/xxx/wp-content/themes/pro/woocommerce/single-product/tabs/tabs.php on line 55

Warning : call_user_func() expects parameter 1 to be a valid callback, no array or string given in /home/xxx/public_html/xxx/wp-content/themes/pro/woocommerce/single-product/tabs/tabs.php on line 5

What can I do for adding a filter without any conflict?

Thanks in advance.

Hi @omid020,

Thanks for writing in. Regretfully as this is related to custom development, it’s not something we can help fully implement as it would be outside the scope of support. That being said, if I saw that error I would test commenting out each line until the error went away.

I don’t know for sure but what’s probably happening is one of those keys doesn’t exist at the time you want to change it’s priority. For example:

$tabs['additional_information']['priority'] = 15;

If $tabs['additional_information'] isn’t set, it will create a new empty array on the fly. Then when the tabs go to render it will try to looper over that empty item and not find the title, callback, etc.

You could try this:

if ( isset( $tabs['additional_information'] ) ) {
  $tabs['additional_information']['priority'] = 15;
}

Once again, we can’t help you full implement this but hopefully this advice will help you figure out what’s going on and solve this issue.

@alexander It works like a charm!

Thanks for your support.

You’re very welcome, @omid020!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.