Answer the question
In order to leave comments, you need to log in
How to add class to billing fields?
The task is to save the value of the fields through cookies (field names - "billing_first_name", "billing_last_name" and others).
I wrote the code but on wordpress it was not possible to add a class to the fields. Tried with jquery, same thing.
The HTML code that I gave is formed in wordpress (I brought it for the test), so there is no way to edit it.
Hoping for some help or hints, thanks.
PS I use the Saphali WC plugin to form fields. There, too, unfortunately, I dug into the code but did not find the opportunity to manually register the name of the class.
<script>
(function(jQuery){var isLS=typeof window.localStorage!=="undefined";function wls(n,v){var c;if(typeof n==="string"&&typeof v==="string"){localStorage[n]=v;return true}else if(typeof n==="object"&&typeof v==="undefined"){for(c in n)if(n.hasOwnProperty(c))localStorage[c]=n[c];return true}return false}function wc(n,v){var dt,e,c;dt=new Date;dt.setTime(dt.getTime()+31536E6);e="; expires="+dt.toGMTString();if(typeof n==="string"&&typeof v==="string"){document.cookie=n+"="+v+e+"; path=/";return true}else if(typeof n===
"object"&&typeof v==="undefined"){for(c in n)if(n.hasOwnProperty(c))document.cookie=c+"="+n[c]+e+"; path=/";return true}return false}function rls(n){return localStorage[n]}function rc(n){var nn,ca,i,c;nn=n+"=";ca=document.cookie.split(";");for(i=0;i<ca.length;i++){c=ca[i];while(c.charAt(0)===" ")c=c.substring(1,c.length);if(c.indexOf(nn)===0)return c.substring(nn.length,c.length)}return null}function dls(n){return delete localStorage[n]}function dc(n){return wc(n,"",-1)}jQuery.extend({Storage:{set:isLS?
wls:wc,get:isLS?rls:rc,remove:isLS?dls:dc}})})(jQuery);
(function input-text() {
var text, cl;
$(".input-text").each(function(i) {
cl = "input-text"+i;
$(this).addClass(cl); // add new class
text = $.Storage.get(cl);
if (text && text.length > 0 && !$(this).val()) {
$(this).val(text); // set field data
}
});
$(".input-text").keyup(function() {
$.Storage.set($(this).attr("class").split(" ")[$(this).attr("class").split(" ").length -1], $(this).val()); // save field data
});
$(".input-textSubmit").click(function() {
$(".input-text").each(function(i) {
$.Storage.remove("input-text"+i); // remove data
});
});
})();
</script>
<div class="accordion" id="checkout-accordion" style="float:left;width:50%;">
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#checkout-accordion" href="#collapse1">
Платежные данные и доставка </a>
</div>
<div id="collapse1" class="accordion-body collapse in">
<div class="accordion-inner">
<div class="form-billing-wrap">
<div class="woocommerce-billing-fields">
<p class="form-row form-row-first validate-required" id="billing_first_name_field"><label for="billing_first_name" class="">Имя <abbr
class="required" title="обязательно">*</abbr></label><input type="text" class="input-text" name="billing_first_name" id="billing_first_name"
placeholder="Иван" value=""></p>
<p class="form-row form-row-last validate-required" id="billing_last_name_field"><label for="billing_last_name" class="">Фамилия <abbr
class="required" title="обязательно">*</abbr></label><input type="text" class="input-text " name="billing_last_name" id="billing_last_name"
placeholder="Иванов" value=""></p><div class="clear"></div>
<p class="form-row form-row-first validate-required" id="billing_email_field"><label for="billing_email" class="">Email-адрес <abbr
class="required" title="обязательно">*</abbr></label><input type="text" onblur="var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-
9]{2,4})+$/;if(regex.test(this.value)) { try {rrApi.setEmail(this.value);}catch(e){}}" class="input-text " name="billing_email"
id="billing_email" placeholder="[email protected]" value=""></p>
<p class="form-row form-row-last" id="billing_phone_field"><label for="billing_phone" class="">Телефон</label><input type="text" class="input-
text " name="billing_phone" id="billing_phone" placeholder="89161234567" value=""></p><div class="clear"></div>
<p class="form-row " id="order_comments_field"><label for="order_comments" class="">Примечания к заказу</label><textarea name="order_comments"
class="input-text " id="order_comments" placeholder="" rows="2" cols="5"></textarea></p>
<p class="form-row form-row-first address-field" id="billing_postcode_field"><label for="billing_postcode" class="">Почтовый индекс</label><input
type="text" class="input-text " name="billing_postcode" id="billing_postcode" placeholder="Почтовый индекс" value=""></p>
<p class="form-row form-row-last address-field" id="billing_city_field"><label for="billing_city" class="">Город</label><input type="text"
class="input-text " name="billing_city" id="billing_city" placeholder="Город" value=""></p>
<p class="form-row form-row-first address-field" id="billing_street_field"><label for="billing_street" class="">Улица</label><input type="text"
class="input-text " name="billing_street" id="billing_street" placeholder="Улица" value=""></p>
<p class="form-row form-row-last address-field" id="billing_house_field"><label for="billing_house" class="">Дом</label><input type="text"
class="input-text " name="billing_house" id="billing_house" placeholder="Дом" value=""></p><div class="clear"></div>
<p class="form-row form-row-first address-field" id="billing_new_fio_field"><label for="billing_new_fio" class="">ФИО</label><input type="text"
class="input-text " name="billing_new_fio" id="billing_new_fio" placeholder="Иванов Иван Иванович" value=""></p>
<p class="form-row form-row-last address-field" id="billing_new_passport_field"><label for="billing_new_passport" class="">Серия номер
паспорта</label><input type="text" class="input-text " name="billing_new_passport" id="billing_new_passport" placeholder="7811 123456"
value=""></p><div class="clear"></div>
<p class="form-row form-row-wide create-account">
<input class="input-checkbox" id="createaccount" type="checkbox" name="createaccount" value="1"> <label for="createaccount"
class="checkbox">Зарегистрировать вас?</label>
</p>
<div class="create-account">
<p>Заполнив нижеуказанные поля, можно создать постоянный профиль на нашем сайте. Если вы уже совершали покупки у нас и регистрировались ранее, то
вы можете авторизоваться, заполнив поле логина и пароля наверху.</p>
<p class="form-row validate-required" id="account_password_field"><label for="account_password" class="">Пароль к аккаунту <abbr class="required"
title="обязательно">*</abbr></label><input type="password" class="input-text " name="account_password" id="account_password" placeholder="Пароль"
value=""></p>
<div class="clear"></div>
</div>
</div></div>
</div>
</div>
</div>
<a href="/cart/" style="padding-top:10px;float:left;"><div class="btn btn-warning">Назад</div></a>
</div>
Answer the question
In order to leave comments, you need to log in
Did you manage to resolve the issue? I have the same problem - one to one I use the same
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question