You can sync product quantities in the WooCommerce cart by designating one “master” product and automatically matching every other cart item’s quantity to it whenever the master product’s quantity changes.
Why Synchronize Cart Item Quantities
- Useful for bundle-style products sold as separate line items that must always match in quantity
- Keeps kits or matched sets consistent without forcing customers to manually update every item
- A niche but genuinely useful technique for programmatically setting cart quantities
- Runs automatically on every page load once a master product is present
Step 1: Sync All Cart Items to a Master Product’s Quantity
/** Keep every cart item's quantity in sync with one master product's quantity */
add_action( 'template_redirect', 'sync_cart_quantities_to_master_product' );
function sync_cart_quantities_to_master_product() {
if ( WC()->cart->is_empty() ) {
return;
}
$master_product_id = 45;
$master_quantity = null;
foreach ( WC()->cart->get_cart() as $cart_item ) {
if ( $master_product_id === $cart_item['product_id'] ) {
$master_quantity = $cart_item['quantity'];
break;
}
}
if ( null === $master_quantity ) {
return;
}
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
if ( $master_product_id !== $cart_item['product_id'] ) {
WC()->cart->set_quantity( $cart_item_key, $master_quantity );
}
}
}

Troubleshooting
Quantities don’t sync until the page is manually refreshed
This snippet runs on template_redirect, which fires on page load, not on Ajax quantity updates — for a live sync without a refresh, you’d need to hook into WooCommerce’s Ajax cart update process as well.
A customer’s separately intended quantity gets overwritten unexpectedly
Since every non-master item is forced to match, this only works correctly when all non-master products are genuinely meant to move in lockstep — don’t apply it to a cart with unrelated products mixed in.
Frequently Asked Questions
Can I sync quantities without designating a single master product?
Not with this simple approach — the logic needs one reference point to sync everything else against. A more complex version could average or use the highest quantity instead.
Does this work with variations?
Yes, since WC()->cart->get_cart() includes variation line items the same way it includes simple products — just confirm the master product ID matches correctly if it’s a variation.
Will this affect stock validation?
Yes, since quantities are set programmatically, make sure every synced product actually has enough stock to cover the master product’s quantity, or checkout may fail stock validation.
Conclusion
A short loop is enough to sync product quantities in the WooCommerce cart against one master product, which is handy for bundle-style products sold as separate line items. Keep in mind it only re-syncs on page load by default, so pair it with an Ajax-aware version if you need instant syncing without a refresh.
See also How to Check if a Product ID Is in the WooCommerce Cart. Then read How to Automatically Update the WooCommerce Cart on Quantity Change.
Prefer no code? All-in-One Utilities Woo Add-on adds over 50 WooCommerce features, so you can switch them on without code.