首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >woocommerce重新排序标签创建php错误

woocommerce重新排序标签创建php错误
EN

Stack Overflow用户
提问于 2021-03-25 18:47:17
回答 2查看 69关注 0票数 0

我使用原始代码段对选项卡进行重新排序。然后我意识到,如果我忘记输入描述或属性,这些选项卡就是空的。然后snippet创建php错误。这是原始代码和我的错误注释。https://gist.github.com/woogists/abb8a37f8c708d712e46ce2d02ffdc43#file-wc-reorder-tabs-php

代码语言:javascript
复制
    add_filter( 'woocommerce_product_tabs', 'woo_reorder_tabs', 98 );
function woo_reorder_tabs( $tabs ) {
    if ($tabs[''] !== undefined)
    {
        $tabs['additional_information']['priority'] = 1;
    }
    return $tabs;
}

然后我添加了if空规则,并像这样修改了代码。但这也造成了另一个错误。

代码语言:javascript
复制
add_filter( 'woocommerce_product_tabs', 'woo_reorder_tabs', 98 );
function woo_reorder_tabs( $tabs ) {
    if ($tabs[''] !== undefined)
    {
        $tabs['additional_information']['priority'] = 1;
    }
    return $tabs;
}

下面是错误

代码语言:javascript
复制
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

你有什么建议吗?

EN

回答 2

Stack Overflow用户

发布于 2021-03-25 18:57:30

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

您的代码应该如下所示。

代码语言: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;
}
票数 1
EN

Stack Overflow用户

发布于 2021-03-31 22:07:13

这个也适用于我。

代码语言:javascript
复制
    /**
 * 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; 
}`
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66797877

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档