• Resolved roadlink

    (@roadlink)


    Hello,

    I am using this snippet to reorder my tabs.
    https://gist.github.com/woogists/abb8a37f8c708d712e46ce2d02ffdc43#file-wc-reorder-tabs-php

    But it creates a php error if one of the tabs is empty.
    Like if I don’t add any attributes and decsription, these tabs are now shown in front end.
    Then this snippet creates error.

    Is there any way to fix it?

    Error code:

    2021/03/10 11:39:31 [error] 77282#77282: *18799929 FastCGI sent in stderr: "PHP message: PHP Warning: call_user_func() expects parameter 1 to be a valid callback, no array or string given in /www/xxxx/public/wp-content/themes/woodmart/woocommerce/single-product/tabs/tabs.php on line 60" while reading response header from upstream, client: 194.29.214.244, server: xxx.com, request: "GET /product/4605// HTTP/1.0", upstream: "fastcgi://unix:/var/run/php7.4-fpm-xxxx.sock:", host: "www.xxx.com", referrer: "https://www.google.com/"

Viewing 9 replies - 1 through 9 (of 9 total)
  • Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi @roadlink!

    You have to use conditional tags. Please see the following for the solution:

    https://docs.woocommerce.com/document/editing-product-data-tabs/#section-6

    Cheers!

    Thread Starter roadlink

    (@roadlink)

    Thanks for advise.
    I did use below code and opened a product without attributes. Gor error again.
    /**
    * Check if product has attributes, dimensions or weight to override the call_user_func() expects parameter 1 to be a valid callback error when changing the additional tab
    */
    add_filter( ‘woocommerce_product_tabs’, ‘woo_reorder_tabs’, 98 );

    function woo_reorder_tabs( $tabs ) {

    global $product;

    if( $product->has_attributes() || $product->has_dimensions() || $product->has_weight() ) { // Check if product has attributes, dimensions or weight
    $tabs[‘additional_information’][‘priority’] = 3;
    }

    return $tabs;

    }

    error message;

    PHP Warning: call_user_func() expects parameter 1 to be a valid callback, no array or string given in /kunder/gaming_10908/devgam_14130/public/wp-content/themes/woodmart/woocommerce/single-product/tabs/tabs.php on line 60

    Thread Starter roadlink

    (@roadlink)

    I use both rename and reorder. So I use $tabs for both. can it be a reason?

    Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi @roadlink!

    > I use both rename and reorder. So I use $tabs for both. can it be a reason?

    Possibly, yes.

    What difference does it make when only using a single instance?

    Please check and let us know. I’d be happy to dig into this further for a workaround.

    Cheers!

    Thread Starter roadlink

    (@roadlink)

    Handled after add this condition to both rename and reorder functions.

    I also have another issue when reorder description tab.
    It gives same error when it is empty.

    What could be conditional code “if there is a description”?

    Thread Starter roadlink

    (@roadlink)

    Actually It was not.
    I have 2 snippets now and working without error.

    But still couldn’t solve rename description tab.
    Still getting error when it is empty.
    What could be conditional code “if there is a description”?

    Hello @roadlink ,

    You can use the PHP isset() function to determine if the description field is available or not. So, my approach is like this –

    add_filter( 'woocommerce_product_tabs', 'woo_reorder_tabs', 98 );
    function woo_reorder_tabs( $tabs ) {
    
    	$tabs['reviews']['priority'] = 5;			// Reviews first
    		
            //checking if description is available
    	if(isset($tabs['description'])) {
    		$tabs['description']['priority'] = 10; // Description second
    	}
    
    	$tabs['additional_information']['priority'] = 15;
    				
    	return $tabs;
    }

    This does the trick for me and does not produce an error when the description field is not empty.

    Cheers ??

    Thread Starter roadlink

    (@roadlink)

    Thank you.

    Hello @roadlink ,

    I assume this has solved the issue for you. I am going to close this thread, for now, feel free to open a new thread if you have any other queries.

    Thank you ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘reorder tabs snippet creates php error’ is closed to new replies.