【问题标题】:woocommerce reorder tabs create php errorswoocommerce 重新排序选项卡创建 php 错误
【发布时间】:2021-03-25 10:47:16
【问题描述】:

我使用原始的 sn-p 重新排序选项卡。 然后意识到如果我忘记放置描述或属性,这些选项卡是空的。 然后 sn -p 创建 php 错误。 这是原始代码和我的错误注释。 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;
}

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

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

这是错误

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

你有什么建议吗?

【问题讨论】:

    标签: php wordpress woocommerce tabs


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      这个也对我有用。

          /**
       * 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; 
      }`
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-06-07
        • 2010-11-08
        • 2012-11-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-10-07
        相关资源
        最近更新 更多