Skip to content

Instantly share code, notes, and snippets.

@imesut
Created September 12, 2019 21:37
Show Gist options
  • Save imesut/501f5cff83b7370b5dba2d4d46674c8a to your computer and use it in GitHub Desktop.
Save imesut/501f5cff83b7370b5dba2d4d46674c8a to your computer and use it in GitHub Desktop.
function getCookie(name) {
var v = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)');
return v ? v[2] : null;
}
function fillParilti() {
//Show Other Shipping Address Field
document.getElementsByClassName("shipping_address")[0].style.display = "block";
document.getElementById("ship-to-different-address-checkbox").checked = true;
// Fill info
document.getElementById("shipping_first_name").value = "Parıltı";
document.getElementById("shipping_last_name").value = "Derneği";
document.getElementById("shipping_company").value = "Parıltı Derneği";
document.getElementById("shipping_address_1").value = "Büyükdere Cad.";
document.getElementById("shipping_address_2").value = "Bentek İş Merkezi No:47 D:2";
document.getElementById("shipping_postcode").value = "34387";
document.getElementById("shipping_city").value = "Şişli";
document.getElementById("shipping_phone").value = "+90 (212) 288 51 44";
document.getElementById("shipping_state").value = "TR34";
document.getElementById("select2-shipping_state-container").innerText = "İstanbul";
document.getElementById("select2-shipping_state-container").setAttribute("title", "İstanbul");
}
// This funtions fills form immediately if cookie has set
window.onload = function gift() {
var cookieValue = getCookie("send_to_parilti");
if(cookieValue == 1) {
document.getElementById("shipping_selector").value = "parilti";
fillParilti();
}
}
// This is a listener allows user to change shipping state
document.addEventListener('DOMContentLoaded',function(){
document.getElementById("shipping_selector").addEventListener("change", function(){
if(document.getElementById("shipping_selector").value == "parilti"){
document.cookie = "send_to_parilti = 1; path=/";
fillParilti();
}
else if (document.getElementById("shipping_selector").value == "myself"){
// Unset cookie
document.cookie = "send_to_parilti = 0; path=/";
// Empty fields
document.getElementById("shipping_first_name").value = "";
document.getElementById("shipping_last_name").value = "";
document.getElementById("shipping_company").value = "";
document.getElementById("shipping_address_1").value = "";
document.getElementById("shipping_address_2").value = "";
document.getElementById("shipping_postcode").value = "";
document.getElementById("shipping_city").value = "";
document.getElementById("shipping_state").value = "";
document.getElementById("select2-shipping_state-container").innerText = "";
document.getElementById("select2-shipping_state-container").setAttribute("title", "");
document.getElementsByClassName("shipping_address")[0].style.display = "none";
document.getElementById("ship-to-different-address-checkbox").checked = false;
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment