cwcfp_letter_fee_length

The cwcfp_letter_fee_length filter allows you to modify the length of a text string based on custom rules that you can set in your own code.

By default, the filter will return a value that is equal to strlen( $customer_input );

The filter is passed four parameters:

  • $customer_input_length: This is equal to the value that strlen( $customer_input ); would provide.
  • $customer_input: The value that the customer has entered into the text box or text area field.
  • $field_id: The conditional field's ID number
  • $i: The number that this field has repeated. If there are three of the same field shown on the checkout page, this value could be 1, 2, or 3.

If for some reason the strlen( $customer_input ); is not generating the correct count for your purposes, you can use this filter to apply some other logic to count the number of letters in the customer's input.

For example, by default this will include spaces between words. If you only want to include non-space characters, you could use this filter to strip out the spaces first before counting.

	add_filter( 'cwcfp_letter_fee_length', 'no_spaces_in_fee', 10, 4 );
	function no_spaces_in_fee( $customer_input_length, $customer_input, $field_id, $i ) {
		$new_str = str_replace( ' ', '', $customer_input); //remove all spaces from a string
		$customer_input_length = strlen( $new_str ); // get the length of the new string
		return $customer_input_length; // return the length of the new string
	}

You may also only want to do this when $field_id = 7, which you can do as well.

	add_filter( 'cwcfp_letter_fee_length', 'no_spaces_in_fee', 10, 4 );
	function no_spaces_in_fee( $customer_input_length, $customer_input, $field_id, $i ) {
		if ( 7 == $field_id ) {
			$new_str = str_replace( ' ', '', $customer_input); //remove all spaces from a string
			$customer_input_length = strlen( $new_str ); // get the length of the new string
		}
		return $customer_input_length; // return the length of the new string, or the original string if this is not $field_id 7
	}