WordPress at Your Fingertips
function is not described

Automattic\WooCommerce\Blocks\StoreApi\Routes

Checkout::create_or_update_draft_order() private WC 1.0

Create or update a draft order based on the cart.

{} It's a method of the class: Checkout{}

Return

null. Nothing.

Usage

// private - for code of main (parent) class only
$result = $this->create_or_update_draft_order();

Code of Checkout::create_or_update_draft_order() WC 5.6.0

private function create_or_update_draft_order() {
	$this->order = $this->get_draft_order_id() ? wc_get_order( $this->get_draft_order_id() ) : null;

	if ( ! $this->is_valid_draft_order( $this->order ) ) {
		$this->order = $this->order_controller->create_order_from_cart();
	} else {
		$this->order_controller->update_order_from_cart( $this->order );
	}

	/**
	 * WooCommerce Blocks Checkout Update Order Meta (experimental).
	 *
	 * This hook gives extensions the chance to add or update meta data on the $order.
	 *
	 * This is similar to existing core hook woocommerce_checkout_update_order_meta.
	 * We're using a new action:
	 * - To keep the interface focused (only pass $order, not passing request data).
	 * - This also explicitly indicates these orders are from checkout block/StoreAPI.
	 *
	 * @see https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/3686
	 * @internal This Hook is experimental and may change or be removed.
	 *
	 * @param WC_Order $order Order object.
	 */
	do_action( '__experimental_woocommerce_blocks_checkout_update_order_meta', $this->order );

	// Confirm order is valid before proceeding further.
	if ( ! $this->order instanceof WC_Order ) {
		throw new RouteException(
			'woocommerce_rest_checkout_missing_order',
			__( 'Unable to create order', 'woocommerce' ),
			500
		);
	}

	// Store order ID to session.
	$this->set_draft_order_id( $this->order->get_id() );

	// Try to reserve stock for 10 mins, if available.
	try {
		$reserve_stock = new ReserveStock();
		$reserve_stock->reserve_stock_for_order( $this->order, 10 );
	} catch ( ReserveStockException $e ) {
		$error_data = $e->getErrorData();
		throw new RouteException(
			$e->getErrorCode(),
			$e->getMessage(),
			$e->getCode()
		);
	}
}