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

By default, when a product is added to the shopping cart, the links within the cart should reflect the origin shop. This means that if you added a specific product from Shop A to your cart, the links in the cart should lead back to Shop A.

However, there might be a situation where the links in the cart are not reflecting the correct origin shop. Instead, they might be pulling data from a different shop within the network. Thankfully, resolving this issue is straightforward and requires a small update to the code. The solution will be explained in the following lines, providing you with the necessary instructions to ensure that the links in the cart accurately reflect the origin shop where the product was added.

First locate the theme ( child-theme ) cart template which should be located at /woocommerce/cart/cart.php. If there is no such file, copy over from /wp-plugins/woocommerce/templates/cart/cart.php

Many themes use something like this to output the cart:

            foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
                $_product   = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
                $product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );

                
                ... more code ...
                
            }

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

              foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
                do_action( 'woocommerce/cart_loop/start', $cart_item );
                $_product   = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
                $product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );

                
                ... more code ...
                
                do_action( 'woocommerce/cart_loop/end', $cart_item );
            }

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