WooCommerce 2.1.9 cheatsheet – product listing page

How To Change Number Products Displayed Per Page

Insert the following code in your theme’s functions.php

// Display 40 products per page. 
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 40;' ), 20 );

How To Remove Sorting Option Dropdown Menu

Insert the following code in your theme’s functions.php

//remove sorting option drop down in product listing page
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );

How To Remove Prices From Product Listing Page

Insert the following code in your theme’s functions.php

function woo_product_listing_remove_price(){
// hide product price on category page
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10);
}
add_action( 'init', 'woo_product_listing_remove_price' );

How To List Product Attributes

This will involve overwriting “product-content.php” in WooCommerce template:

  1. Copy “content-product.php” from /wp-content/plugins/woocommerce/templates/ to  /wp-content/themes/yourthemefolder/woocommerce/  you may have to create “woocommerce” folder within your root of your theme folder if you haven’t already)
  2. In content-product.php, add the following code in the location where you want to the attributes to show.  The example is showing just attribute values
//insert product attributes
if ( $attributes = $product->get_attributes( ) ) :
	foreach($attributes as $attribute){
?>
	<div class="attribute">
	<?php
		$values = wc_get_product_terms( $product->id, $attribute['name'], array( 'fields' => 'names' ) );
		foreach($values as $value) echo $value . " ";
	?>
	</div>
	<?php
	}
endif;

If you want to display the attributes closer to how they are shown in single product page, you can check the code by looking at product-attributes.php in /wp-content/plugins/woocommerce/templates/single-product/. The attributes related code starts at line 42.

Leave a Reply