News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

"Displayed Name" in Checkout: Can it Auto-Fill with First & Last Name and Hide

Started by bryanearl, May 12, 2018, 00:48:05 AM

Previous topic - Next topic

bryanearl

Alright, I have done a lot of reading about this topic but I cannot seem to find this exact info to make this work for me... In checkout, there is a field for "Displayed Name", which I have learned is for the Joomla Core user field "Name" when registering an account. Therefore, I understand that in order to register an account during checkout, SOMETHING needs to be used there.

However, I do NOT want this field to be seen by customers because it is confusing and redundant. Therefore, I would like to hide the field using CSS and auto-fill it with whatever the user inputs for the "First Name" and "Last Name" fields.

I found something close, which looks to be editing this file (templates\xxxxxxxxx\html\com_virtuemart\user\edit_address_userfields.php) and it allows auto-filling the "Displayed Name" field using the "username" data:

<?php
if ($addrtype != 'ST') {
?>

<script type="text/javascript">
    document.getElementById("username_field").setAttribute("onchange", "username_is_name_field()");
   
    function username_is_name_field(){
      var reg_fill_name_field = document.getElementById("username_field").value
      document.getElementById("name_field").value = (reg_fill_name_field);
   }
</script>
<?php  ?>


However, I really want it to auto-fill using the "first name" AND "last name" fields instead of username. Can anyone help me with this one?


bryanearl

UPDATE:

I have managed to make this work on the basic, built-in registration and checkout pages (the URL I provided above) by finding a code snippet from someone else. It does exactly what I wanted, which is to auto-fill the "Displayed Name" field using the First name + Last Name.

Here is the working code, by creating an override of the "edit_address_userfields.php" file:

<script type="text/javascript">
document.getElementById("email_field").setAttribute("onchange", "mail_is_user()");
    function mail_is_user(){
var reg_email = document.getElementById("email_field").value;
document.getElementById("username_field").value = (reg_email);
}

document.getElementById("first_name_field").setAttribute("onchange", "joomla_name_is_vmname()");
document.getElementById("last_name_field").setAttribute("onchange", "joomla_name_is_vmname()");
    function joomla_name_is_vmname(){
var first_name = document.getElementById("first_name_field").value;
var last_name = document.getElementById("last_name_field").value;
document.getElementById("name_field").value = (first_name + ' ' + last_name);
}
</script>


Now, I just need to find a good One-Page Checkout plugin!