Hello I am calculating price on the basis of total amount. I want to add after discount price as my sell price for product. so when i click on the add to cart button it should show the after discount price.
Here’s my html sturucture that i have created accoding to my requirenment:
<div class="woocommerce-variation-price">
<span class="price-incvat" style="text-decoration:line-through;">
<span class="woocommerce-Price-amount amount">
<bdi>
<span class="woocommerce-Price-currencySymbol">£</span>
531.36
</bdi>
</span>
Inc. VAT
</span><br>
<span class="price2" style="text-decoration:line-through;">
<span class="woocommerce-Price-amount amount">
<bdi>
<span class="woocommerce-Price-currencySymbol">£</span>
442.80
</bdi>
</span>
Exc. VAT
</span><br>
<span class="price-incvat newprice">
<span class="woocommerce-Price-amount amount">
<bdi>
<span class="woocommerce-Price-currencySymbol">£</span>
478.22
</bdi>
</span>
Inc. VAT
</span><br>
<span class="price2 newprice">
<span class="woocommerce-Price-amount amount">
<bdi>
<span class="woocommerce-Price-currencySymbol">£</span>
398.52
</bdi>
</span>
Exc. VAT
</span>
</div>
Here’s defalut html sturucture of Woocommerce
<div class="yith_wapo_group_total
" data-product-price="442.8" data-product-id="205692">
<table>
<tbody><tr class="ywapo_tr_product_base_price">
<td data-nosnippet="">Product price</td>
<td data-nosnippet=""><div class="yith_wapo_group_product_price_total"><span class="price amount">£442.80</span></div></td>
</tr>
<tr class="ywapo_tr_additional_options">
<td data-nosnippet="">Additional options total:</td>
<td data-nosnippet=""><div class="yith_wapo_group_option_total"><span class="price amount">£0.00</span></div></td>
</tr>
<tr class="ywapo_tr_order_totals">
<td data-nosnippet="">Order total:</td>
<td data-nosnippet=""><div class="yith_wapo_group_final_total"><span class="price amount">£442.80</span></div></td>
</tr>
</tbody></table>
</div>
And here’s my Jquery code to calculate dicosunt price:
jQuery(function ($) {
$('.yith_wapo_group_final_total .price.amount').on("DOMSubtreeModified", function () {
var price_ele = jQuery(".woocommerce-variation.single_variation .woocommerce-variation-price");
var price_ele_simp = jQuery(".new-price-simple");
var add_price1 = jQuery(".yith_wapo_group_final_total .price.amount").text().replace(/£/g, "");
var add_price = add_price1.replace(/,/g, "");
var inc = (add_price * 20) / 100;
var inc_price = parseFloat(add_price) + parseFloat(inc);
if(bundleproduct != '')
{
var bundleExcVatFinalPrice = parseFloat(add_price) - (add_price * bundleproduct);
var bundleIncVatFinalPrice = parseFloat(bundleExcVatFinalPrice) + (bundleExcVatFinalPrice * 0.20);
if (add_price1 != 0 && price_ele.text() != "")
{
price_ele.html('<span class="price-incvat" style="text-decoration:line-through;"><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>' + numberWithCommas(inc_price.toFixed(2)) + '</bdi></span> Inc. VAT</span></span><br><span class="price2" style="text-decoration:line-through;"><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>' + numberWithCommas(add_price) + '</bdi></span> Exc. VAT</span><br><span class="price-incvat"><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>' + numberWithCommas(bundleIncVatFinalPrice.toFixed(2)) + '</bdi></span> Inc. VAT</span></span><br><span class="price2"><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>' + numberWithCommas(bundleExcVatFinalPrice.toFixed(2)) + '</bdi></span> Exc. VAT</span>');
}
else if (price_ele.text() == "")
{
price_ele.html('<span class="price-incvat" style="text-decoration:line-through;"><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>' + numberWithCommas(inc_price.toFixed(2)) + '</bdi></span> Inc. VAT</span></span><br><span class="price2" style="text-decoration:line-through;"><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>' + numberWithCommas(add_price) + '</bdi></span> Exc. VAT</span><br><span class="price-incvat"><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>' + numberWithCommas(bundleIncVatFinalPrice.toFixed(2)) + '</bdi></span> Inc. VAT</span></span><br><span class="price2"><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>' + numberWithCommas(bundleExcVatFinalPrice.toFixed(2)) + '</bdi></span> Exc. VAT</span>');
}
}
}, 350);
});
});
Now What i want is.. when i click on add-to-cart button it should take span with class “price2 newprice” that is “398.52” in according to html given above.
Attched images for better understanding:
Before adding to cart
After clickeing basket button (It should show “398.52” price here
Thank You
I have tried this in above jquery i have prodvide:
$('.yith_wapo_group_total').attr('data-product-price', bundleExcVatFinalPrice);
$('.yith_wapo_group_final_total .price amount').attr('data-product-price', bundleExcVatFinalPrice);
But it’s not working. What i want is.. when i click on add-to-cart button it should take span with class “price2 newprice” that is “398.52” in according to html given above.
Sabir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.