Fix for broken number of columns on shop pages
-
This is a fix for the closed topic: Change Number of Product Columns on Shop Page
Basically the problem is that the number of products in storefront pages can get stuck on 2 columns. I tried using plugins as suggested in the responses in the original thread but they did not work. I tried disabling all plugins and eventually found that the problem was that Woocommerce was not working with Ultimatum properly. I then looked through the php files for Woocommerce and Ultimatum with no luck until I noticed “Ultimatum Connect WooCommerce”. Going through the php of “Ultimatum Connect WooCommerce” I found where the columns were getting their instructions:wp-content\plugins\ultimatum-connect-wc\templates\content-product.php
// Increase loop count $woocommerce_loop['loop']++; // Extra post classes $classes = array(); if ( 0 == ( $woocommerce_loop['loop'] - 1 ) % $woocommerce_loop['columns'] || 1 == $woocommerce_loop['columns'] ) $classes[] = 'first'; if ( 0 == $woocommerce_loop['loop'] % $woocommerce_loop['columns'] ) $classes[] = 'last';
I commented out the “$woocommerce_loop[‘loop’]++;” because it was making the item count increase by 2 (1,3,5,7,9,etc) instead of 1 (0,1,2,3,4,etc)
I also rewrote the “first/last” class assignments because variables had changed so the math had to change to compensate.// Increase loop count //$woocommerce_loop['loop']++; // Extra post classes $classes = array(); if ( 1 == $woocommerce_loop['columns'] ) { $classes[] = 'first'; $classes[] = 'last'; } else if ( 0 == ( $woocommerce_loop['loop']) % $woocommerce_loop['columns']) { $classes[] = 'first'; } else if ( $woocommerce_loop['columns'] - 1 == ( $woocommerce_loop['loop']) % $woocommerce_loop['columns'] ) { $classes[] = 'last'; }
This fixed it so I could have 4 columns.
The css did not have to be changed as suggested in the closed thread, once the math gave the items the correct first or last class, the existing css worked fine.
- The topic ‘Fix for broken number of columns on shop pages’ is closed to new replies.