Skip to content

Instantly share code, notes, and snippets.

@shahidbahader
Forked from plugin-republic/update-cart-item-ajax.js
Last active September 8, 2022 10:03
Show Gist options
  • Save shahidbahader/1a8101fa4f393a526a936e2deab5800b to your computer and use it in GitHub Desktop.
Save shahidbahader/1a8101fa4f393a526a936e2deab5800b to your computer and use it in GitHub Desktop.
(function($){
$(document).ready(function(){
$(document.body).on('change keyup paste', '.prefix-cart-notes', function(){
$('.cart_totals').block({
message: null,
overlayCSS: {
background: '#fff',
opacity: 0.6
}
});
var cart_id = $(this).data('cart-id');
$.ajax(
{
type: 'POST',
url: prefix_vars.ajaxurl,
data: {
action: 'prefix_update_cart_notes',
security: $('#woocommerce-cart-nonce').val(),
notes: $('#cart_notes_' + cart_id).val(),
cart_id: cart_id
},
success: function( response ) {
$('.cart_totals').unblock();
}
}
)
});
});
})(jQuery);
@shahidbahader
Copy link
Author

shahidbahader commented Sep 8, 2022

The event was not triggering after the update cart function was called, which means the custom text could not be updated if a customer has updated the cart. For that the event must be triggered on the document body. (Tested and Worked)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment