'Get all product categories in WooCommerce
I am trying to get product categories in WooCommerce, but get_terms() function doesn't work for me. I am getting an empty array.
What I am doing wrong? How to get all Woocommerce product category terms?
Solution 1:[1]
I got mine out of all product categories, also exclude categories that I don't want to display
$taxonomy = "product_cat";
$terms = get_terms($taxonomy, array('orderby' => 'slug', 'hide_empty' => false, 'exclude' => array( 19 ))); //Exclude Specific Category by ID
foreach ($terms as $term) {
$thumbnail_id = get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true);
$image = wp_get_attachment_url($thumbnail_id); ?>
<div class="col-12 col-md-3">
<div class="cat-item drop-shadow white-b padding-20 align-center margin-bottom-30">
<?php
echo '<h3 class="uppercase strong blue-2-c margin-bototm-20 equal-height">' . $term->name . '</h3>';
echo '<div class="item-thumbnail" style="background: url('.$image.');height:150px"></div>';
echo '<a href="' . get_term_link($term->name, $taxonomy) . '" class="button color-blue-2-radial">View Range</a>';
?>
</div>
</div>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Aleksandrs Krasnovskis |
