I’ve gotta say WooCommerce is a pretty nice platform for setting up a web store within WordPress. We’ve worked with several eCommerce solutions over the years, but keep gravitating back to WooCommerce. Sure, its got its quirks like everyone else, but at the end of the day you can usually get the job done.

The job this month was an in-house project, Direct Mailing Company, who operates in the business mailing list space. This site has presented some interesting challenges dealing with massive contact databases and trying to find the best way to slice and dice the data so clients can easily search through these catalogs and cherry pick the set of contacts that best fits their needs. The layout and development work is a whole separate topic, but today I want to look at an issue we ran into when implementing WooCommerce.

How Direct Mailing Company is setup, we didn’t want to have customers landing on product description pages. The information packaged within those pages was largely redundant since it is presented in a much better fashion on the individual profession pages via a nice grid format with cooresponding contact counts. So our challenge was to ensure none of those default links to the WooCommerce store showed up throughout the website. Easy task, right? Well easy if you know where to look.

Upon researching this topic, we ran across this great detailed article by Chris Lema, but the only problem is that since he wrote it in 2012, WooCommerce has switched up where everything is located as well as some of the layout. We used Chris’ inspiration to trek out to find the new files.

There are two files you are looking for — mini-cart.php & cart.php. Both are located in the folder /wp-content/plugins/woocommerce/templates/cart which sits off the main directory of your WordPress install. As always, I recommend backing up both of these files before you make any changes to them. This can be as simple as copy & pasting them over to a text file to serve as a safety net while you work.

So let’s look at what each of these files do and where this link over to the product page is entering into the equation. mini_cart.php displays the sidebar widget that shows up once you’ve added an item to your cart and you tell WooCommerce that you’d like to continue shopping. If we hover over our cart item, we’ll see that it links over to the product page as does the square icon to its right.

If we crack open the mini_cart.php file, we’ll see this line about midway down the php code:

apply_filters( 'woocommerce_cart_item_name', sprintf( '<a href="%s">%s</a>', $_product->get_permalink(), $_product->get_title() ), $cart_item, $cart_item_key );

We are going to make a quick revision so that permalink gets dropped and the title of the product simply gets printed out instead:

apply_filters( 'woocommerce_cart_item_name', sprintf( '%s', $_product->get_title() ), $cart_item, $cart_item_key );

Without that link, there is no way for your user to get back to the product page from the sidebar widget. Now we need to do the same thing with the cart itself. The cart, of course, houses all of your selections until you tell it you are ready to advance to checkout. If we open up cart.php, look for the same apply_filters line we referenced above and make the same replace. Save each one of those files out, and you’ve short circuited WooCommerce’s most valiant efforts to send your customer’s to a product page. Painfully easy right? Well easy, if you know which files to tweak in WooCommerce confusing file structure.

Hopefully, that solves your issue of pesky product pages and you are on to tackle much more important problems like where to eat lunch.