Skip to content

Instantly share code, notes, and snippets.

@Astargh
Created February 22, 2017 22:44
Show Gist options
  • Save Astargh/43948416b28a3cb669059da5caf0eaf9 to your computer and use it in GitHub Desktop.
Save Astargh/43948416b28a3cb669059da5caf0eaf9 to your computer and use it in GitHub Desktop.
Input + - woocommerce
$(document).on('click', '.jckqv-qty-spinner', function () {
var $the_button = $(this),
$catalog = $the_button.parents('.catbox'),
$price = $catalog.find('.amount').attr('data-price-span'),
$pricePrev = $the_button.parents('.single_variation_wrap').find('.amount').attr('data-price-val'),
$qty_wrapper = $the_button.closest('.quantity'),
$qty_field = $qty_wrapper.find('.qty'),
dir = $the_button.attr('data-dir');
if (dir === "plus") {
$qty_field.val(function (i, oldval) {
return ++oldval;
});
} else {
$qty_field.val(function (i, oldval) {
if (oldval > 1) {
return oldval - 1;
} else {
return 1;
}
});
}
$catalog.find('.price').children('.amount').html($qty_field.val() * $price + '&nbsp;<span class="woocommerce-Price-currencySymbol"><span class="rur">р<span>уб.</span></span></span>');
});
<div class="quantity quantity-js catalog_item_count_sec">
<span>количество</span>
<input type="number" step="1" min="1" max="<?php echo esc_attr( $max_value ); ?>" name="<?php echo esc_attr( $input_name ); ?>" value="<?php echo esc_attr( $input_value ); ?>" title="<?php echo esc_attr_x( 'Qty', 'Product quantity input tooltip', 'woocommerce' ) ?>" class="input-text qty text" size="4" inputmode="numeric"/>
<div class="jckqv-qty-spinners">
<input type="button" value="+" data-dir="plus" class="jckqv-qty-spinner plus count_btns_sec count_plus_sec">
<input type="button" value="-" data-dir="minus" class="jckqv-qty-spinner minus count_btns_sec count_minus_sec">
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment