Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi! Any help is appreciated. Here is my issue:
Some of my variants have a $0 price tag because it's not a variant I stock (quantity is also set to 0 and the "sold out" verbiage I changed to "not available"), but it's stocked for some other variants. Example: 1" mirror is not available and price is $0 and quantity is 0. A 2.25" mirror is available though. Variant Options are size and style, but not every size and style is something I make. So on my collection pages, the $0 price tag displays since it's the "lowest" but I don't like that. So hiding anything anywhere that says $0 would be great. My shop link is rebel-buttons.myshopify.com If you scroll all the way down, you'll see a collection that will display $0 for the buttons. If you click on a product and choose 1" mirror, you will see how it says "Not Available" but also displays $0. I would love to hide or not display this $0.
Thank you so much!
Hey,
1. In your Shopify Admin go to online store > themes > actions > edit code
2. In your theme.liquid file, find the </body> (press CTRL + F or command + F on Mac)
3. paste this code right above the </body> tag:
<script>
function hidePrices(){
var prices = document.querySelectorAll(`.price-item--regular`);
if (!prices){
return;
}
for (var each of prices){
var price = each.textContent.trim();
if (price === '$0.00'){
each.closest('.price').remove();
}
}
}
hidePrices();
</script>
Result:
Please keep in mind that this would not work on multiple currencies, it would require a bit more of a complex script.
Kind regards,
Diego
Thank you so much for your help Diego! I tried this out, but it also is now hiding ALL of my prices and even on the product pages too. I would only like anything with a $0.00 to be hidden, but everything else can show. Thanks again!
@rebelbuttons
It's hiding exclusively anything with $0.00. This product, for example, is showing the price up.
Do you want to hide the price exclusively at the home page?
The ornaments don't have anything with $0, so they are not part of my problem. When I apply your code, ALL prices are hidden for any product that has a variant that is a $0. I would just like those $0 variants hidden, but the other prices shown if that makes sense. I'm attaching a screenshot - it should be showing a $1 price for the options selected on this product page, but the price is hidden.
Oh, I see.
In this case yes, this Javascript script I sent you wouldn't work, a .Liquid solution would be much easier and simpler to achieve what you need.
I'd need to be within your store's theme though, I couldn't guide you through.
Unfortunately my time to the community is a bit limited because of my work, but someone around here will surely be kind enough to help you out!
Kind regards,
Diego
Thank you so much for you time and help you dedicated to my problem! I really appreciate it! I will keep trying to figure out a way to fix it. Thanks again!
Hey did you end up finding a solution to this?
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024