Forked from rajeebbanstola/get-woocommerce-categories.php
Last active
September 5, 2019 22:26
-
-
Save hemusyl/e37984df1050945c20447de67fb5d9ae to your computer and use it in GitHub Desktop.
Simple way to fetch WooCommerce Categories with Image and Description
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://stackoverflow.com/questions/21009516/get-woocommerce-product-categories-from-wordpress | |
https://stackoverflow.com/questions/38288298/cant-get-category-object-in-some-templates-of-woocommerce?noredirect=1&lq=1 | |
<?php | |
$get_featured_cats = array( | |
'taxonomy' => 'product_cat', | |
'orderby' => 'name', | |
'hide_empty' => '0', | |
'include' => $cat_array | |
); | |
$all_categories = get_categories( $get_featured_cats ); | |
$j = 1; | |
foreach ($all_categories as $cat) { | |
$cat_id = $cat->term_id; | |
$cat_link = get_category_link( $cat_id ); | |
$thumbnail_id = get_term_meta( $cat->term_id, 'thumbnail_id', true ); // Get Category Thumbnail | |
$image = wp_get_attachment_url( $thumbnail_id ); | |
if ( $image ) { | |
echo '<img src="' . $image . '" alt="" />'; | |
} | |
echo $cat->name; // Get Category Name | |
echo $cat->description; // Get Category Description | |
$j++; | |
} | |
// Reset Post Data | |
wp_reset_query(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment