☛ Properly Loop the Global Cart when contains products from different shops
Looping through the Cart Items is straightforward and achievable through the code:
$cart_items = WC()->cart->get_cart(); foreach ( $cart_items as $cart_key => $item ) { //custom code }
When the cart includes products from different shops ( within the MultiSite Network ), the same code can be used. Still, a switch to the product shop is required, for the inner code to be able to correctly retrieve the data. The easiest approach will be to add 2 actions as the example:
$cart_items = WC()->cart->get_cart(); foreach ( $cart_items as $cart_key => $item ) { do_action( 'woocommerce/cart_loop/start', $item ); //custom code do_action( 'woocommerce/cart_loop/end', $item ); }
The above hooks are the easiest approach to make a fix for 3rd codes that are not MultiSite capable and fail to process the cart contents. That ensures they fetch the products from the correct shop, instead of the current site.