Skip to content

Commit

Permalink
Improve handling free text value.
Browse files Browse the repository at this point in the history
  • Loading branch information
rvdsteege committed Aug 25, 2023
1 parent 3ce7845 commit d13802a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Pronamic.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ public static function get_submission_value( WPCF7_Submission $submission, $type

switch ( $type ) {
case 'amount':
/**
* Contact Form 7 concatenates the field option value with user input for free text fields. We
* are only interested in the input value as amount.
*
* @link https://github.com/rocklobster-in/contact-form-7/blob/2cfaa472fa485c6d3366fcdd80701fdaf7f9e425/includes/submission.php#L434-L437
*/
if ( \wpcf7_form_tag_supports( $tag->type, 'selectable-values' ) && $tag->has_option( 'free_text' ) ) {
$values = \WPCF7_USE_PIPE ? $tag->pipes->collect_afters() : $tag->values;

$last_value = end( $values );

if ( \str_starts_with( $value, $last_value . ' ' ) ) {
$value = substr_replace( $value, '', 0, strlen( $last_value . ' ' ) );
}
}

$value = Tags\AmountTag::parse_value( $value );

// Set parsed value as result or add to existing money result.
Expand Down

0 comments on commit d13802a

Please sign in to comment.