skip to Main Content

I was using original snippet to reorders tabs.
then realized that if I forget to put description or attributes, these tabs are empty.
Then snippet creates php error.
here is the original code and my error comment. https://gist.github.com/woogists/abb8a37f8c708d712e46ce2d02ffdc43#file-wc-reorder-tabs-php

    add_filter( 'woocommerce_product_tabs', 'woo_reorder_tabs', 98 );
function woo_reorder_tabs( $tabs ) {
    if ($tabs[''] !== undefined)
    {
        $tabs['additional_information']['priority'] = 1;
    }
    return $tabs;
}

then I added if empty rule and changed the code like this. but this is also create another error.

add_filter( 'woocommerce_product_tabs', 'woo_reorder_tabs', 98 );
function woo_reorder_tabs( $tabs ) {
    if ($tabs[''] !== undefined)
    {
        $tabs['additional_information']['priority'] = 1;
    }
    return $tabs;
}

here is the error

PHP Warning: Use of undefined constant undefined - assumed 'undefined' (this will throw an Error in a future version of PHP) in /kunder/gaming_10908/devgam_14130/public/wp-content/plugins/code-snippets/php/snippet-ops.php(469) : eval()'d code on line 6

Do you have any suggestion?

2

Answers


  1. Chosen as BEST ANSWER

    This one also worked for me.

        /**
     * 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;    
        $tabs['reviews']['priority'] = 40;
        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; 
    }`
    

  2. PHP doesn’t have the undefined constant. It is a javascript thing.

    Your code should be as below.

    add_filter( 'woocommerce_product_tabs', 'woo_reorder_tabs', 98 );
    function woo_reorder_tabs( $tabs ) {
        if ( is_array( $tabs ) )
        {
            $tabs['additional_information']['priority'] = 1;
        }
        return $tabs;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search