Frequently asked questions Custom Code

How do I set the number of products to a multiple of 5, 10, 100, etc.?

How do I set the number of products to a multiple of 5, 10, 100, etc.?

Examples below require knowledge of Javascript and CSS. Tilda Customer Support does not assist in code-related questions.

To change the behavior of the “plus” and “minus” buttons in the shopping cart, you need to add a T123 block from the “Other’ category and insert the following code:

<script>
var newMultipleNumber = 100; /* вместо 100 укажите нужное вам число */

function tcart__product__plus(t) {
var r = t.closest(".t706__product"),
o = r.attr("data-cart-product-i");
window.tcart.products[o].quantity += (window.tcart.products[o].quantity % newMultipleNumber > 0 ? newMultipleNumber - window.tcart.products[o].quantity : newMultipleNumber);
window.tcart.products[o].amount = window.tcart.products[o].price * window.tcart.products[o].quantity;
window.tcart.products[o].amount = tcart__roundPrice(window.tcart.products[o].amount);
r.find(".t706__product-quantity").html(window.tcart.products[o].quantity);
0 < window.tcart.products[o].amount ? r.find(".t706__product-amount").html(tcart__showPrice(window.tcart.products[o].amount)) : r.find(".t706__product-amount").html("");
tcart__updateTotalProductsinCartObj();
$(".t706__carticon-counter").html(window.tcart.total);
tcart__reDrawTotal();
tcart__saveLocalObj();
}

function tcart__product__minus(t) {
var r = t.closest(".t706__product"),
o = r.attr("data-cart-product-i");
0 < window.tcart.products[o].quantity && (window.tcart.products[o].quantity -= newMultipleNumber);
window.tcart.products[o].amount = window.tcart.products[o].price * window.tcart.products[o].quantity;
window.tcart.products[o].amount = tcart__roundPrice(window.tcart.products[o].amount);
r.find(".t706__product-quantity").html(window.tcart.products[o].quantity);
0 < window.tcart.products[o].amount ? r.find(".t706__product-amount").html(tcart__showPrice(window.tcart.products[o].amount)) : tcart__product__del(t);
tcart__updateTotalProductsinCartObj();
$(".t706__carticon-counter").html(window.tcart.total);
tcart__reDrawTotal();
tcart__saveLocalObj();
}

</script>

<style>
.t706__product-plusminus {
width: unset !important;
}
</style>

Replace the value “100” of the variable “newMultipleNumber” with the number you need.

The block containing the code should be added to the very bottom of the page, or placed to the Footer.

Was this answer helpful?
Yes
0
No
0
Views: 17289