Adding “same as billing” CheckBox to your Funnelish page

In this brief tutorial, I will be going through how to add a “same as billing” CheckBox to your page in Funnelish Just like this:

This is useful because it will save more time for the customer whose billing address is the same as their shipping address, so they won’t have to retype the same address.

Currently, Funnelish does not have a native feature to allow such functionality thus we will need to use a custom script to get the job done.

Step 1: Adding shipping details:

Add all of the shipping details just like the image below, and all other elements here are some details that need to be followed.
Make sure you set data names correctly.

  1. Shipping Address title.

  2. Shipping address information fields.

  3. Billing Address Title

  4. An Input Form of Type CheckBox (used to hide the billing address fields).


    => Ps: Now that you added the CheckBox form element make sure to give it the following details:
    image

Step 2: Adding Billing details (Will be hidden when the checkbox is checked):

Same as shipping details, except that the elements should be combined in a single container, just make sure to set data names correctly.

Here is how we need it to be.

All the elements are combined inside a Container with a unique ID to be used to hide it using our script, you can do so by selecting the Container then heading to the left menu and clicking on Advanced, then giving it the ID “billing_container”.

=> Here are the fields we need to add to the container:

  1. Billing Address information fields.

Step 3: Adding The Custom Code to Custom JS (body).

Again to the left Menu head to Custom Codes > Custom JS (Body) and paste this code into the box:

<script>
   let elements = ['country', 'city', 'address', 'state', 'zip'];
 elements.forEach(x=>{
                document.querySelector("[data-type='"+x+"']").value = document.querySelector("[data-type='shipping_"+x+"']").value;
        })
        
 elements.forEach(x=>{
            document.querySelector("[data-type='shipping_"+x+"']").addEventListener('change', () => {
                document.querySelector("[data-type='"+x+"']").value = document.querySelector("[data-type='shipping_"+x+"']").value;
            });
        })
document.querySelectorAll('input[data-name="same_billing"]').forEach((r,i) => {
  document.getElementById("billing_container").style.display = 'none';
  r.checked = true;
  r.addEventListener('change', function (){
    if (i === 0 && r.checked) {
        elements.forEach(x=>{
           document.querySelector("[data-type='"+x+"']").value =  document.querySelector("[data-type='shipping_"+x+"']").value;
        })
  document.getElementById("billing_container").style.display = 'none';
     }
    else{
      elements.forEach(x => {
      document.querySelector("[data-type='"+x+"']").value = '';
      });
      document.getElementById("billing_container").style.display = 'flex';
    }
  })
})
 </script>

Step 3: Styling (Optional).

Container 1:

  • Select the container and then at the left menu click background color:
    and past this color: #FAFAFA
  • Scroll down then add a Border to the container: border-width: 1px; and border Color: #D9D9D9; style: solid;
    You can also add some padding to the container (head to the Advanced tab in container options).

how to Set data names for input fields?

All input fields in the shipping container need to have properties look something like this:
PS: Data type needs to be changed for each element to the data the element is supposed to get.**

Example (for the Address field)

>Shipping address field needs to have these options:

image

>Billing address field needs to have these options:

image

How about if it’s the other way around? the Billing address section is not yet shown in Checkout page, and it will only show when people select “Use a different billing address”

image

1 Like

The code above does exactly that! It’s just worded differently:)

For the Radio buttons like the following:

Give each Radio Form Element a data name called same_billing
image

And that’s it! Use the exact same code above to get the results.