wpforms_process_validate_payment-coupon

Beschreibung

Die wpforms_process_validate_payment-coupon Aktion löst die Validierung der Coupon Formularfeld, wenn das Formular abgeschickt wird.

Parameter

$feld_id
(int) Feld-ID.
$field_submit
(array) Ursprünglicher roher/unsanierter Feldwert, der für das Feld übermittelt wurde.
$form_data
(Array) Verarbeitete Formulareinstellungen/Daten, die für die spätere Verwendung vorbereitet sind.

Quelle

wpforms/includes/class-process.php

Mehr Informationen

Die wpforms_process_validate_payment-coupon Aktion wird auf die Coupon Formularfeld zur Überprüfung des Betrags des Gutscheins, der beispielsweise über einem bestimmten, in der Funktion festgelegten Betrag liegt.

Beispiele

In diesem Beispiel wird verhindert, dass ein Formular abgeschickt wird, wenn der Betrag der Gutscheinpauschale unter 1,00 liegt.

/*
 * Do not allow to submit coupons lower than 1.00.
 *
 * @link https://wpforms.com/developers/wpforms_process_validate_payment-coupon/
 *
 * @param int     $field_id        Field ID.
 * @param array   $field_submit    Unsanitized field value submitted for the field.
 * @param array   $form_data       Form data and settings.
*/

function wpf_discard_low_coupons( $field_id, $field_submit, $form_data ) {

	$coupon = wpforms_coupons()->get( 'repository' )->get_coupon_by_code( $field_submit );

	if ( $coupon === null ) {
		return;
	}

	$currency = wpforms_get_currency();

	if ( $coupon->get_discount_type() === 'flat' && (float) $coupon->get_discount_amount() <= 1.00 ) {
		wpforms()->get( 'process' )->errors[ $form_data[ 'id' ] ][ $field_id ] = sprintf( /* translators: %s - Currency code name. */
			esc_html__( 'Coupon amount is less that 1.00 %s. Please, use another one.', 'your-translation-domain' ),
			$currency
		);
	}
}
add_action( "wpforms_process_validate_payment-coupon", 'wpf_discard_low_coupons', 10, 3 );

Artikel-Referenz: Wie man Gutscheine nach Betrag einschränkt