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.