Default value for zip code

This topic contains 8 replies, has 4 voices, and was last updated by  Naveen Giri 4 years ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #533785

    blumbre
    Free User
    Post count: 61

    Hi,

    I would like to know how can I set a default value for the zip code in the input form for the user.

    Thanks!

    #533794

    Kor
    Moderator
    Post count: 16516

    Hi blumbre,

    Thanks for your post. Unfortunately, what you needed there isn’t possible out of the box and would require customization. May I ask, why would you want to do that?

    #533971

    blumbre
    Free User
    Post count: 61

    Hi Kor,

    Thanks for your answer.
    I want it because the map that I use is centered in a point and users only insert the street, but not the city…so, the map is not able to find the correct address, if I insert the zip code, it can find it…

    Can you tell me the customization that I must do please?

    Thanks!

    #534001

    Alex Rollin
    Moderator
    Post count: 27815

    You could try adding more words to the address description, informing your site visitors what they should type in to find an address.

    #534727

    blumbre
    Free User
    Post count: 61

    Hi,

    The problem that I have is that it’s always in the same place, so it’s not pleasant to do my users to insert always this data..that is why I wonder if I could do it as a snippet code to could set as default….

    Is there any way to do it?

    Thanks!

    #534728

    Kor
    Moderator
    Post count: 16516

    Hi blumbre,

    Thanks for your reply. Sorry, there isn’t a way to achieve this without customization. Please allow me to forward this to a developer for a second opinion.

    #534875

    Naveen Giri
    Moderator
    Post count: 1559

    You can do it with the help of this code.

    
    add_action( 'wp_head', function () { ?>
    	<script>
    
    		/* write your JavaScript code here */
    
    		jQuery(document).ready(function(){
                       jQuery('#address_zip').val('401107'); //make sure to replace it with correct zip code.
    
    		});
    	</script>
    <?php } );
    

    Thanks
    Naveen

    #539456

    blumbre
    Free User
    Post count: 61

    Hi Naveen,

    Thanks!! It worked! 🙂
    One more thing…is it possible to hide the field so that users can’t change it but it will still be considered by the address search?

    Thanks!!

    #539469

    Naveen Giri
    Moderator
    Post count: 1559

    You can use this code but it will get change if someone changes the address by dragging the map marker.

    
    add_action( 'wp_head', function () { ?>
    	<script>
    
    		/* write your JavaScript code here */
    
    		jQuery(document).ready(function(){
                       jQuery('#address_zip').val('401107'); //make sure to replace it with correct zip code.
     jQuery('#address_zip').attr('disabled', true);
    		});
    	</script>
    <?php } );
    
    

    Thanks

Viewing 9 posts - 1 through 9 (of 9 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket