Search
☛ Properly Loop the Global Cart when contains products from different shops - WP Global Cart
15795
documentation-template-default,single,single-documentation,postid-15795,theme-awake,eltd-core-1.1,woocommerce-no-js,awake child-child-ver-1.0.0,awake-ver-1.0,eltd-smooth-scroll,eltd-smooth-page-transitions,eltd-mimic-ajax,eltd-grid-1200,eltd-blog-installed,eltd-default-style,eltd-fade-push-text-top,eltd-header-standard,eltd-sticky-header-on-scroll-down-up,eltd-default-mobile-header,eltd-sticky-up-mobile-header,eltd-menu-item-first-level-bg-color,eltd-dropdown-slide-from-top,eltd-,eltd-fullscreen-search eltd-search-fade,eltd-side-menu-slide-from-right,wpb-js-composer js-comp-ver-6.3.0,vc_responsive
 

☛ Properly Loop the Global Cart when contains products from different shops

WP Global Cart / ☛ Properly Loop the Global Cart when contains products from different shops
Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInShare on TumblrPin on PinterestEmail this to someonePrint this page

☛ 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.

0
Would love your thoughts, please comment.x
()
x