Shopify themes, liquid, logos, and UX
I am wondering if anyone can supply me a code to post so that when i click on my variant i have selected the page reloads.
Thanks!
Solved! Go to the solution
For Dawn based themes you can either listen on the html custom elements like <variant-radios>|<variant-selects> , or the source input typically 'input[name="id"]' in product forms that is made to dispatch a change event after variant functions run.
https://github.com/Shopify/dawn/blob/main/assets/global.js#L813
Below is a basic starting example with a parameter to pass in a callback function to trigger when the variant event happens.
function variant_change_listener(callback){
const selector = 'input[name="id"]';
const emitting_element = document.querySelector(selector);
emitting_element.addEventListener('change', function(){
callback ? callback() : console.log("variant changed, but no callback function");
});
}
// either call listening function directly in flow of document or set it to run after document ready
variant_change_listener();
Contact paull.newton+shopifyforum@gmail.com for the solutions you need
Save time & money ,Ask Questions The Smart Way
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Thank Paul with a ☕ Coffee for more answers or donate to eff.org
This worked perfectly for me, thank you!
This is PageFly - Free Landing Page Builder.
You can try this code, but should change the query selector to match with your structures.
Step1: Online store > Themes > Edit code > search for your theme.liquid
Step2: Paste the code to above </head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
jQuery(function() {
$('.single-option-selector').on('change', function(){
setTimeout(function(){
if($('[name="id"]').val() != "{{ product.selected_or_first_available_variant.id }}"){
location.reload();
}
}, 1);
});
});
</script>
Hope this can help you solve the issue
Best regards,
PageFly
Not function this in Dawn theme
Not function this in Dawn theme
Thanks heaps for this.. Helped me heaps.. I was using some script logic that would refresh even when opening an image.
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025