title: Sync two product quantities at cart woocommerce
body: <p>I am trying to sync two product ids at the cart in woocommerce so that change in one bring change in the other quantity, I am trying this code but it updates all the products in the cart with master product ID, which I dont want.</p>
  <pre><code>add_action( 'template_redirect', 'bbloomer_sync_cart_quantities' );
      
  function bbloomer_sync_cart_quantities() {
      if ( WC()-&gt;cart-&gt;is_empty() ) return;
     $master_product_id = 20;
     $in_cart = false;
     foreach( WC()-&gt;cart-&gt;get_cart() as $cart_item_key =&gt; $cart_item ) {
        if ( $master_product_id === $cart_item['product_id'] ) {
           $qty = $cart_item['quantity'];
           $in_cart = true;
           break;
        }
     }
     if ( ! $in_cart ) return;
     foreach( WC()-&gt;cart-&gt;get_cart() as $cart_item_key =&gt; $cart_item ) {
        if ( $master_product_id !== $cart_item['product_id'] ) {
           WC()-&gt;cart-&gt;set_quantity( $cart_item_key, $qty );
        }
     }     
  }
  </code></pre>