@ygen

Как добавить класс к полям billing?

Задача - необходимо сохранять значение полей через cookies (название полей - "billing_first_name", "billing_last_name" и прочие).

Написал код но на wordpress не получилось добавить класс к полям. Пробовал через jquery, тоже самое.

Код HTML который я дал формируется в wordpress (привел для теста), поэтому отредактировать его нет возможности.

Надеюсь на помощь или подсказки, спасибо.
P.S. использую плагин Saphali WC для формирования полей. Там тоже к сожалению копался в коде но не нашел возможность прописать вручную название класса.

<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="example@mail.ru" 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>
  • Вопрос задан
  • 520 просмотров
Решения вопроса 1
@ygen Автор вопроса
ygen @ygen
Видимо не пропустили код.

jQuery(function($){
$("#billing_phone").mask("+7(999)999-99-99",{placeholder:"+7(999)999-99-99"});
$("#billing_postcode").mask("999999",{placeholder:"999999"});
$("#billing_new_passport").mask("9999 999999",{placeholder:"9999 999999"});
});
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 2
@kapitan7830
А в чем собственно вопрос?
Ответ написан
@ruff-a-hell
Удалось ли решить вопрос? У меня та же самая проблема - один в один всё то же самое использую
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы