首页 > 解决方案 > WooCommerce 在 bool 上调用成员函数 get_type()

问题描述

在我的网站上更新插件后,我遇到了一个致命错误Call to a member function get_type() on bool

/* WooCommerece settings */
if ( defined( 'WOOCOMMERCE_VERSION' ) && isset( $query_post_type ) && $query_post_type == 'product' ) {
    if ( function_exists( 'wc_get_product' ) ) {
        // WC 3.0+
        $woo_product = wc_get_product( $post->ID );
        $woo_is_variation = $woo_product->get_type() == 'variable' ? true : false;
    } else {
        // Old WC
        $woo_product = get_product( $post->ID );
        $woo_is_variation = isset( $woo_product->product_type ) && ( $woo_product->product_type == 'variation' || $woo_product->product_type == 'variable' ) ? true : false;
        if ( $woo_is_variation ) {$post = $woo_product->post;}
    }
}

我尝试将代码修改为

if( $product->is_type('variable') ) :
    $woo_is_variation = true;
else :
    $woo_is_variation = false;
endif;

我已经联系了插件作者,但到目前为止我没有任何回应。

我的产品页面已关闭,希望能提供一些帮助。

标签: woocommerce

解决方案


推荐阅读