donald draper donald draper - 5 months ago 10
MySQL Question

woocomerce - get category image from mysql

I want to return my categories images from mysql database in woocomerce . I don't know what should I do and How can I return the images from database .

Could you help me .

so far I just return categories names and Ides ,

SELECT * from `wp_terms` where term_id in (SELECT term_id FROM `wp_term_taxonomy` WHERE `taxonomy` LIKE 'product_cat' AND `parent` = 0 and count>0)


How can I do so ?

Answer
Try below code:

    $catTerms = get_terms('product_cat', array('hide_empty' => 0, 'orderby' => 'ASC'));
    foreach($catTerms as $catTerm) :
    $thumbnail_id = get_woocommerce_term_meta( $catTerm->term_id, 'thumbnail_id', true ); 
    // get the image URL
    $image = wp_get_attachment_url( $thumbnail_id );
    <li>
        <img src="<?php echo $image; ?>" width="152" height="245"/>
        <span><?php echo $catTerm->name; ?></span>
    </li>
    endforeach;