woocommerce_subcategory_thumbnail

Show subcategory thumbnails.

Description

woocommerce_subcategory_thumbnail( (mixed) $category ); 

Parameters (1)

0. $category (mixed)
The category.

Usage

  1. if ( !function_exists( 'woocommerce_subcategory_thumbnail' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-template-functions.php'; 
  3.  
  4. // The category. 
  5. $category = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = woocommerce_subcategory_thumbnail($category); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-template-functions.php  
  1. function woocommerce_subcategory_thumbnail( $category ) { 
  2. $small_thumbnail_size = apply_filters( 'subcategory_archive_thumbnail_size', 'shop_catalog' ); 
  3. $dimensions = wc_get_image_size( $small_thumbnail_size ); 
  4. $thumbnail_id = get_woocommerce_term_meta( $category->term_id, 'thumbnail_id', true ); 
  5.  
  6. if ( $thumbnail_id ) { 
  7. $image = wp_get_attachment_image_src( $thumbnail_id, $small_thumbnail_size ); 
  8. $image = $image[0]; 
  9. $image_srcset = function_exists( 'wp_get_attachment_image_srcset' ) ? wp_get_attachment_image_srcset( $thumbnail_id, $small_thumbnail_size ) : false; 
  10. $image_sizes = function_exists( 'wp_get_attachment_image_sizes' ) ? wp_get_attachment_image_sizes( $thumbnail_id, $small_thumbnail_size ) : false; 
  11. } else { 
  12. $image = wc_placeholder_img_src(); 
  13. $image_srcset = $image_sizes = false; 
  14.  
  15. if ( $image ) { 
  16. // Prevent esc_url from breaking spaces in urls for image embeds 
  17. // Ref: https://core.trac.wordpress.org/ticket/23605 
  18. $image = str_replace( ' ', '%20', $image ); 
  19.  
  20. // Add responsive image markup if available 
  21. if ( $image_srcset && $image_sizes ) { 
  22. echo '<img src="' . esc_url( $image ) . '" alt="' . esc_attr( $category->name ) . '" width="' . esc_attr( $dimensions['width'] ) . '" height="' . esc_attr( $dimensions['height'] ) . '" srcset="' . esc_attr( $image_srcset ) . '" sizes="' . esc_attr( $image_sizes ) . '" />'; 
  23. } else { 
  24. echo '<img src="' . esc_url( $image ) . '" alt="' . esc_attr( $category->name ) . '" width="' . esc_attr( $dimensions['width'] ) . '" height="' . esc_attr( $dimensions['height'] ) . '" />';