Sometimes when you use CPB in bundle mode you don't want the base CPB product to appear in cart.
It's pretty easy to solve following these few steps:
1) In the cart template (usually cart.liquid or cart-template.liquid file) we need to add an attribute to the products we want to get rid of. Find code similar to this:
{% for item in cart.items %}
<div class="cart__row">
and add if statement to have this:
{% for item in cart.items %}
<div class="cart__row" {% if item.product.type contains 'cpb_' and item.product.price == 0 %}data-cpb-null-product="{{item.key}}"{% endif%}>
2) In the bottom of the file add scripts:
<!-- script placed in cart template -->
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
;(function($) {
$('[data-cpb-null-product]').each(function() {
$.post('/cart/change.js', {
id: $(this).attr('data-cpb-null-product'),
quantity: 0
});
});
})(jQuery);
</script>
You don't need to add "<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>" if jquery is already turned on before in your theme (usually it is)
3) We need to hide the product from the cart before it was removed. For it add style to your theme (usually theme.css.liquid file)
[data-cpb-null-product] {
display: none;
}
Done! Now CPB products with zero price won't appear in cart.
Comments
0 comments
Please sign in to leave a comment.