i copy paste this (global/quantity-input.php) file into my theme directory. And made this changes
`
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
?>
<div class="quantity">
<input class="minus" type="button" value="-">
<input type="number" step="<?php echo esc_attr( $step ); ?>" min="<?php echo esc_attr( $min_value ); ?>" 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" />
<input class="plus" type="button" value="+">
</div>
also this jquery code into my js file.
<script type="text/javascript">
jQuery(document).ready(function($){
$('.quantity').on('click', '.plus', function(e) {
$input = $(this).prev('input.qty');
var val = parseInt($input.val());
$input.val( val+1 ).change();
});
$('.quantity').on('click', '.minus',
function(e) {
$input = $(this).next('input.qty');
var val = parseInt($input.val());
if (val > 0) {
$input.val( val-1 ).change();
}
});
});
</script>
it works fine but the problem is when i update any product on cart page it doesn't work anymore. is there any kind of solution? Please correct me if i did anything wrong?
Thanks
You have the first part correct. Your code will work when loading a page. But in addition to this you need to add an event for the AJAX calls.
I also added .off() so the value wont add itself multiple times after every AJAX call.
<script type="text/javascript">
jQuery(document).ajaxComplete(function(){
jQuery('.quantity').off('click', '.plus').on('click', '.plus', function(e) {
$input = jQuery(this).prev('input.qty');
var val = parseInt($input.val());
$input.val( val+1 ).change();
});
jQuery('.quantity').off('click', '.minus').on('click', '.minus',
function(e) {
$input = jQuery(this).next('input.qty');
var val = parseInt($input.val());
if (val > 1) {
$input.val( val-1 ).change();
}
});
});
</script>