Last active
May 10, 2024 14:49
-
-
Save unlocomqx/7e5306c65add454f28ef1ad16dc64230 to your computer and use it in GitHub Desktop.
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
// 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