Automattic\WooCommerce\StoreApi\Utilities

CartController::get_cart_instance()publicWC 1.0

Get main instance of cart class.

Method of the class: CartController{}

No Hooks.

Return

\WC_Cart.

Usage

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

CartController::get_cart_instance() code WC 7.7.0

public function get_cart_instance() {
	$cart = wc()->cart;

	if ( ! $cart || ! $cart instanceof \WC_Cart ) {
		throw new RouteException( 'woocommerce_rest_cart_error', __( 'Unable to retrieve cart.', 'woocommerce' ), 500 );
	}

	return $cart;
}