WC_Dynamic_Gallery_Variations

WooCommerce Dynamic Gallery Variations Class.

Defined (1)

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

/classes/class-wc-dynamic-gallery-variations.php  
  1. class WC_Dynamic_Gallery_Variations 
  2.  
  3. public static function change_image_in_cart_page( $product_image, $values, $cart_item_key ) { 
  4. if ( is_array( $values ) && isset( $values['variation_id'] ) && $values['variation_id'] > 0 ) { 
  5. return $product_image; 
  6.  
  7. } elseif ( isset( $values['product_id'] ) && $values['product_id'] > 0 ) { 
  8. $product_id = $values['product_id']; 
  9. // Don't change the image if product has featured image 
  10. if ( has_post_thumbnail( $product_id ) ) return $product_image; 
  11.  
  12. $dgallery_ids = WC_Dynamic_Gallery_Functions::get_gallery_ids( $product_id ); 
  13. if ( is_array( $dgallery_ids ) && count( $dgallery_ids ) > 0 ) { 
  14. // Use first image from variation gallery 
  15. $img_id = (int) array_shift( $dgallery_ids ); 
  16. $product_image = wp_get_attachment_image( $img_id, 'shop_thumbnail' ); 
  17.  
  18. return $product_image;