product-image.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. global $post, $product;
  20. $attachment_ids = $product->get_gallery_image_ids();
  21. $attachment_count = count( $attachment_ids );
  22. $columns = apply_filters( 'woocommerce_product_thumbnails_columns', 3 );
  23. $placeholder = has_post_thumbnail() ? 'with-images' : 'without-images';
  24. $wrapper_classes = apply_filters( 'woocommerce_single_product_image_gallery_classes', array(
  25. 'woocommerce-product-gallery',
  26. 'woocommerce-product-gallery--' . $placeholder,
  27. 'woocommerce-product-gallery--columns-' . absint( $columns ),
  28. 'images',
  29. ) );
  30. ?>
  31. <div class="<?php echo esc_attr( implode( ' ', array_map( 'sanitize_html_class', $wrapper_classes ) ) ); ?>" data-columns="<?php echo esc_attr( $columns ); ?>">
  32. <?php do_action( 'vamtam_woocommerce_before_single_product_images' ) ?>
  33. <?php
  34. if ( has_post_thumbnail() || $attachment_count > 0 ) :
  35. $large_thumbnail_size = apply_filters( 'single_product_large_thumbnail_size', 'shop_single' );
  36. $small_thumbnail_size = apply_filters( 'single_product_small_thumbnail_size', 'shop_thumbnail' );
  37. if ( VamtamTemplates::early_cube_load() ) {
  38. wp_enqueue_script( 'cubeportfolio' );
  39. }
  40. wp_enqueue_style( 'cubeportfolio' );
  41. $slider_options = array(
  42. 'layoutMode' => 'slider',
  43. 'drag' => true,
  44. 'auto' => false,
  45. 'autoTimeout' => 5000,
  46. 'autoPauseOnHover' => true,
  47. 'showNavigation' => true,
  48. 'showPagination' => false,
  49. 'rewindNav' => true,
  50. 'gridAdjustment' => 'responsive',
  51. 'mediaQueries' => array(
  52. array(
  53. 'width' => 1,
  54. 'cols' => 1,
  55. ),
  56. ),
  57. 'gapHorizontal' => 0,
  58. 'gapVertical' => 0,
  59. 'caption' => '',
  60. 'displayType' => 'default',
  61. 'plugins' => array(
  62. 'slider' => array(
  63. 'pagination' => '#product-gallery-pager-' . intval( $post->ID ),
  64. 'paginationClass' => 'cbp-pagination-active',
  65. ),
  66. ),
  67. );
  68. if ( has_post_thumbnail() ) {
  69. $main_image_id = get_post_thumbnail_id();
  70. array_unshift( $attachment_ids, $main_image_id );
  71. }
  72. ?>
  73. <div id="product-gallery-<?php echo intval( $post->ID ) ?>" class="vamtam-cubeportfolio cbp cbp-slider-edge" data-options="<?php echo esc_attr( json_encode( $slider_options ) ) ?>">
  74. <?php foreach ( $attachment_ids as $aid ) : ?>
  75. <div class="cbp-item">
  76. <div class="cbp-caption">
  77. <div class="cbp-caption-defaultWrap">
  78. <?php
  79. $full_size_image = wp_get_attachment_image_src( $aid, $large_thumbnail_size );
  80. $image_title = esc_attr( get_the_title( $aid ) );
  81. $attributes = array(
  82. 'class' => 'wp-post-image',
  83. 'title' => $image_title,
  84. 'data-caption' => get_post_field( 'post_excerpt', $aid ),
  85. 'data-src' => $full_size_image[0],
  86. 'data-large_image' => $full_size_image[0],
  87. 'data-large_image_width' => $full_size_image[1],
  88. 'data-large_image_height' => $full_size_image[2],
  89. );
  90. if ( has_post_thumbnail() ) {
  91. $html = '<div data-thumb="' . get_the_post_thumbnail_url( $post->ID, 'shop_thumbnail' ) . '" class="woocommerce-product-gallery__image"><a href="' . esc_url( $full_size_image[0] ) . '" class="cbp-lightbox">';
  92. $html .= wp_get_attachment_image( $aid, $large_thumbnail_size, false, $attributes );
  93. $html .= '</a></div>';
  94. } else {
  95. $html = '<div class="woocommerce-product-gallery__image--placeholder">';
  96. $html .= sprintf( '<img src="%s" alt="%s" class="wp-post-image" />', esc_url( wc_placeholder_img_src() ), esc_html__( 'Awaiting product image', 'vamtam-consulting' ) );
  97. $html .= '</div>';
  98. }
  99. echo apply_filters( 'woocommerce_single_product_image_thumbnail_html', $html, get_post_thumbnail_id( $post->ID ) ); // xss ok
  100. ?>
  101. </div>
  102. </div>
  103. </div>
  104. <?php endforeach ?>
  105. </div>
  106. <?php
  107. else :
  108. $html = '<div class="woocommerce-product-gallery__image--placeholder">';
  109. $html .= sprintf( '<img src="%s" alt="%s" class="wp-post-image" />', esc_url( wc_placeholder_img_src() ), esc_html__( 'Awaiting product image', 'vamtam-consulting' ) );
  110. $html .= '</div>';
  111. echo $html;
  112. endif;
  113. ?>
  114. <?php if ( $attachment_count > 0 ) : ?>
  115. <div class="thumbnails" id="product-gallery-pager-<?php echo intval( $post->ID ) ?>"><?php
  116. $loop = 0;
  117. foreach ( $attachment_ids as $attachment_id ) {
  118. $classes = array( 'cbp-pagination-item' );
  119. if ( 0 === $loop || 0 === $loop % $columns )
  120. $classes[] = 'first';
  121. if ( 0 === ( $loop + 1 ) % $columns )
  122. $classes[] = 'last';
  123. $image_link = wp_get_attachment_url( $attachment_id );
  124. if ( $image_link ) {
  125. $image = wp_get_attachment_image( $attachment_id, apply_filters( 'single_product_small_thumbnail_size', 'shop_thumbnail' ) );
  126. $image_class = esc_attr( implode( ' ', $classes ) );
  127. $image_title = esc_attr( get_the_title( $attachment_id ) );
  128. echo wp_kses_post( apply_filters( 'vamtam_woocommerce_single_product_image_thumbnail_html', sprintf( '<div class="%s" title="%s">%s</div>', $image_class, $image_title, $image ), $attachment_id, $post->ID, $image_class ) );
  129. $loop++;
  130. }
  131. }
  132. ?></div>
  133. <?php endif ?>
  134. <?php do_action( 'vamtam_woocommerce_after_single_product_images' ) ?>
  135. </div>