Сервисный сбор в корзине Тильды

Создай товары и корзину
Скопируй код и вставь его в блок T123
В коде поменяй строку с процентом на нужный тебе процент
1
2
3
<script>

    function updateTotalPrice() {
        const totalPriceElem = document.querySelector('.t706__cartwin-totalamount .t706__cartwin-prodamount-price');
        const productItems = document.querySelectorAll('.t706__product');

        if (totalPriceElem && productItems.length > 0) {
            let total = 0;

            
            productItems.forEach(item => {
                const totalAmountElem = item.querySelector('.t706__cartwin-prodamount-price'); 
                
                if (totalAmountElem) {
                    const totalAmount = parseFloat(totalAmountElem.textContent.replace(/\s+/g, '').replace(',', '.')); 
                    total += totalAmount; 
                }
            });

            // Увеличиваем итоговую сумму на 10%
            const updatedPrice = total * 1.10; // Добавляем 10%
            totalPriceElem.textContent = Math.round(updatedPrice); // Округляем результат до ближайшего целого
        }
    }

  
    const observer = new MutationObserver((mutationsList) => {
        for (const mutation of mutationsList) {
            if (mutation.type === 'childList' || mutation.type === 'subtree') {
                updateTotalPrice(); 
            }
        }
    });

    
    const cartElement = document.querySelector('.t706__cartwin-products');
    if (cartElement) {
        observer.observe(cartElement, { childList: true, subtree: true });
    }

    
    updateTotalPrice();

</script>
Made on
Tilda