How to sync two product stock quantities together with WooCommerce?

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

I’m using ACF to create product links :

enter image description here

I have a function that is called on save_post_product that looks something like this :

That function syncs the inventory in the linked ACF row perfectly because you can only update the stock of one product at a time.

However, when I try to call this with woocommerce_thankyou it breaks because it only updates the inventory once on the first item and doesn’t take in consideration the inventory management of the possible product B in the same cart.

How would I go about combining the cart items together and setting the correct stock afterwards?

Right now, if only one product from the row is in the cart, it works fine. If both products from the row are in the cart, the calculation only happens on the first product and it ignores the second product.

Thank you

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