Search
Update my custom theme cart to show correct product link - WP Global Cart
14234
documentation-template-default,single,single-documentation,postid-14234,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
 

Update my custom theme cart to show correct product link

WP 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() );
            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() );
            foreach ( $carts as $cart_item_key => $values ) : ?>
                <?php do_action( 'woocommerce/cart_loop/start', $values ); ?>
                <?php $_product = $values['data'];
                    if ( $_product->exists() && $values['quantity'] > 0 ): ?>

                    <div class="product">

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

                <?php endif; ?>
                <?php do_action( 'woocommerce/cart_loop/end', $values ); ?>
            <?php endforeach; ?>

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

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