Last active
November 11, 2024 20:47
-
-
Save chrisjhoughton/893f536698e2c27cb7f5 to your computer and use it in GitHub Desktop.
Remove a Shopify cart attribute
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% if cart.attributes.yourCartAttribute %} | |
<script> | |
$.ajax({ | |
type: 'POST', | |
url: '/cart/update.js', | |
data: 'attributes[yourCartAttribute]=', | |
dataType: 'json' | |
}); | |
</script> | |
{% endif %} |
Provide null
as the value wherever you normally send the request (e.g. XHR, fetch, et al), and Shopify will remove the key from its attributes hash.
In the original example, you probably want to remove the dataType
param, since json
isn't a valid MIME type and the payload isn't JSON (obj[key]=value
is form urlencoded).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alternatively (and equally undocumented!), you could use the Shopify API directly.