Christophvh Christophvh - 4 months ago 403
jQuery Question

Woocommerce 2.6.2 adds disabled attribute to update cart button

I am using Wordpress

4.5.3
and Woocommerce
2.6.2
.

Code inside woocommerce/cart/cart.php

<input type="submit" class="button" id="update_cart_button" name="update_cart" value="<?php esc_attr_e( 'Update Cart', 'woocommerce' ); ?>" />

<?php do_action( 'woocommerce_cart_actions' ); ?>

<?php wp_nonce_field( 'woocommerce-cart' ); ?>


Which generates following html:

<input type="submit" class="button" id="update_cart_button" name="update_cart" value="Winkelmand bijwerken" disabled="">
<input type="hidden" id="_wpnonce" name="_wpnonce" value="847e1da0f8">
<input type="hidden" name="_wp_http_referer" value="/winkelmand/">


So the strange thing is that inside the input field the 'disabled' attribute is added. When i remove the disabled value with developer tools i can click the button and the cart is updated correctly.

So i want to remove this attribute, what i have tried:

<script>
document.getElementById('update_cart_button').disabled = false;
</script>

<script>
jQuery('#update_cart_button').prop('disabled', false);
</script>
<script>
jQuery('#update_cart_button').removeAttr('disabled');
</script>


but none of the solutions remove the disabled attribute.

Answer

You can try below code-

jQuery(document).ready(function() {
jQuery( '.shop_table.cart' ).closest( 'form' ).find( 'input[name="update_cart"]' ).removeProp( 'disabled');
  });
Comments