I am trying to disable the 'Proceed to Checkout' button when the cart quantities are changed. To do this, Im using jQuery to inject some CSS to the proceed button (see below).
The code I am currently using works but it only works for the first time the cart is updated. If the user then edits their cart for a seconds time, the priced to checkout button stays active.
The tricky part to this was targeting the correct elements as is seems as though the IDs are dynamically created by WooCommerce so they change each time the page is loaded.
// Disable proceed button
$( ".product-quantity > .quantity > input" ).change( function() {
$( 'a.checkout-button' ).css({
'pointer-events': 'none',
'opacity': '0.25'
});
});
$( '.actions > input[type="submit"]' ).click( function() {
$( 'a.checkout-button' ).css({
'pointer-events': 'auto',
'opacity': '1'
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="shop_table shop_table_responsive cart woocommerce-cart-form__contents" cellspacing="0">
<thead>
<tr>
<th class="product-remove"> </th>
<th class="product-thumbnail"> </th>
<th class="product-name">Product</th>
<th class="product-price">Price</th>
<th class="product-quantity">Quantity</th>
<th class="product-subtotal">Total</th>
</tr>
</thead>
<tbody>
<tr class="woocommerce-cart-form__cart-item cart_item">
<td class="product-remove">
<a href="http://mowgli.dev/basket/?remove_item=0039818e7547d3314205171d9ec650da&_wpnonce=09541aba5e" class="remove" aria-label="Remove this item" data-product_id="166" data-product_sku="">×</a>
</td>
<td class="product-thumbnail">
<a href="http://mowgli.dev/product/gift-cards/?attribute_choose-value=%C2%A3100.00">
<img src="//mowgli.dev/wp-content/uploads/2017/09/PR-Gift-Card-180x180.png" class="attachment-shop_thumbnail size-shop_thumbnail wp-post-image" alt="" srcset="//mowgli.dev/wp-content/uploads/2017/09/PR-Gift-Card-180x180.png 180w, //mowgli.dev/wp-content/uploads/2017/09/PR-Gift-Card-150x150.png 150w, //mowgli.dev/wp-content/uploads/2017/09/PR-Gift-Card-300x300.png 300w" sizes="(max-width: 180px) 100vw, 180px" width="180" height="180">
</a>
</td>
<td class="product-name" data-title="Product">
<a href="http://mowgli.dev/product/gift-cards/?attribute_choose-value=%C2%A3100.00">Gift Cards - £100.00</a> </td>
<td class="product-price" data-title="Price">
<span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">£</span>100.00</span> </td>
<td class="product-quantity" data-title="Quantity">
<div class="quantity">
<label class="screen-reader-text" for="quantity_59f058ed51782">Quantity</label>
<input id="quantity_59f058ed51782" class="input-text qty text" step="1" min="0" max="" name="cart[0039818e7547d3314205171d9ec650da][qty]" value="21" title="Qty" size="4" pattern="[0-9]*" inputmode="numeric" type="number">
</div>
</td>
<td class="product-subtotal" data-title="Total">
<span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">£</span>2,100.00</span> </td>
</tr>
<tr>
<td colspan="6" class="actions">
<input class="button" name="update_cart" value="Update basket" disabled="" type="submit">
<input id="_wpnonce" name="_wpnonce" value="09541aba5e" type="hidden"><input name="_wp_http_referer" value="/basket/" type="hidden">
</td>
</tr>
</tbody>
</table>
<div class="wc-proceed-to-checkout">
<a href="http://mowgli.dev/checkout/" class="checkout-button button alt wc-forward">
Proceed to checkout</a>
</div>
I have already checked the following posts on SO which haven't really helped me: