a
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudanti.
a
Follow Me
Search
Update my custom theme cart to show correct product link - WooCommerce MultiSite Global Cart
14234
documentation-template-default,single,single-documentation,postid-14234,eltd-core-1.1,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-5.0.1,vc_responsive
 

Update my custom theme cart to show correct product link

WooCommerce MultiSite Global Cart / Update my custom theme cart to show correct product link
Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInShare on TumblrPin on PinterestEmail this to someonePrint this page

Update my custom theme cart to show correct product link

As default the links within cart should reflect the original shop where they pushed to the cart. In some cases a custom theme is not using the recommended WooCommerce template implementation which conclude to wrong url. Fortunate this is a small update, explained in the following lines.

Many themes use something like this to output the cart:

            global $woocommerce;
            $carts = array_reverse( $woocommerce->cart->get_cart() );
            <?php foreach ( $carts as $cart_item_key => $values ) : ?>

                <?php $_product = $values['data'];
                    if ( $_product->exists() && $values['quantity'] > 0 ): ?>

                    <div class="product">

                        ... more code ...
                    </div>
                    <!--/product -->

                <?php endif; ?>
            <?php endforeach; ?>

This need a bit of update to include the switch_to_blog() and restore_current_blog() so add the 2 new lines:

            global $woocommerce;
            $carts = array_reverse( $woocommerce->cart->get_cart() );
            <?php foreach ( $carts as $cart_item_key => $values ) : ?>
                <?php switch_to_blog($values['blog_id']); ?>
                <?php $_product = $values['data'];
                    if ( $_product->exists() && $values['quantity'] > 0 ): ?>

                    <div class="product">

                        ... more code ...
                    </div>
                    <!--/product -->

                <?php endif; ?>
                <?php restore_current_blog() ?>
            <?php endforeach; ?>

At this point the products within the cart, pushed on other shops will use the correct links back to original shop.