Automattic\WooCommerce\StoreApi\Routes\V1

Checkout::validate_user_can_place_orderprivateWC 1.0

This validates if the order can be placed regarding settings in WooCommerce > Settings > Accounts & Privacy If registration during checkout is disabled, guest checkout is disabled and the user is not logged in, prevent checkout.

Method of the class: Checkout{}

Returns

null. Nothing (null).

Usage

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

Checkout::validate_user_can_place_order() code WC 9.9.3

private function validate_user_can_place_order() {
	if (
		// "woocommerce_enable_signup_and_login_from_checkout" === no.
		false === filter_var( WC()->checkout()->is_registration_enabled(), FILTER_VALIDATE_BOOLEAN ) &&
		// "woocommerce_enable_guest_checkout" === no.
		true === filter_var( WC()->checkout()->is_registration_required(), FILTER_VALIDATE_BOOLEAN ) &&
		! is_user_logged_in()
	) {
		throw new RouteException(
			'woocommerce_rest_guest_checkout_disabled',
			esc_html(
				/**
				 * Filter to customize the checkout message when a user must be logged in.
				 *
				 * @since 9.4.3
				 *
				 * @param string $message Message to display when a user must be logged in to check out.
				 */
				apply_filters(
					'woocommerce_checkout_must_be_logged_in_message',
					__( 'You must be logged in to checkout.', 'woocommerce' )
				)
			),
			403
		);
	}
}