Created
October 8, 2018 17:59
-
-
Save slaFFik/0885fcee6085ea977cf8e6fd177ba7b3 to your computer and use it in GitHub Desktop.
WPForms: Make "$40.00 - Second Choice" instead of "Second Choice - $40.00" for different payment fields.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Make "$40.00 - Second Choice" instead of "Second Choice - $40.00" | |
* for different payment fields. | |
*/ | |
add_filter( 'wpforms_html_field_value', function ( $value, $field, $form_data, $context ) { | |
if ( 'email-html' !== $context ) { | |
return $value; | |
} | |
$form_id = (int) $form_data['id']; | |
// For a specific form. | |
// REMOVE IF NEEDED FOR ALL FORMS. | |
if ( 1 !== $form_id ) { | |
return $value; | |
} | |
// Different field types have different data format. | |
switch ( $field['type'] ) { | |
case 'payment-select': | |
$value = wpforms_format_amount( $field['amount_raw'], true ) . ' - ' . $field['value_choice']; | |
break; | |
case 'payment-single': | |
$value = wpforms_format_amount( $field['amount_raw'], true ) . ' - ' . $field['name']; | |
break; | |
case 'payment-multiple': | |
$field_submit = $field['value_raw']; | |
if ( | |
! empty( $field_submit ) && | |
! empty( $field['choices'][ $field_submit ]['value'] ) && | |
! empty( $field['choices'][ $field_submit ]['label'] ) | |
) { | |
$amount = wpforms_format_amount( wpforms_sanitize_amount( $field['choices'][ $field_submit ]['value'] ), true ); | |
$value = $amount . ' - ' . sanitize_text_field( $field['choices'][ $field_submit ]['label'] ); | |
} | |
break; | |
} | |
return $value; | |
}, 15, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment