Display Woocommerce Product category Description on all Category Pages

Out of the box, WooCommerce displays the product category description only on the first page of the category archive. In other words, if the category contains a bunch of products and is paginated, the category description will not be shown on page 2, 3, etc.

But what if you want to display the category description on all the paginated pages? What if, for example, you are running a special promotion and want to include the promotion details in the category description and make sure your shop visitor sees it regardless of which page of the category s/he is on?

The solution is quite straight-forward. Add the following code to your theme’s functions.php file:

/* Display WooCommerce product category description on all category archive pages */
 function my_theme_woocommerce_taxonomy_archive_description() {
 if ( is_tax( array( 'product_cat', 'product_tag' ) ) && get_query_var( 'paged' ) != 0 ) {
 $description = wc_format_content( term_description() );
 if ( $description ) {
 echo '' . $description . '';}
 }
 }
 add_action( 'woocommerce_archive_description', 'my_theme_woocommerce_taxonomy_archive_description');

 

The WooCommerce category pages’ layout is governed by the /templates/archive-product.php template and we leverage the woocommerce_archive_description action hook called in this template.

Our custom function above is almost a carbon copy of the default woocommerce_taxonomy_archive_description function, with only one difference: instead of using get_query_var( ‘paged’ ) == 0 as in the default function, we use get_query_var( ‘paged’ ) != 0.

This ensures that the category description is added on all the category pages. Since we do not override the default function, but merely hook into the woocommerce_archive_description action, the category description is still added on the first category page by the default function.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s