WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

Automattic\WooCommerce\Blocks\StoreApi\Utilities

OrderController::validate_coupons() protected WC 1.0

Validate coupons applied to the order and remove those that are not valid.

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

Хуков нет.

Возвращает

null. Ничего.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->validate_coupons( $order );
$order(WC_Order) (обязательный)
Order object.

Код OrderController::validate_coupons() WC 5.7.1

protected function validate_coupons( \WC_Order $order ) {
	$coupon_codes  = $order->get_coupon_codes();
	$coupons       = array_filter( array_map( [ $this, 'get_coupon' ], $coupon_codes ) );
	$validators    = [ 'validate_coupon_email_restriction', 'validate_coupon_usage_limit' ];
	$coupon_errors = [];

	foreach ( $coupons as $coupon ) {
		try {
			array_walk(
				$validators,
				function( $validator, $index, $params ) {
					call_user_func_array( [ $this, $validator ], $params );
				},
				[ $coupon, $order ]
			);
		} catch ( Exception $error ) {
			$coupon_errors[ $coupon->get_code() ] = $error->getMessage();
		}
	}

	if ( $coupon_errors ) {
		// Remove all coupons that were not valid.
		foreach ( $coupon_errors as $coupon_code => $message ) {
			wc()->cart->remove_coupon( $coupon_code );
		}

		// Recalculate totals.
		wc()->cart->calculate_totals();

		// Re-sync order with cart.
		$this->update_order_from_cart( $order );

		// Return exception so customer can review before payment.
		throw new RouteException(
			'woocommerce_rest_cart_coupon_errors',
			sprintf(
				/* translators: %s Coupon codes. */
				__( 'Invalid coupons were removed from the cart: "%s"', 'woocommerce' ),
				implode( '", "', array_keys( $coupon_errors ) )
			),
			409,
			[
				'removed_coupons' => $coupon_errors,
			]
		);
	}
}