product-image.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Single Product Image
  4. *
  5. * This template can be overridden by copying it to yourtheme/woocommerce/single-product/product-image.php.
  6. *
  7. * HOWEVER, on occasion WooCommerce will need to update template files and you
  8. * (the theme developer) will need to copy the new files to your theme to
  9. * maintain compatibility. We try to do this as little as possible, but it does
  10. * happen. When this occurs the version of the template file will be bumped and
  11. * the readme will list any important changes.
  12. *
  13. * @see https://docs.woocommerce.com/document/template-structure/
  14. * @author WooThemes
  15. * @package WooCommerce/Templates
  16. * @version 3.3.2
  17. */
  18. defined( 'ABSPATH' ) || exit;
  19. // Note: `wc_get_gallery_image_html` was added in WC 3.3.2 and did not exist prior. This check protects against theme overrides being used on older versions of WC.
  20. if ( ! function_exists( 'wc_get_gallery_image_html' ) ) {
  21. return;
  22. }
  23. global $product;
  24. $columns = apply_filters( 'woocommerce_product_thumbnails_columns', 4 );
  25. $post_thumbnail_id = $product->get_image_id();
  26. $wrapper_classes = apply_filters( 'woocommerce_single_product_image_gallery_classes', array(
  27. 'woocommerce-product-gallery',
  28. 'woocommerce-product-gallery--' . ( has_post_thumbnail() ? 'with-images' : 'without-images' ),
  29. 'woocommerce-product-gallery--columns-' . absint( $columns ),
  30. 'images',
  31. ) );
  32. ?>
  33. <div class="<?php echo esc_attr( implode( ' ', array_map( 'sanitize_html_class', $wrapper_classes ) ) ); ?>" data-columns="<?php echo esc_attr( $columns ); ?>" style="opacity: 0; transition: opacity .25s ease-in-out;">
  34. <figure class="woocommerce-product-gallery__wrapper">
  35. <?php
  36. if ( has_post_thumbnail() ) {
  37. $html = wc_get_gallery_image_html( $post_thumbnail_id, true );
  38. } else {
  39. $html = '<div class="woocommerce-product-gallery__image--placeholder">';
  40. $html .= sprintf( '<img src="%s" alt="%s" class="wp-post-image" />', esc_url( wc_placeholder_img_src() ), esc_html__( 'Awaiting product image', 'woocommerce' ) );
  41. $html .= '</div>';
  42. }
  43. echo apply_filters( 'woocommerce_single_product_image_thumbnail_html', $html, $post_thumbnail_id );
  44. do_action( 'woocommerce_product_thumbnails' );
  45. ?>
  46. </figure>
  47. </div>