Shopify themes, liquid, logos, and UX
Sorry you are facing this issue, it would be my pleasure to help you.
Welcome to the Shopify community!😊
Thanks for your good question.
Please share your site URL,
I will check out the issue and provide you a solution here.
Hi @Moise75,
This is Victor from PageFly - Landing Page Builder App
You can try this code by following these steps:
Go to Online Store->Theme->Edit code theme.liquid paste my code before </body> element
<script>
window.onload=()=>{
const changeColor=()=>{
const variant=document.querySelectorAll('fieldset')
variant.forEach(v=>{
const infor=v.closest('.product__info-wrapper');
const title=infor.querySelector('.product__title h1')
const inputs=v.querySelectorAll('input[name="Color"]')
if(inputs.length>0){
inputs.forEach(input=>{
if(input.checked){
const value=input.value;
const checkLenght=value.indexOf(' ');
if(checkLenght<0){
title.style.color=`${value}`
}else{
const newColor=value.slice(checkLenght+1);
title.style.color=`${newColor}`
}
}
})
}
})
}
changeColor();
document.querySelectorAll('fieldset input[name="Color"]').forEach(item=>{
item.onclick=()=>changeColor()
})
}
</script>
Hope my solution works perfectly for you!
Regards,
Victor | PageFly
how can I change the title then? Will that work for only this product?
this only change the color I don't want the color to be change I want the title to change is it's black t-shirt change it to black T-shirt instead of Green
You can try again with this code:
<script>
window.onload=()=>{
const changeColor=()=>{
const variant=document.querySelectorAll('fieldset')
variant.forEach(v=>{
const infor=v.closest('.product__info-wrapper');
const title=infor.querySelector('.product__title h1')
const inputs=v.querySelectorAll('input[name="Color"]')
if(inputs.length>0){
inputs.forEach(input=>{
if(input.checked){
const value=input.value;
const content=title.innerText
title.innerText=content.slice(0,content.indexOf('-')-1) + value
}
})
}
})
}
changeColor();
document.querySelectorAll('fieldset input[name="Color"]').forEach(item=>{
item.onclick=()=>changeColor()
})
}
</script>
Hope my solution works perfectly for you!
Regards,
Victor | PageFly
We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024The Hydrogen Visual Editor is now available to merchants in Shopify Editions | Summer '...
By JasonH Sep 2, 2024