Skip to content

Instantly share code, notes, and snippets.

@plugin-republic
Created February 19, 2019 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save plugin-republic/462975544b9c76c9fc8f503c8722334f to your computer and use it in GitHub Desktop.
Save plugin-republic/462975544b9c76c9fc8f503c8722334f to your computer and use it in GitHub Desktop.
(function($){
$(document).ready(function(){
$('.prefix-cart-notes').on('change keyup paste',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);
@yoske25
Copy link

yoske25 commented Apr 13, 2020

Where do we need to enter this code? Inside of functions.php ?

@plugin-republic
Copy link
Author

@yoske25
Copy link

yoske25 commented Apr 13, 2020

Please see https://pluginrepublic.com/how-to-add-an-input-field-to-woocommerce-cart-items/

Yeah I've read it. But not sure where to upload this js file since I upload it to the child theme, and nothing is changing

@tucson-az
Copy link

I have the same question as yoske25... I'm no coder, so I've just been poking around trying to get it to work without breaking anything. So far, nothing broken, but still not working. Would love to get there though...

@tucson-az
Copy link

OK, I think I found how to do it, and I'm getting partial results... the text stays in the text field after updating the page, but I'm not getting it to come through on the order form yet.

For yoske25 - I put the .js code provided between <script></script> tags, and then used "Header Footer Code Manager" to place that within the of the page I'm working on. Hope that helps.

@lyonsun
Copy link

lyonsun commented Apr 29, 2021

Hi, thanks for sharing this. I went through your article, and got it working, which is awesome.
But it seems it will result in a page reload when trying to update the notes after removing one or more items from the cart.
Do you have some time to take a look into this? Thanks again.

@shahidbahader
Copy link

This event is not firing after we hit the update cart. when the cart page is loaded initially, everything works fine, but when we change the quantity of the item and hit the Update Cart button, the cart is updated. after that, the text changes are not saved.

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