Skip to content

Instantly share code, notes, and snippets.

@oguzhanoptimum7
Created November 29, 2021 11:09
Show Gist options
  • Save oguzhanoptimum7/47ce034862a7f4cc0a87eba3122857c6 to your computer and use it in GitHub Desktop.
Save oguzhanoptimum7/47ce034862a7f4cc0a87eba3122857c6 to your computer and use it in GitHub Desktop.
Clear Cart Attr
$.ajax({
type: "GET",
url: '/cart.js',
dataType: 'json',
success: function(resp) {
var nullHash = {};
for ([key, value] of Object.entries(resp.attributes)) {
nullHash[key] = null;
}
$.ajax({
type: "POST",
url: '/cart/update.js',
data: {attributes:nullHash},
dataType: 'json'
});
}
});
Or if you want to delete them by name, you can do this:
var nullHash = {
'someAtt1': null,
'someAtt2': null,
'someAtt3': null
};
$.ajax({
type: "POST",
url: '/cart/update.js',
data: {attributes:nullHash},
dataType: 'json'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment