Skip to content
function format(n){ return n.toFixed(2); }
function updateTotals(){
let total = 0;
rows.forEach(row=>{
const price = parseFloat(row.dataset.price) || 0;
const qtyEl = row.querySelector('input.qty');
const qty = Number(qtyEl.value) || 0;
const sub = price * qty;
row.querySelector('.subtotal').textContent = format(sub);
total += sub;
});
totalEl.textContent = format(total);
// Générer récapitulatif texte court
if(textarea){
let lines = [];
rows.forEach(row=>{
const name = row.querySelector('td').textContent.trim();
const qty = Number(row.querySelector('input.qty').value) || 0;
if(qty>0) lines.push(qty + ' x ' + name);
});
lines.push('Total: €' + format(total));
textarea.value = lines.join('\n');
}
}
rows.forEach(row=>{
row.querySelector('input.qty').addEventListener('input', updateTotals);
});
// initial
updateTotals();
// Juste avant l'envoi CF7 : s'assurer que le textarea contient le récap (some setups send via AJAX)
const form = document.querySelector('.wpcf7-form') || document.querySelector('form');
if(form){
form.addEventListener('submit', updateTotals);
}
});