You know it’s the little things in life that highlight our great successes. I have been looking for this for literally hours.. What I wanted to do was edit the number of product columns that are shown in the default grid view homepage. It’s set to 4 and I wanted 3. Not hard right? Sadly it was but the solution was a two liner! Let me explain…
Woocommerce, by default, doesn’t work from a shortcode (it can do but not by default), instead it will show the shop page content using it’s own template system. It will look for arguments/parameters attached to the shortcode in order to augment the number of columns on any product listing page. I know I know, I just said that we aren’t using a shortcode but it’s looking for one anyway? Almost.. here is the solution:
global $woocommerce_loop; $woocommerce_loop['columns'] = 3;
There we have it, two lines. Either a sign of my genius or incompetence. I suspect the latter but for the moment I am fairly proud of this achievement. Essentially $woocommerce_loop contains the settings for the product page and by default the columns argument isn’t set leaving it up to the shortcode to populate (if used) or to fall back to it’s standard setting.. 4!
So after hours of trawling through code trying to find a WordPress Filter I can hook onto, I thought I would try this little gem (added to my theme functions.php) and magically it worked. This post can now hopefully help the next person to have to deal with this or indeed for someone to point out my stupidity and show me how it should have been done.