Automattic\WooCommerce\StoreApi\Utilities

OrderController::validate_selected_shipping_methods()publicWC 1.0

Check there is a shipping method if it requires shipping.

Метод класса: OrderController{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$OrderController = new OrderController();
$OrderController->validate_selected_shipping_methods( $needs_shipping, $chosen_shipping_methods );
$needs_shipping(true|false) (обязательный)
Current order needs shipping.
$chosen_shipping_methods(массив)
Array of shipping methods.
По умолчанию: array()

Код OrderController::validate_selected_shipping_methods() WC 8.7.0

public function validate_selected_shipping_methods( $needs_shipping, $chosen_shipping_methods = array() ) {
	if ( ! $needs_shipping || ! is_array( $chosen_shipping_methods ) ) {
		return;
	}

	foreach ( $chosen_shipping_methods as $chosen_shipping_method ) {
		if ( false === $chosen_shipping_method ) {
			throw new RouteException(
				'woocommerce_rest_invalid_shipping_option',
				__( 'Sorry, this order requires a shipping option.', 'woocommerce' ),
				400,
				array()
			);
		}
	}
}