Skip to content

Instantly share code, notes, and snippets.

@ChromeOrange
Created June 28, 2012 14:00
Show Gist options
  • Save ChromeOrange/3011557 to your computer and use it in GitHub Desktop.
Save ChromeOrange/3011557 to your computer and use it in GitHub Desktop.
Change the product columns in WooCommerce
/*
1 - modify your theme functions file
2 - modify the 'loop-shop.php' file
You need to set the 'Product List' value to suit your layout. You will also need to look at changing the CSS if you change from the default WooCommerce values.
1 : Add this to your theme functions file
*/
add_filter('loop_shop_columns', 'wc_product_columns_frontend');
function wc_product_columns_frontend() {
global $woocommerce;
// Default Value also used for categories and sub_categories
$columns = 4;
// Product List
if ( is_product_category() ) :
$columns = 4;
endif;
//Related Products
if ( is_product() ) :
$columns = 2;
endif;
//Cross Sells
if ( is_checkout() ) :
$columns = 4;
endif;
return $columns;
}
/*
2 : Copy
wp_content/plugins/woocommerce/templates/loop-shop.php
to
wp_content/themes/YOUR_THEME_NAME/woocommerce/loop-shop.php
and change line 8 from
*/
if (!isset($woocommerce_loop['columns']) || !$woocommerce_loop['columns']) $woocommerce_loop['columns'] = apply_filters('loop_shop_columns', 4);
// to
$woocommerce_loop['columns'] = apply_filters('loop_shop_columns', 4);
@fredmat
Copy link

fredmat commented Apr 18, 2014

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment