- This topic has 3 replies, 3 voices, and was last updated 8 years, 1 month ago by
Tom.
-
AuthorPosts
-
February 28, 2018 at 8:32 am #508015
Mike
Hello there!
I tried the following code placed in functions.php but it does not seem to have an effect. I wonder if the code is wrong, or if GP Woocommerce per-row settings overwrite it, in which case I altered the priorities but no cigar.
Here’s the code:
if ( ! function_exists( 'loop_columns' ) ) { function loop_columns( $columns ) { if ( ! is_product_category( 'target-product-category-here' ) ) return $columns; return 5; // Or any other number } } add_filter( 'loop_shop_columns', 'loop_columns' );February 28, 2018 at 4:17 pm #508401Leo
StaffCustomer SupportHi there,
Can you try Tom’s code here with your conditional statement?
https://generatepress.com/forums/topic/customize-woocomerce-layout/#post-225844Let us know.
March 6, 2018 at 8:41 pm #513502Mike
Thanks for the reference. I tried the following:
add_filter('loop_shop_columns', 'loop_columns'); if (!function_exists('loop_columns')) { if (!is_product_category('target-category-here')) { function loop_columns() { return 2; } } }and
add_filter('loop_shop_columns', 'loop_columns'); if (!is_product_category('audio')) { function loop_columns() { return 2; } }Neither had any effect. The category pages don’t change the number of columns at all. This problem is a bit of a head-scratcher. Some categories have only two subcategories, so I didn’t want them to be arranged in four columns per row as that would leave two empty spaces. Blowing up those two subcategories to take up the entire area of two columns would be better than the current set-up.
Some categories need to display 3 columns, others 4 and 2 etc. So I would be targetting specific categories with each block of conditionals. I couldn’t create an array as coding isn’t my strength (I’ve seen them used in different ways before).
I appreciate any guidance to get this solved!
March 7, 2018 at 10:15 am #514081Tom
Lead DeveloperLead DeveloperGive this a shot:
add_filter( 'option_generate_woocommerce_settings', 'tu_custom_wc_columns' ); function tu_custom_wc_columns( $options ) { if ( ! is_product_category( 'audio' ) ) { $options['columns'] = 2; } return $options; } -
AuthorPosts
- You must be logged in to reply to this topic.