javascript - Woocommerce 2.6.2 adds disabled attribute to update cart button - Stack Overflow

I am using Wordpress 4.5.3 and Woomerce 2.6.2 .Code inside woomercecartcart.php<input type="s

I am using Wordpress 4.5.3 and Woomerce 2.6.2 .

Code inside woomerce/cart/cart.php

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

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

    <?php wp_nonce_field( 'woomerce-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:

Attempt 1

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

Attempt 2

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

Attempt 3

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

but none of the solutions remove the disabled attribute.

I am using Wordpress 4.5.3 and Woomerce 2.6.2 .

Code inside woomerce/cart/cart.php

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

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

    <?php wp_nonce_field( 'woomerce-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:

Attempt 1

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

Attempt 2

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

Attempt 3

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

but none of the solutions remove the disabled attribute.

Share Improve this question edited Jan 23, 2017 at 19:07 Christophvh asked Jul 19, 2016 at 9:23 ChristophvhChristophvh 13.3k7 gold badges51 silver badges73 bronze badges 2
  • do you try jQuery('#update_cart_button').removeAttr('disabled'); ? – Danil Pyatnitsev Commented Jul 19, 2016 at 9:25
  • @DanilPyatnitsev yes, that also doesn't remove it – Christophvh Commented Jul 19, 2016 at 9:48
Add a ment  | 

5 Answers 5

Reset to default 2

I've had the same issue. I think my way to solve it is not the best but it should work for the time we wait for the patch so you may want to hear it.

Go into

wp-content/plugins/woomerce/assets/js/frontend/cart.min.js

Its a bit confusing but you can search for

.prop("disabled",!0)},input_changed

Change the !0 into a !1

Save and upload the file after this the button should work fine again. there is one Problem the function which is enable the button after a change, has been taken out the button is now always enabled. Its like i said a temporarily solution after the patch there should be no need for further edits.

Greets Lukas

You can try below code-

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

If you want to enable the button after the quantity of products is changed you can do something like this:

$(document).on("click",".woomerce-cart .control-prod", function (e) {
    $( ".woomerce-cart .control-prod" ).click(function() {
        $('input[name="update_cart"]' ).removeProp( 'disabled');
    });
});

where the element .control-prod is where you change the number of products. You can also use change insted of click.

This code works for me :

jQuery(window).on('load', function() {
 jQuery( '.shop_table.cart' ).find( 'input[name="update_cart"]' ).prop("disabled", false);
});

Perfect solution by Wallace! But actually it had a flaw that it removed the 'disabled' property only after two clicks. I have updated the code so this will work eveytime you click + or -

Add this to header.php between head tags:

<script>
    $(document).on("click",".bw-quantity", function (e) {
        $('input[name="update_cart"]' ).removeProp( 'disabled');
    });
</script>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744962122a4603451.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信