首页 > 解决方案 > woocommerce reorder tabs create php errors

问题描述

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?

标签: phpwordpresswoocommercetabs

解决方案


PHP没有undefined常数。这是一个javascript的东西。

您的代码应如下所示。

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;
}

推荐阅读