Custom Product thumb sang swiper slider

PHOTO EMBED

Sat Aug 16 2025 02:07:54 GMT+0000 (Coordinated Universal Time)

Saved by @vanthien

function smo_product_images_func2($atts) {
    ob_start();
	$atts = shortcode_atts(
        array(
            'product_id' => '',
        ), 
        $atts, 
        'smo_product_images2'
    );
	if(isset($atts['product_id']) && $atts['product_id'] != '') {
		$id = $atts['product_id'];
	}else{
		$id = get_the_ID();
	}
	$product = wc_get_product($id);
	//global $product;
	$thumbnail_size = 'woocommerce_single';
    $thumbnail_size_full = 'full';
	if ($product) {
	$post_thumbnail_id = $product->get_image_id();
	$attachment_ids = $product->get_gallery_image_ids();
	$thumbnail_src     = wp_get_attachment_image_src( $post_thumbnail_id, $thumbnail_size_full );
	$thumbnail_src2     = wp_get_attachment_image_src( $post_thumbnail_id, $thumbnail_size );
	}
?>
<div class="product--thumbnail_slider">
<div class="swiper rst-image-product-big2">
    <div class="swiper-wrapper">
		<div class="swiper-slide rst-item-image-product-big">
			<img src="<?php echo esc_url( $thumbnail_src[0] ); ?>" alt="" />
		</div>
		<?php
		if ( is_array($attachment_ids) && !empty($attachment_ids) ) {
		foreach ( $attachment_ids as $attachment_id ) {
		$gallery_src = wp_get_attachment_image_src( $attachment_id, $thumbnail_size_full );
		?>
		<div class="swiper-slide rst-item-image-product-big">
			<img src="<?php echo esc_url( $gallery_src[0] ); ?>" alt="" />
		</div>
		<?php
		}
		}
		?>
	</div> 
	<div class="swiper-pagination"></div>
</div> 
<?php
	if ( is_array($attachment_ids) && !empty($attachment_ids) ) {
?>
<div class="rst-image-product-thumb-container2">
<div class="swiper rst-image-product-thumb2">
    <div class="swiper-wrapper">
		<div class="swiper-slide rst-item-image-product-thumb">
			<div class="rst-item-image-product-thumb-img"><img src="<?php echo esc_url( $thumbnail_src2[0] ); ?>" alt="" /></div>
		</div>
		<?php
		
		foreach ( $attachment_ids as $attachment_id ) {
		$gallery_src = wp_get_attachment_image_src( $attachment_id, $thumbnail_size );
		?>
		<div class="swiper-slide rst-item-image-product-thumb">
			<div class="rst-item-image-product-thumb-img"><img src="<?php echo esc_url( $gallery_src[0] ); ?>" alt="" /></div>
		</div>
		<?php
		}
		?>
	</div>
	
</div>
	</div>
<?php
	}
?>
</div>
<?php	
	$output = ob_get_contents();
    ob_end_clean();
    return $output;
}

add_shortcode('smo_product_images2', 'smo_product_images_func2');
content_copyCOPY