Automattic\WooCommerce\StoreApi\Utilities
OrderController::perform_custom_order_validation
Perform custom order validation via WooCommerce hooks.
Allows plugins to perform custom validation before payment.
Method of the class: OrderController{}
Hooks from the method
Returns
null. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->perform_custom_order_validation( $order );
- $order(WC_Order) (required)
- Order object.
OrderController::perform_custom_order_validation() OrderController::perform custom order validation code WC 10.8.1
protected function perform_custom_order_validation( \WC_Order $order ) {
$validation_errors = new \WP_Error();
/**
* Allow plugins to perform custom validation before payment.
*
* Plugins can add errors to the $validation_errors object.
*
* @param \WC_Order $order The order object.
* @param \WP_Error $validation_errors WP_Error object to add custom errors to.
* @since 9.9.0
*/
do_action( 'woocommerce_checkout_validate_order_before_payment', $order, $validation_errors );
// Check if there are any errors after custom validation.
if ( $validation_errors->has_errors() ) {
throw new RouteException(
'woocommerce_rest_checkout_custom_validation_error',
esc_html( implode( ' ', $validation_errors->get_error_messages() ) ),
400
);
}
}