Filter uncanny-automator

wwlc_filter_postcode_field_form_placeholder

Filters the placeholder text for the postcode field in wholesale forms, allowing customization of the default value.

add_filter( 'wwlc_filter_postcode_field_form_placeholder', $callback, 10, 1 );

Description

This filter allows developers to modify the placeholder text for the postcode field in Wholesale Suite forms. You can change the default placeholder, which is retrieved from plugin settings, to provide more specific guidance to users. This is useful for adapting the form to different regions or specific requirements.


Usage

add_filter( 'wwlc_filter_postcode_field_form_placeholder', 'your_function_name', 10, 1 );

Return Value

The filtered value.


Examples

/**
 * Filters the placeholder text for the postcode field in the form.
 *
 * This function modifies the default placeholder text for the postcode field.
 * For example, it could prepend a country code or add a specific format instruction.
 *
 * @param string $placeholder The current placeholder text for the postcode field.
 * @return string The modified placeholder text.
 */
add_filter( 'wwlc_filter_postcode_field_form_placeholder', function( $placeholder ) {
    // Check if the current placeholder is empty and if a specific placeholder is set in options.
    if ( empty( $placeholder ) ) {
        $custom_placeholder = get_option( 'wwlc_fields_postcode_placeholder', '' );
        // If a custom placeholder is set, use it.
        if ( ! empty( $custom_placeholder ) ) {
            return esc_attr( $custom_placeholder );
        }
    }

    // Add a country-specific hint if the user's country is known or can be inferred.
    // This is a simplified example; in a real scenario, you might check user IP or profile.
    // For demonstration, let's assume we want to suggest a UK postcode format if likely.
    // In a more complex setup, you might have a setting for default country.
    $country_hint = '';
    // Example: if a default country setting is available and it's UK
    // $default_country = get_option( 'wwlc_default_country', '' );
    // if ( 'GB' === $default_country ) {
    //     $country_hint = ' (e.g., SW1A 0AA)';
    // }

    // You could also dynamically change it based on the form context if available.
    // For instance, if this form is for a specific region.

    // Combine the existing placeholder with any additional hints.
    return $placeholder . $country_hint;
}, 10, 1 );

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/integrations/wholesale-suite/helpers/wholesale-suite-helpers.php:156

'placeholder' => apply_filters( 'wwlc_filter_state_field_form_placeholder', get_option( 'wwlc_fields_state_placeholder', '' ) ),
			),
			'wwlc_postcode'     => array(
				'label'       => apply_filters( 'wwlc_filter_postcode_field_form_label', esc_html__( 'Postcode', 'uncanny-automator' ) ),
				'type'        => 'text',
				'required'    => ( get_option( 'wwlc_fields_require_address_field' ) == 'yes' ) ? true : false,
				'active'      => ( get_option( 'wwlc_fields_activate_address_field' ) == 'yes' ) ? true : false,
				'placeholder' => apply_filters( 'wwlc_filter_postcode_field_form_placeholder', get_option( 'wwlc_fields_postcode_placeholder', '' ) ),
			),
			'wwlc_role'         => array(
				'label'       => esc_html__( 'Role', 'uncanny-automator' ),
				'type'        => 'text',
				'required'    => true,
				'active'      => true,
				'placeholder' => esc_html__( 'Set user role', 'uncanny-automator' ),


Scroll to Top