How to display Woocommerce Category image?

后端 未结 9 1497
说谎
说谎 2020-12-08 07:41

I use this code in PHP:

$idcat = 147;
$thumbnail_id = get_woocommerce_term_meta( $idcat, \'thumbnail_id\', true );
$image = wp_get_attachment_url( $thumbnail         


        
9条回答
  •  眼角桃花
    2020-12-08 08:24

    From the WooCommerce page:

    // WooCommerce – display category image on category archive
    
    add_action( 'woocommerce_archive_description', 'woocommerce_category_image', 2 );
    function woocommerce_category_image() {
        if ( is_product_category() ){
          global $wp_query;
          $cat = $wp_query->get_queried_object();
          $thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
          $image = wp_get_attachment_url( $thumbnail_id );
          if ( $image ) {
              echo '';
          }
      }
    }
    

提交回复
热议问题