I would like to alter this code so there is another tickbox for if a product is ‘out of stock’. So if the box is checked, it shows out of stock products. If unchecked, it hides them. How do I do this?
<script>
$(function() {
var status = localStorage.getItem('chkStatus');
if(status == 'true'){
$("span.price").css("display", "none");
$("p.price").css("display", "none");
$(".tradePriceToggle").attr('checked', true)
}
else{
$("span.price").css("display", "block");
$("p.price").css("display", "block");
$(".tradePriceToggle").attr('checked', false)
}
$(".tradePriceToggle").click(function() {
if (this.checked) {
$("span.price").hide();
$("p.price").hide();
}
else {
$("span.price").show();
$("p.price").show();
}
localStorage.setItem("chkStatus", this.checked);
});
});
</script>
Below is similar to what I’m trying to achieve:
.available-on-backorder:has(.product_card) {
display:none;
}
But this CSS only applies when the box is ticked.
2
Answers
The code needed for this was:
The code searches for the out-of-stock elements on the page, traces the parent 'box' elements and hides all elements on page corresponding with the rule. Then uses the tick box so that the status stays the seem on page refresh/move until unticked.
in database mark product as OUT of stock OR available.
$(function() {
});