Automattic\WooCommerce\StoreApi\Utilities

AgenticCheckoutUtils::calculate_statuspublic staticWC 1.0

Calculate the status of the checkout session.

Method of the class: AgenticCheckoutUtils{}

No Hooks.

Returns

String. Status value.

Usage

$result = AgenticCheckoutUtils::calculate_status( $checkout_session ): string;
$checkout_session(AgenticCheckoutSession) (required)
Checkout session object.

AgenticCheckoutUtils::calculate_status() code WC 10.4.3

public static function calculate_status( AgenticCheckoutSession $checkout_session ): string {
	$wc_session = WC()->session;
	if ( null === $wc_session ) {
		return CheckoutSessionStatus::CANCELED;
	}

	if ( $wc_session->get( SessionKey::AGENTIC_CHECKOUT_COMPLETED_ORDER_ID ) ) {
		return CheckoutSessionStatus::COMPLETED;
	}

	if ( $wc_session->get( SessionKey::AGENTIC_CHECKOUT_PAYMENT_IN_PROGRESS ) ) {
		return CheckoutSessionStatus::IN_PROGRESS;
	}

	// Check for validation errors.
	if (
		$checkout_session->get_messages()->has_errors()
		// Once we switch to using the CartController everywhere, there should be no notices and need for this.
		|| ! empty( wc_get_notices( 'error' ) )
	) {
		return CheckoutSessionStatus::NOT_READY_FOR_PAYMENT;
	}

	return CheckoutSessionStatus::READY_FOR_PAYMENT;
}