Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slaFFik/0885fcee6085ea977cf8e6fd177ba7b3 to your computer and use it in GitHub Desktop.
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.
<?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