WP Global Cart >
☛ Properly Loop the Global Cart when contains products from different shops
☛ 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.
Related Posts
Managing multiple WooCommerce shops within a WordPress Multisite environment can be challenging, especially when it comes to keeping product information consistent across all stores. The WooCommerce Product Synchronization feature in the WP Global Cart plugin addresses this challenge by enabling seamless synchronization of products across your network.
Name: woogc/sequential_order_number/format
Type: Filter
Arguments: (int) $order_number,...
Name: woogc/global_cart/sites
Type: Filter
Arguments: (array) $sites_ids
The...
Name: woogc/single_checkout/split_order/order_created
Type: Action
Arguments: $new_order
The `woogc/single_checkout/split_order/order_created` action...
The WordPress WooCommerce Global...
By default, on Product...
Name: woogc/ps/synchronize_product/child_product
Type: Filter
Arguments:
(object)$child_product
(array)$main_product_data
(int)$origin_product_blog_ID
This filter...
The WooCommerce Global Cart...
Name: woogc/ps/interfaces/sync_to_shop
Type: Filter
Arguments: $status, $remote_blog_id, $post
The...