我使用原始代码段对选项卡进行重新排序。然后我意识到,如果我忘记输入描述或属性,这些选项卡就是空的。然后snippet创建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空规则,并像这样修改了代码。但这也造成了另一个错误。
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你有什么建议吗?
发布于 2021-03-25 18:57:30
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;
}发布于 2021-03-31 22:07:13
这个也适用于我。
/**
* 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;
}`https://stackoverflow.com/questions/66797877
复制相似问题