Adding discount functionality to the cart

Đã có trọn bộ đề thi thử THPT Quốc Gia 2022 các môn: vip.dethihsg247.com

Hey guys 🙂 I’m trying to implement a custom discount rule to the cart. Basically there is WooCommerce and the site is selling t-shirts. There is a current promotion that if you buy 3 t-shirts, you have to pay only for 2 and the one with the lowest price you get for free. I created a custom function using the hook ‘woocommerce_cart_calculate_fees’ and so far it’s working.
Here is my code:

Here is a screenshot of the cart page –> https://pasteboard.co/JkES3RD.png
The discount is displayed and applied.
The tricky part I can’t get to is, how to make the price of the discounted product striked and display price 0.00 in the table and how to edit the function so in the mini cart still displays 3 products, but to show the discounted price of 2 products? Thanks so much in advance! 🙂

EDIT: Also, it appears that it only works if I have 3 different products in the cart. If I have 1 product with quantity 2 and 1 product with quantity 1 it’s not working.. How to tweak the function to make it work?

Xin chào các bạn và quý Thầy Cô. Hãy nhập từ khóa mình muốn vào ô tìm kiếm trên Website để tìm kiếm mọi thứ hoặc trên google các bạn hãy nhập từ khóa + dethihsg247.com để tìm kiếm các bài viết của chúng tôi nhé.
  • Hiện tại chúng tôi có hơn 25 nghìn bài văn mẫu các thể loại.
  • Kho tài liệu, đề thi học sinh giỏi các lớp vô cùng phong phú.
  • Mỗi ngày cập nhật hơn 100 đề thi chất lượng từ các website bán tài liệu lớn.

Tải đề thi VIP với giá siêu rẻ tại Vip.Dethihsg247.Com