Я столкнулся с этой проблемой.
Неустранимая ошибка: необученная ошибка: вызов функции-члена is_type () для null
Поможет ли кто-нибудь мне в этом вопросе.
Вот код, который я использую.
add_action( 'woocommerce_before_calculate_totals', 'sione_change_cart_item_name_and_price', 10, 1 );
function sione_change_cart_item_name_and_price( $cart ) {
global $product;
// Get new items names from WC_Session
$session_data = (array) WC()->session->get( 'new_item_names' );
//$sku_data = (array) WC()->session->get( 'product_sku' );
// Loop through cart items
foreach ( $cart->get_cart() as $cart_item_key => $cart_item ) {
if($product->is_type( 'simple' )) {
$item_names = $product->get_short_description();
} else {
$item_names = $cart_item['data']->get_name() .", ". $cart_item['data']->get_attribute('color'). "," . $cart_item['data']->get_attribute('gender') . " (Product SKU: " . $cart_item['data']->get_sku() . ")";
}
// If item name doesn't exist in WC_Session for this cart item, we do it
if( ! isset($session_data[$cart_item_key]) ) {
$session_data[$cart_item_key] = $item_names;
WC()->session->set( 'new_item_names', $session_data );
}
}
}
Любая помощь будет оценена. Спасибо