Automattic\WooCommerce\StoreApi\Utilities
OrderController::validate_selected_shipping_methods()
Check there is a shipping method if it requires shipping.
Method of the class: OrderController{}
No Hooks.
Return
null
. Nothing.
Usage
$OrderController = new OrderController(); $OrderController->validate_selected_shipping_methods( $needs_shipping, $chosen_shipping_methods );
- $needs_shipping(true|false) (required)
- Current order needs shipping.
- $chosen_shipping_methods(array)
- Array of shipping methods.
Default: array()
OrderController::validate_selected_shipping_methods() OrderController::validate selected shipping methods code WC 7.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, [] ); } } }