woocommerce – get category image from mysql

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

so far I just return categories names and Ides ,

Read More
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?

Related posts

2 comments

  1. 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;
    
  2. To display the category image for the currently displayed category –

    // verify that this is a product category page
    if ( is_product_category() ){
        global $wp_query;
    
        // get the query object
        $cat = $wp_query->get_queried_object();
    
        // get the thumbnail id using the queried category term_id
        $thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true ); 
    
        // get the image URL
        $image = wp_get_attachment_url( $thumbnail_id ); 
    
        // print the IMG HTML
        echo "<img src='{$image}' alt='' width='762' height='365' />";
    }
    

Comments are closed.