Automattic\WooCommerce\StoreApi\Utilities

CartController::normalize_cartpublicWC 1.0

Normalizes the cart by fixing any quantity violations.

Method of the class: CartController{}

No Hooks.

Returns

null. Nothing (null).

Usage

$CartController = new CartController();
$CartController->normalize_cart();

CartController::normalize_cart() code WC 9.9.4

public function normalize_cart() {
	$quantity_limits = new QuantityLimits();
	$cart_items      = $this->get_cart_items();

	foreach ( $cart_items as $cart_item ) {
		$normalized_qty = $quantity_limits->normalize_cart_item_quantity( $cart_item['quantity'], $cart_item );

		if ( $normalized_qty !== $cart_item['quantity'] ) {
			$this->set_cart_item_quantity( $cart_item['key'], $normalized_qty );
		}
	}
}