Задать вопрос
@anmkh

Как вывести изображение выбранной вариации Woocommerce в слайдер Swiper JS?

Не меняется изображения, если выбираю вариацию
Для ссылки fancybox атрибут src меняется, а для img нет. Есть ли какие варианты?
<?php
/**
 * Single Product Image
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/single-product/product-image.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see     https://docs.woocommerce.com/document/template-structure/
 * @package WooCommerce\Templates
 * @version 7.8.0
 */

defined( 'ABSPATH' ) || exit;

// 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.
if ( ! function_exists( 'wc_get_gallery_image_html' ) ) {
	return;
}

global $product;

$columns           = apply_filters( 'woocommerce_product_thumbnails_columns', 4 );
$post_thumbnail_id = $product->get_image_id();
$wrapper_classes   = apply_filters(
	'woocommerce_single_product_image_gallery_classes',
	array(
		'woocommerce-product-gallery',
		'woocommerce-product-gallery--' . ( $post_thumbnail_id ? 'with-images' : 'without-images' ),
		'woocommerce-product-gallery--columns-' . absint( $columns ),
		'images',
	)
);
?>
<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;">
<div class="slider__images <?php echo esc_attr( implode( ' ', array_map( 'sanitize_html_class', $wrapper_classes ) ) ); ?>">
	<div class="swiper-container"> <!-- Слайдер с изображениями -->
		<div class="swiper-wrapper">
		
		<?php if ( has_post_thumbnail() ) : ?>
              <div class="slider__images_slide swiper-slide woocommerce-product-gallery__image">
				<a href="<?php the_post_thumbnail_url(); ?>" data-fancybox="gallery">
					<img src="<?php the_post_thumbnail_url(); ?>" width="499" height="374">
				</a>
			</div>
			<?php 		
			echo apply_filters( 'woocommerce_single_product_image_thumbnail_html', $html, $post_thumbnail_id ); // phpcs:disable WordPress.XSS.EscapeOutput.OutputNotEscaped

		     do_action( 'woocommerce_product_thumbnails' );
			?>
		<?php endif; ?>

		<?php
              global $product;
              $attachment_ids = $product->get_gallery_attachment_ids();
              foreach( $attachment_ids as $attachment_id ) {
                ?>
				<div class="slider__images_slide swiper-slide woocommerce-product-gallery__image">
					<a href="<?php echo $image_link = wp_get_attachment_url( $attachment_id ); ?>" data-fancybox="gallery">
					<img src="<?php echo $image_link = wp_get_attachment_url( $attachment_id ); ?>" class="wp-post-image" width="499" height="374">
					</a>
				</div>
						<?php 		
			echo apply_filters( 'woocommerce_single_product_image_thumbnail_html', $html, $post_thumbnail_id ); // phpcs:disable WordPress.XSS.EscapeOutput.OutputNotEscaped

		     do_action( 'woocommerce_product_thumbnails' );
			?>
					
		<?php
              }
		?> 

		</div>
	</div>

	<?php if ($product->get_gallery_attachment_ids()) { ?>
	<div class="slider__nav">
		<div class="pagination"></div>
		<div class="slider__nav__buttons">
			<div class="btn-product-prev"></div>
			<div class="btn-product-next"></div>
		</div>
	</div>
	<?php  } ?>
</div>
</div>
  • Вопрос задан
  • 133 просмотра
Подписаться 1 Простой 2 комментария
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы