Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Displaying Woocommerce Categories in Custom Theme

Hello,

Does anyone know how to display product categories in a custom theme with Woocommerce?

2 Answers

Sue Dough
Sue Dough
35,800 Points

You don't need all of this but this is all the options you have to work with. This will display woo commerce product categories with thumbnails and a description.

I suggest looking at themes too that have already done what you are looking to do to get a better understanding.

<?php

global $post;

$args = array(

‘show_option_all’    => ”,

‘orderby’            => ‘name’,

‘order’              => ‘ASC’,

‘style’              => ‘list’,

‘show_count’         => 0,

‘hide_empty’         => 1,

‘use_desc_for_title’ => 1,

‘child_of’           => 0,

‘feed’               => ”,

‘feed_type’          => ”,

‘feed_image’         => ”,

‘exclude’            => ”,

‘exclude_tree’       => ”,

‘include’            => ”,

‘hierarchical’       => 1,

‘title_li’           => __( ‘Categories’ ),

‘show_option_none’   => __(‘No categories’),

‘number’             => null,

‘echo’               => 1,

‘depth’              => 0,

‘current_category’   => 0,

‘pad_counts’         => 0,

‘taxonomy’           => ‘product_cat’,

‘walker’             => null );  ?>

<?php $catTerms = get_terms(‘product_cat’, array(‘hide_empty’ => 0, ‘orderby’ => ‘ASC’)); ?>

<?php foreach($catTerms as $catTerm) : ?>

<a href=”?product_cat=<?php echo $catTerm->slug; ?>”><?php echo $catTerm->name; ?></a><br/>

<?php echo $catTerm->description ; ?>

<?php

$thumbnail_id = get_woocommerce_term_meta( $catTerm->term_id, ‘thumbnail_id’, true );

// get the image URL

$image = wp_get_attachment_url( $thumbnail_id );

// print the IMG HTML

echo ‘<img src=”‘.$image.'” alt=”” width=”300″ height=”208″ />'; ?>

<?php echo $catTerm->term_id;?>

<?php endforeach; ?>
Patricia Silva
PLUS
Patricia Silva
Courses Plus Student 89,123 Points

I don't have an answer but I have two suggestions on where you can look:

http://docs.woothemes.com/document/third-party-custom-theme-compatibility/

http://docs.woothemes.com/document/woocommerce-shortcodes/

for the last link, click on item 12 in the left sidebar to get to category