Descrizione
Il wpforms_process_validate_payment-coupon
lancia la validazione dell'azione Coupon quando il modulo viene inviato.
Parametri
- $campo_id
- (int) ID del campo.
- $campo_submit
- (array) Valore originale del campo grezzo/non sanificato inviato per il campo.
- $form_data
- (array) Impostazioni/dati del modulo elaborati, preparati per essere utilizzati in seguito.
Fonte
wpforms/includes/class-process.php
Ulteriori informazioni
Il wpforms_process_validate_payment-coupon
viene applicata all'elemento Coupon campo modulo per il controllo dell'importo del buono, ad esempio superiore a un determinato importo impostato nella funzione.
Esempi
In questo esempio, si impedisce l'invio di un modulo se l'importo forfettario del coupon è inferiore a 1,00.
/* * 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 );
Correlato
Riferimento articolo: Come limitare i coupon per importo