Automattic\WooCommerce\StoreApi\Utilities

CartController::validate_cart_not_emptypublicWC 1.0

When placing an order, validate that the cart is not empty.

Method of the class: CartController{}

No Hooks.

Returns

null. Nothing (null).

Usage

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

CartController::validate_cart_not_empty() code WC 9.9.4

public function validate_cart_not_empty() {
	$cart_items = $this->get_cart_items();

	if ( empty( $cart_items ) ) {
		throw new InvalidCartException(
			'woocommerce_cart_error',
			// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Errors are converted to response objects later.
			new WP_Error( 'woocommerce_rest_cart_empty', __( 'Cannot place an order, your cart is empty.', 'woocommerce' ), 400 ),
			400
		);
	}
}