Skip to content

Instantly share code, notes, and snippets.

@rajeebbanstola
Created December 28, 2015 11:15
Show Gist options
  • Save rajeebbanstola/c30a076b2c33cd146d08 to your computer and use it in GitHub Desktop.
Save rajeebbanstola/c30a076b2c33cd146d08 to your computer and use it in GitHub Desktop.

Revisions

  1. rajeebbanstola created this gist Dec 28, 2015.
    26 changes: 26 additions & 0 deletions get-woocommerce-categories.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    <?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_woocommerce_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();
    ?>