WC_Cart::get_cart_contents_weight()publicWC 2.5.0

Get weight of items in the cart.

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

Хуки из метода

Возвращает

float.

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

$WC_Cart = new WC_Cart();
$WC_Cart->get_cart_contents_weight();

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

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

Код WC_Cart::get_cart_contents_weight() WC 8.7.0

public function get_cart_contents_weight() {
	$weight = 0.0;

	foreach ( $this->get_cart() as $values ) {
		if ( $values['data']->has_weight() ) {
			$weight += (float) $values['data']->get_weight() * $values['quantity'];
		}
	}

	return apply_filters( 'woocommerce_cart_contents_weight', $weight );
}