• Resolved EarShell

    (@earshell)


    Does this plugin allow you to set different character lengths for checkout fields such as the “address” and “email” fields, etc.?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support dominikl65

    (@dominikl65)

    Hi,

    This can be solved in several ways:

    1. Use of HTML attributes i.e. adding maxlength=”x” for example. Code:
      add_action( 'flexible_checkout_fields_custom_attributes', function ( array $custom_attrs, array $field_data ) { if ( in_array( $field_data['name'], [ 'billing_company', 'billing_organization' ], true ) ) { $custom_attrs['maxlength'] = '30'; } return $custom_attrs; }, 10, 2 );
      Here, maxlength is set to 30 for the fields from billing_company and billing_organisation – you can change the values for your fields created in the FCF plug-in here.
    2. Custom validation – in the example also 30 characters max length after adding to functions.php (you can go there from View → Theme file editor → functions.php) you still have to select this validation in the settings (fields in the FCF plugin) and save (after adding this code it should appear there). Code:
      /** * Add custom number validation * */ add_filter( 'flexible_checkout_fields_custom_validation', 'wpdesk_fcf_custom_validation_field_value_length' ); function wpdesk_fcf_custom_validation_field_value_length( $custom_validation ) { $custom_validation['number'] = array( 'label' => 'Field length less than 30', 'callback' => 'wpdesk_fcf_validate_field_value_length' ); return $custom_validation; } /** * Function to validate if value length is less than 30 * */ function wpdesk_fcf_validate_field_value_length( $field_label, $value ) { if ( strlen( $value ) > 30 ) { wc_add_notice( sprintf( '%s is too long.', '<strong>' . $field_label . '</strong>' ), 'error' ); } }
    Plugin Support dominikl65

    (@dominikl65)

    Hi,

    I haven’t heard from you in a while, so I’m marking this thread as resolved. Please don’t hesitate to open a new one if you encounter other issues while using our plugin.

    Have a fantastic day,

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.