使用 WooCommerce 时出错 - 在 $product 上使用 is_type 函数
Error using WooCommerce - using is_type function on $product
我在使用 WordPress、WooCommerce、Divi 以及特别是名为 Divi Body Commerce 的插件时遇到了一些问题
当我创建可变产品并转到我的购物车时,出现 php 错误。
这不是我的代码,但我需要修复它。
这是代码的开头:
<?php
if( ! defined( 'ABSPATH' ) ) exit;
$mydata = get_option( 'divi-bodyshop-woo_options' );
$mydata = unserialize($mydata);
if(isset($mydata['variation_striketrhough'][0])) {
$variation_striketrhough = $mydata['variation_striketrhough'][0];
}
else{
$variation_striketrhough = "0";
}
if ($variation_striketrhough == 1) {
if ( ! is_admin() ) {
function wcbv_variation_is_active( $active, $variation ) {
if( ! $variation->is_in_stock() ) {
return false;
}
return $active;
}
add_filter( 'woocommerce_variation_is_active', 'wcbv_variation_is_active', 10, 2 );
add_filter( 'woocommerce_variation_option_name', 'customizing_variations_terms_name', 10, 1 );
function customizing_variations_terms_name( $term_name ){
global $product;
if( $product->is_type( 'variable' ) || $product->is_type( 'subscription-variation' ) ) {
/*...........*/
}
}
}
}
?>
当我在变量产品上调用 is_type 函数时发生错误。
PHP Fatal error: Uncaught Error: Call to a member function is_type() on null
我不习惯使用 WordPress 和 WooCommerce,所以如果有人能为我解答那就太好了。
您可以添加额外的检查,通常这会阻止错误消息
global $product;
if ( is_a( $product, 'WC_Product' ) ) {
if ( $product->is_type( 'variable' ) ) {
// Continue..
}
}
我在使用 WordPress、WooCommerce、Divi 以及特别是名为 Divi Body Commerce 的插件时遇到了一些问题
当我创建可变产品并转到我的购物车时,出现 php 错误。 这不是我的代码,但我需要修复它。
这是代码的开头:
<?php
if( ! defined( 'ABSPATH' ) ) exit;
$mydata = get_option( 'divi-bodyshop-woo_options' );
$mydata = unserialize($mydata);
if(isset($mydata['variation_striketrhough'][0])) {
$variation_striketrhough = $mydata['variation_striketrhough'][0];
}
else{
$variation_striketrhough = "0";
}
if ($variation_striketrhough == 1) {
if ( ! is_admin() ) {
function wcbv_variation_is_active( $active, $variation ) {
if( ! $variation->is_in_stock() ) {
return false;
}
return $active;
}
add_filter( 'woocommerce_variation_is_active', 'wcbv_variation_is_active', 10, 2 );
add_filter( 'woocommerce_variation_option_name', 'customizing_variations_terms_name', 10, 1 );
function customizing_variations_terms_name( $term_name ){
global $product;
if( $product->is_type( 'variable' ) || $product->is_type( 'subscription-variation' ) ) {
/*...........*/
}
}
}
}
?>
当我在变量产品上调用 is_type 函数时发生错误。
PHP Fatal error: Uncaught Error: Call to a member function is_type() on null
我不习惯使用 WordPress 和 WooCommerce,所以如果有人能为我解答那就太好了。
您可以添加额外的检查,通常这会阻止错误消息
global $product;
if ( is_a( $product, 'WC_Product' ) ) {
if ( $product->is_type( 'variable' ) ) {
// Continue..
}
}