致命错误:未捕获错误:调用未定义函数 is_product()
Posted
技术标签:
【中文标题】致命错误:未捕获错误:调用未定义函数 is_product()【英文标题】:Fatal error: Uncaught Error: Call to undefined function is_product() 【发布时间】:2019-05-22 12:27:00 【问题描述】:将我的生产 WordPress 相关网站导入本地 Xampp 环境后,我收到此错误:
在 C:\xampp\htdocs\public_html\siliconharvest\wp-content\themes\storefront-child\functions.php:62 堆栈跟踪:#0 C:\xampp\htdocs\public_html\siliconharvest\wp-includes\class-wp-hook.php(286): wc_variable_simple_conditions('') #1 C:\xampp\htdocs\public_html\siliconharvest\wp-includes\class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array) #2 C:\xampp\htdocs\public_html\siliconharvest\wp-includes\plugin.php(453): WP_Hook->do_action(Array) #3 C:\xampp\htdocs\public_html\siliconharvest\wp-includes\general-template.php(2614): do_action('wp_head') #4 C:\xampp\htdocs\public_html\siliconharvest\wp-content\themes\storefront\header.php(18): wp_head() #5 C:\xampp\htdocs\public_html\siliconharvest\wp-includes\template.php(688): require_once('C:\xampp\htdocs...') #6 C:\xampp\htdocs\public_html\siliconharvest\wp-includes\template.php(647): load_template('C:\xampp\htdocs...', true) #7 C:\xampp\htdocs\public_html\siliconharvest\wp-includes\general-template.php( 在 C:\xampp\htdocs\public_html\siliconharvest\wp-content\themes\storefront-child\functions.php 在第 62 行
我尝试了以下诊断步骤,但对错误没有影响:
-
禁用所有插件,包括与产品相关的插件 (Woocommerce)
重命名 storefront-child\functions.php 文件(暂时禁用它)
将模板更改为除店面子项之外的其他内容
但无论上述任何步骤如何,错误仍然存在。正确的解决方案必须消除所有这些错误。
编辑:错误中引用的functions.php文件的第1-73行:
<?php
// BEGIN Remove "Storefront Designed by WooThemes" from Footer as per https://danielsantoro.com/remove-storefront-designed-woothemes/
add_action('init', 'custom_remove_footer_credit', 10);
function custom_remove_footer_credit()
remove_action('storefront_footer', 'storefront_credit', 20);
add_action('storefront_footer', 'custom_storefront_credit', 20);
function custom_storefront_credit()
?>
<div class="site-info">
<div class="deferred-menu-items">
<ul style="list-style-type: none;" class="footer-menu">
<li style="display:inline-block" class="menu-item-156"><a href="/about/">About Us</a></li><!--
--><li style="display:inline-block" class="menu-item-189"><a href="/faq/">FAQ</a></li><!--
--><li style="display:inline-block" class="fa-delivery"><a href="/delivery/">Delivery</a></li><!--
--><li style="display:inline-block" class="fa-returns"><a href="/returns/">Returns</a></li><!--
--><li style="display:inline-block" class="menu-item-464"><a href="/store-policies/"><i class="far fa-handshake"></i> Store Policies</a></li><!--
--><!--<li style="display:inline-block" class="menu-item-1024"><a href="/articles/">Articles</a></li>--><!--
--><li style="display:inline-block" class="affiliates"><a href="/about-the-silicon-harvest-affiliates-program/"><i class="fas fa-bullhorn"></i> Affiliates Programme</a></li>
<!--<li style="display:inline-block" class="fa-opas"><a href="/overseas-parts-acquisition-service-opas/">Overseas Parts Acquisition Service (OPAS)</a></li>-->
</ul>
</div>
© <?php
echo get_bloginfo('name') . ' ' . get_the_date('Y') . ' | ABN: 31 022 705 565 | <a style="color:blue" href="/terms-of-service-and-privacy-policy/">Terms of Service/Privacy Policy</a> <div class="front-page-contact">
<a style="color:blue" href="/contact-us/#aggs-contact-form">Contact Form</a> | mob: 0424 214 930 | tel: (02) 8007 6871 <!--| mob: +61 424 214 930 (international) / tel: +612 8007 6871 -->| <a style="color:blue" href="mailto:mail@siliconharvest.com.au">mail@siliconharvest.com.au</a><br />Live contact hours from 9am-9pm (AEST/AEDT or Sydney/Melbourne/ACT/TAS time), Mon-Sun</div>';
?>
</div><!-- .site-info -->
<?php
// END Remove "Storefront Designed by WooThemes" from Footer
/* START add microdata relating to item condition to satisfy Google Merchant's optional advice - as per https://github.com/woocommerce/woocommerce/issues/15797#issuecomment-355744594 */
add_filter('woocommerce_structured_data_product_offer', 'filter_woocommerce_structured_data_product', 10, 2);
/**
* Add properties to the http://schema.org/Offer markup for all products.
*/
function filter_woocommerce_structured_data_product($markup, $product)
/* By default, we assume all products sold in the ecommerce are in new condition */
if (empty($markup['itemCondition']))
$markup['itemCondition'] = 'http://schema.org/NewCondition';
return $markup;
/* END add microdata */
// as per https://wordpress.stackexchange.com/questions/276941/woocommerce-add-extra-field-to-variation-product/277556
// based on http://www.remicorson.com/woocommerce-custom-fields-for-variations/
//THESE ACTIONS AND FILTER HANDLE YOUR PRODUCT VARIATION FIELDS + add_filter( 'woocommerce_available_variation', 'load_variation_settings_fields' ); which you have inserted into a conditional
add_action('woocommerce_product_after_variable_attributes', 'variation_settings_fields', 10, 3);
add_action('woocommerce_save_product_variation', 'save_variation_settings_fields', 10, 2);
add_action('wp_head', 'wc_variable_simple_conditions');
function wc_variable_simple_conditions()
if (is_product())
global $post;
$post_id = $post->ID;
$product = wc_get_product($post_id);
$type = $product->get_type();
if ($type == 'variable')
add_filter('woocommerce_available_variation', 'load_variation_settings_fields');
elseif ($type == 'simple')
add_action('woocommerce_single_product_summary', 'custom_data_above_add_to_cart_button', 41);
if (is_product())
行是第 62 行。
【问题讨论】:
据说错误来自文件“functions.php:line 62”,所以你也应该分享该文件中的代码 @MdKowsarHossain 我现在已包含在 OP 中 【参考方案1】:首先检查woocommerce是否激活然后调用函数:
add_action('wp_head', 'wc_variable_simple_conditions');
function wc_variable_simple_conditions()
if (!class_exists('WooCommerce')) return; // add this line
if (is_product())
global $post;
$post_id = $post->ID;
$product = wc_get_product($post_id);
$type = $product->get_type();
if ($type == 'variable')
add_filter('woocommerce_available_variation', 'load_variation_settings_fields');
elseif ($type == 'simple')
add_action('woocommerce_single_product_summary', 'custom_data_above_add_to_cart_button', 41);
【讨论】:
【参考方案2】:确保你include
这个函数的来源includes/wc-conditional-functions.php
http://woocommerce.wp-a2z.org/oik_api/is_product/
【讨论】:
我可以确认文件wc-conditional-functions.php
可以在C:\xampp\htdocs\public_html\siliconharvest\wp-content\plugins\woocommerce\includes
中找到。请指教。
您的 Woocommerce 插件是否处于活动状态?使用 SELECT * FROM wp_options WHERE option_name = 'active_plugins' 签入数据库;
我在 active_plugins 记录 i:54;s:27:"woocommerce/woocommerce.php";
的值中找到了这个词。这会告诉您 Woocommerce 是否处于活动状态?
我使用 Storefront,带有用于自定义的子主题。问题是,我的托管服务器上的现场制作网站运行良好。似乎将网站的相同副本迁移到本地桌面环境破坏了 Woocommerce...
可能是它遗漏了一些文件。尝试再次复制您的主题文件【参考方案3】:
尝试用这个替换你的函数:
function wc_variable_simple_conditions()
if ( !function_exists( 'is_product' ) )
return;
if (is_product())
global $post;
$post_id = $post->ID;
$product = wc_get_product($post_id);
$type = $product->get_type();
if ($type == 'variable')
add_filter('woocommerce_available_variation', 'load_variation_settings_fields');
elseif ($type == 'simple')
add_action('woocommerce_single_product_summary', 'custom_data_above_add_to_cart_button', 41);
【讨论】:
很遗憾,错误仍然存在...请重试:)【参考方案4】:你可以试试这个:
add_action('wp_head', 'wc_variable_simple_conditions');
function wc_variable_simple_conditions()
if (is_singular( array( 'product' ) ))
global $post;
$post_id = $post->ID;
$product = wc_get_product($post_id);
$type = $product->get_type();
if ($type == 'variable')
add_filter('woocommerce_available_variation', 'load_variation_settings_fields');
elseif ($type == 'simple')
add_action('woocommerce_single_product_summary', 'custom_data_above_add_to_cart_button', 41);
如果您收到错误,则自定义帖子类型“产品”可能不存在。
【讨论】:
您的代码返回:Warning: require(../../..//wp-load.php): failed to open stream: No such file or directory in C:\xampp\htdocs\public_html\siliconharvest\wp-content\themes\storefront-child\functions.php on line 3
Fatal error: require(): Failed opening required '../../..//wp-load.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\public_html\siliconharvest\wp-content\themes\storefront-child\functions.php on line 3
这是什么意思?解决方法是什么?
你在functions.php的第3行调用了什么函数()?你可以粘贴它吗?
你可以使用is_product()
而不是is_singular( array( 'product' ) )
来提高效率。【参考方案5】:
如果可行,您可以尝试以下操作吗?
如果主题存在新的更新,请尝试更新主题。
如果 woo commerce 文件夹存在于活动主题文件夹中,则重命名 那个woocommerce文件夹并检查它。
【讨论】:
以上是关于致命错误:未捕获错误:调用未定义函数 is_product()的主要内容,如果未能解决你的问题,请参考以下文章
PHPmyadmin 问题 - 致命错误:未捕获错误:调用未定义函数 mb_detect_encoding()
致命错误:未捕获的错误:调用 /homepages/ 中未定义的函数 mysql_pconnect() [重复]
致命错误:未捕获的错误:调用未定义的函数 mssql_query() [重复]
PHP 致命错误:未捕获的错误:使用 Laravel 5.8 和 PHP 7.4 调用未定义函数 Whoops\Exception\xdebug_is_enabled()