В настоящее время у меня есть функция настройки количества// количества и работы, но при добавлении этого в цикл количество количества дублируется на каждый вход при нажатии кнопок -/+ - см. Прилагаемое.Плюс и минус Qty в Loop
Любая помощь и совет будет полезным.
PHP
while ($loop->have_posts()) : $loop->the_post();
$price = get_post_meta(get_the_ID(), '_regular_price', true);
echo '<li id="'.$subID.'">'.get_the_title().' - £'.$price .' - ID '.$product->id.' ';
echo '<form id="'.$product->id.'" method="POST" action="#">';
echo '<input type="button" value="-" class="qtyminus" field="quantity" />';
echo '<input type="text" name="quantity" value="0" class="qty" />';
echo '<input type="button" value="+" class="qtyplus" field="quantity" />';
echo '</form>';
echo '</li>';
endwhile;
JS
function qty() {
$('.qtyplus').click(function(e){
e.preventDefault();
var fieldName = $(this).attr('field');
var currentVal = parseInt($('input[name='+fieldName+']').val());
if (!isNaN(currentVal)) {
$('input[name='+fieldName+']').val(currentVal + 1);
} else {
$('input[name='+fieldName+']').val(0);
}
});
$(".qtyminus").click(function(e) {
e.preventDefault();
var fieldName = $(this).attr('field');
var currentVal = parseInt($('input[name='+fieldName+']').val());
if (!isNaN(currentVal) && currentVal > 0) {
$('input[name='+fieldName+']').val(currentVal - 1);
} else {
$('input[name='+fieldName+']').val(0);
}
});
}
Спасибо Vixed! – Adam