Неустранимая ошибка: необработанная ошибка: вызов неопределенной функции is_product () - PullRequest
0 голосов
/ 22 декабря 2018

После импорта моего рабочего веб-сайта, связанного с WordPress, в мою локальную среду Xampp, я получаю эту ошибку:

Неустранимая ошибка: необработанная ошибка: вызов неопределенной функции is_product () в C: \ xampp \htdocs \ public_html \ silicharvest \ wp-content \ themes \ storefront-child \ functions.php: 62 Трассировка стека: # 0 C: \ xampp \ htdocs \ public_html \ silicharvest \ wp-includes \ class-wp-hook.php (286): wc_variable_simple_conditions ('') # 1 C: \ xampp \ htdocs \ public_html \ silicharvest \ wp-includes \ class-wp-hook.php (310): WP_Hook-> apply_filters (NULL, Array) # 2 C: \ xampp\ htdocs \ public_html \ silicharvest \ 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 \ silicharvest \ wp-content \ themes \ storefront \ header.php (18): wp_head () # 5 C: \ xampp \ htdocs \ public_html \ silicharvest\ 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 \ silicharvest \ wp-content \ themes \ storefront-child \ functions.php в строке 62

Я предпринял следующие диагностические шаги, но безрезультатнопо ошибке:

  1. Отключены все плагины, включая плагин, относящийся к продуктам (Woocommerce)
  2. Переименован файл storefront-child \ functions.php (для временного отключенияit)
  3. Изменен шаблон на что-то отличное от дочернего магазина

И все же ошибка сохраняется независимо от любого из вышеперечисленных шагов.Правильное решение должно устранить все эти ошибки.

Редактировать: строки 1-73 файла functions.php, на которые ссылается ошибка:

<?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>
        &copy; <?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.

Ответы [ 5 ]

0 голосов
/ 02 января 2019

Сначала проверьте, активирована ли 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);
        }
    }
}
0 голосов
/ 31 декабря 2018

Можете ли вы попробовать следующие вещи, если это работает?

  • Попробуйте обновить тему, если существует новое обновление для темы.

  • Если добиваться коммерциипапка существует в папке активной темы, затем переименуйте эту папку woocommerce и проверьте ее.

0 голосов
/ 26 декабря 2018

Попробуйте заменить вашу функцию следующим образом:

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);
        }
    }
}
0 голосов
/ 29 декабря 2018

Вы можете попробовать это:

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

Если вы получаете ошибки, возможно, пользовательский тип записи 'product' не существует.

0 голосов
/ 26 декабря 2018

Убедитесь, что вы include источник этой функции includes/wc-conditional-functions.php

http://woocommerce.wp -a2z.org / oik_api / is_product /

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...