php - 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?
解决方案
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;
}
推荐阅读
- regex - VBA RegEx:如何在特定字符串之后找到数字的第一个实例并忽略所有其他字符?
- git - 使用 Ansible 向 Azure Repo 添加、提交、推送
- javascript - 在另一个文件检查时返回
- visual-studio - 查找预编译头时出现错误 C1010 文件意外结束
- c# - 带有对象列表的 LINQ Where 查询
- xcode - 解决拉取请求中的合并冲突是 Azure Dev ops 中的 xcode
- kubernetes - 错误:升级失败:升级前挂钩失败:等待条件超时
- redirect - 如何将 squarespace 页面 url 重定向到非 squarespace 子域
- cmake - 使用 ExternalProject 时暂停主 CMake
- python - python:创建unicode字符串的chararray