Skip to content

Instantly share code, notes, and snippets.

@unlocomqx
Last active May 10, 2024 14:49
Show Gist options
  • Save unlocomqx/7e5306c65add454f28ef1ad16dc64230 to your computer and use it in GitHub Desktop.
Save unlocomqx/7e5306c65add454f28ef1ad16dc64230 to your computer and use it in GitHub Desktop.
// To be placed in /themes/[current theme]/assets/js/dynamic/custom.js (create the "dynamic" folder)
window.dp_hook = '[data-widget_type="product-variants.default"]'
window.dp_price_hook = ".ce-product-price span"
$(document).on("dp-loaded", function () {
const addToCart = ceFrontend.utils.urlActions.actions.addToCart;
ceFrontend.utils.urlActions.actions.addToCart = function (e) {
window.dpSaveCustomization(true).then(function (response) {
if (response) {
addToCart.apply(null, e)
}
})
}
const qty = document.querySelector("[data-elementor-type=product] [name=qty]")
// detect enter key
qty.addEventListener("keypress", function (e) {
if (e.keyCode === 13) {
e.preventDefault()
window.dpSaveCustomization(true).then(function (response) {
if (response) {
addToCart.apply(null, e)
}
})
return false
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment