Last active
May 10, 2020 22:23
-
-
Save kyledurand/c147678d00f2ccb10920 to your computer and use it in GitHub Desktop.
Pre populating the billing address at checkout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% if customer and customer.addresses[0].country %} | |
{{ '//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js' | script_tag }} | |
<style> | |
.js .field--same-billing-address { | |
display: none !important; | |
} | |
#checkout_billing_address_country, #checkout_billing_address_province { | |
cursor: default; | |
pointer-events:none; | |
} | |
</style> | |
<script> | |
$(document).ready(function() { | |
$('.field--different-billing-address label').click(); | |
$("#checkout_billing_address_first_name").val('{{customer.addresses[0].first_name}}').prop('readonly', true); | |
$("#checkout_billing_address_last_name").val('{{customer.addresses[0].last_name}}').prop('readonly', true); | |
$("#checkout_billing_address_address1").val('{{customer.addresses[0].address1}}').prop('readonly', true); | |
$("#checkout_billing_address_address2").val('{{customer.addresses[0].address2}}').prop('readonly', true); | |
$("#checkout_billing_address_street").val('{{customer.addresses[0].street}}').prop('readonly', true); | |
$("#checkout_billing_address_company").val('{{customer.addresses[0].company}}').prop('readonly', true); | |
$("#checkout_billing_address_city").val('{{customer.addresses[0].city}}').prop('readonly', true); | |
$("#checkout_billing_address_country").val('{{customer.addresses[0].country}}'); | |
$('#checkout_billing_address_province').append('<option value="{{customer.addresses[0].province}}">{{customer.addresses[0].province}}</option>'); | |
$("#checkout_billing_address_province").val('{{customer.addresses[0].province}}'); | |
$("#checkout_billing_address_zip").val('{{customer.addresses[0].zip}}').prop('readonly', true); | |
$("#checkout_billing_address_phone").val('{{customer.addresses[0].phone}}').prop('readonly', true); | |
}); | |
</script> | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The issue arose from adding the 'disabled' attribute to the country and province dropdowns. I've updated the gist to use the css pointer-events: none property instead.