説明
について wpforms_process_validate_payment-coupon
アクションは クーポン フォームが送信されたときのフォーム・フィールド。
パラメータ
- フィールドID
- (int)フィールドID。
- フィールド・サブミット
- (配列)そのフィールドに対して送信された、生の/未サニタイズのフィールド値。
- フォームデータ
- (配列) 処理済みのフォーム設定/データ。
ソース
wpforms/includes/class-process.php
詳細情報
について wpforms_process_validate_payment-coupon
アクションが適用される。 クーポン クーポンの金額をチェックするためのフォームフィールドで、例として、関数で設定された特定の金額以上です。
例
この例では、クーポンの定額料金が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 );
関連
記事参照クーポンを金額で制限する方法