Support » Plugin: WooCommerce » check out field postcode change to select

  • Resolved charles960915

    (@charles960915)


    im using WooCommerce below code i find in online and past it in my flatsome child function.php. when i use it the value come show in my check out postcode field is 0,1,3. the result should be 001122, 112200,334400.. can anyone help me. i really need the solution

    `add_filter( ‘woocommerce_default_address_fields’ , ‘custom_override_default_postcode_field’ );
    function custom_override_default_postcode_field( $address_fields ) {
    // Your postcodes array
    $postcode_array = array(
    ‘opt1’ => “001122”,
    ‘opt2’ => “112200”,
    ‘opt3’ => “334400”
    );
    $address_fields[‘postcode’][‘type’] = ‘select’;
    $address_fields[‘postcode’][‘options’] = $postcode_array;

    return $address_fields;
    }

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Rynald0s.a11n

    (@rynald0s)

    Automattic Happiness Engineer

    Hi @charles960915!

    Use the following code, and tweak to your specific needs. You can extend the array.

    add_filter('woocommerce_default_address_fields', 'custom_override_default_postcode_field');
    function custom_override_default_postcode_field($address_fields)
    {
        // Your postcodes array
        $postcode_array = array("001122" => "112200", "334400" => "334405");
        $address_fields['postcode']['type'] = 'select';
        $address_fields['postcode']['options'] = $postcode_array;
        return $address_fields;
    }

    Cheers!

    Doug – a11n

    (@dougaitken)

    Automattic Happiness Engineer

    Hi @charles960915

    I hope Rynaldo’s snippet helped out here. We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

    Thanks,

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘check out field postcode change to select’ is closed to new replies.