This snippet will help you synchronize all your cart items’ quantities with a given product ID quantity. When you add a second product to cart, therefore, it will get the same quantity of your product ID. Also, if you update the quantity of product ID, the other cart item quantities will automatically update accordingly.
Applications are quite niche, but it’s great to learn how to programmatically set the quantity of a cart item. As usual, each snippet of this website has got something that sooner or later you may need to use. Enjoy!
Based on the snippet example below, whenever I change the quantity of product ID = 20 (called 2 Simple), all the other products’ quantity will be synced.
PHP Snippet: Synchronize Product ID Quantity And Other Item Quantities @ WooCommerce Cart
Note: you have to specify your “master_product_id” inside the snippet. This is the reference product. All the other products in the cart will sync with its quantity.