Last active
January 17, 2017 09:50
-
-
Save pirey/aa92cccea6bb306bd006db01ad1cb345 to your computer and use it in GitHub Desktop.
Get all categories with additional fields in woocommerce
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
| <?php | |
| function wc_get_categories() { | |
| $all_categories = get_categories(array( | |
| 'taxonomy' => 'product_cat' | |
| )); | |
| foreach ($all_categories as &$cat) { | |
| $thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true ); | |
| $cat->thumbnail_image = wp_get_attachment_url( $thumbnail_id ); | |
| $cat->link = get_term_link( $cat->slug, 'product_cat' ); | |
| } | |
| return $all_categories; | |
| // return this instead if you want to return only root categories | |
| // return array_map($all_categories, function($cat) { | |
| // return $cat->parent == 0; | |
| // }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment