Some people asked me this question on Twitter and I always pointed them to the support forums we’ve got. When this question got asked for the 10th time this week, I figured I had to check if this was actually any different in WooCommerce 2.1 now. Turns out, it’s not. It still works the same as it did in previous versions.
Hi! In new WooCommerce 2.1.2, how can I change the number of shop columns? All fixes that I can find on Google are not working in this release.
Well, here we go. Let’s debunk this myth that it’s no longer working by showing some examples.
The filter is and always was
This filter never changed. In the WooCommerce templates, this filter is used to determine the number of columns on all pages that contain products; shop archive, categories etc. Let’s look at what the WooCommerce documentation says about this filter; “Change number of products per row“:
Defines where ‘first’ and ‘last’ classes are applied in product archives.
In other words, this number that we can filter actually determines on which elements the classes
last are applied. This made me think about possible causes this can break, but more on that later.
Using the filter, let’s change the number!
This filter gets a static number as parameter that we can change. So we have to write a really simple function that returns the new number that we want:
Yes, that is all. This works. Let’s verify this by looking into the source of the shop page of my testing site (and the number of columns actually changed too):
What can go wrong?
Now, I’m glad you asked. There are a couple things that can go wrong here.
#1 Your theme doesn’t use the filter
The filter gets called from the template files. A lot of themes out there bundle all the WooCommerce templates files (they shouldn’t, but do it anyway) and might remove filters like this, for whatever reason. Please check the source of your theme files to see if it overrides any WooCommerce template files (to be found in the
/woocommerce/ folder in your theme). If it does, make sure the loop_shop_columns filter is still used.
#2 Your theme doesn’t style the classes properly
Even if this filter gets called and it inserts the classes by using it, it doesn’t mean it styles the classes properly. If your theme removes all of the default WooCommerce stylesheets, it has to add styling for these classes as well. Make sure your theme adds styling to the
last classes, so they are used as start end end of rows.
#3 Your theme screws up in another way
I hate to pick on themes all the time, but sadly they cause a lot of these issues. If everything is working as expected, there’s only one way to really exclude your theme from the list of possible causes: Switch to a default theme. If this filter still doesn’t work when you are using an unmodified Twenty Twelve theme, something else is wrong. You are allowed to post a question in the WooCommerce support forums for this issues and explain that this all didn’t work.