Categories
WooCommerce

WooCommerce Quantity Buttons

Insert quantity buttons in the mobile to the options that the WooCommerce Extra Product Options plugin creates (update the product id):

if ( wp_is_mobile() ) {
	add_action( 'wp_footer', 'condless_add_cart_quantity_plus_minus' );
	add_action( 'wc_epo_quantity_selector_before_input', 'condless_display_quantity_minus' );
	add_action( 'wc_epo_quantity_selector_after_input', 'condless_display_quantity_plus' );
}

function condless_display_quantity_plus() {
	if ( is_product() && is_single( '683' ) ) {
		echo '<button type="button" class="plus">+</button>';
	}
}

function condless_display_quantity_minus() {
	if ( is_product() && is_single( '683' ) ) {
		echo '<button type="button" class="minus">-</button>';
	}
}

function condless_add_cart_quantity_plus_minus() {
	if ( is_product() && is_single( '683' ) ) {
		?>
			<script type="text/javascript">
			jQuery( function( $ ) {
				$( 'form.cart' ).on( 'click', 'button.plus, button.minus', function() {
					var qty = $( this ).closest( 'form.cart' ).find( '.tm-qty' ), val = parseFloat( qty.val() ), max = 1000, min = parseFloat( qty.attr( 'min' ) ), step = 1;
					if ( $( this ).is( '.plus' ) ) {
						if ( max && ( max <= val ) ) {
							qty.val( max );
						} else {
							qty.val( val + step );
						}
					} else {
						if ( min && ( min >= val ) ) {
							qty.val( min );
						} else if ( val > 1 ) {
							qty.val( val - step );
						}
					}
					$( '.tm-qty' ).trigger( 'change' );
				} );
			} );
			</script>
		<?php
	}
}

Leave a Reply

Your email address will not be published. Required fields are marked *