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