WC_Cart::get_item_product_name │ public │ WC 11.2.0

Gets the display name for a cart item.

For variations, selected "Any" attribute values that are missing from the stored variation name are appended so the name matches fully defined variations. The stored product and variation names are not modified.

Метод класса: WC_Cart{}

Хуков нет.

Возвращает

string. The product name including any selected "Any" attribute values, or an empty string when no product can be resolved from the arguments.

Использование

$WC_Cart = new WC_Cart();
$WC_Cart->get_item_product_name( $cart_item, $product );
$cart_item(массив) (обязательный)
Cart item.
$product(WC_Product|null)
Optional product object to use as the name source, e.g. the result of the woocommerce_cart_item_product
По умолчанию: cart item's product

Список изменений

С версии 11.2.0 Введена.

Код WC_Cart::get_item_product_name() WC 11.3.0

public function get_item_product_name( $cart_item, $product = null ) {
	if ( ! $product instanceof WC_Product ) {
		$product = is_array( $cart_item ) && isset( $cart_item['data'] ) && $cart_item['data'] instanceof WC_Product ? $cart_item['data'] : null;
	}

	if ( ! $product instanceof WC_Product ) {
		return '';
	}

	$variation = isset( $cart_item['variation'] ) && is_array( $cart_item['variation'] ) ? $cart_item['variation'] : array();

	return wc_get_container()->get( SelectedVariationName::class )->get_product_name( $product, $variation, true );
}