단일 제품에서 관련 제품을 제거했습니다.
remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );
이제 제품 이미지 갤러리 아래에 관련 제품을 표시하고 싶습니다. 다음은 제품 갤러리 코드입니다.
/*******Single Product ********/
remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );
remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
add_action( 'woocommerce_product_thumbnails', 'show_product_thumbnails', 20 );
add_action( 'woocommerce_before_single_product_summary', 'show_product_images', 10 );
function show_product_thumbnails(){
global $post, $product, $woocommerce;
$attachment_ids = $product->get_gallery_attachment_ids();
$count_gallery = count($attachment_ids);
echo '<div class="thumbnails" id="gallery">';
if ( $attachment_ids ) {
echo '<div class="main-slider" style="width:85%; float:right;position: relative;">'
echo '<div class="slider slider-for">';
foreach ( $attachment_ids as $attachment_id ) {
$totem_single_image = wp_get_attachment_image_src( $attachment_id, 'shop_single', true );
$image_link = $totem_single_image[0];
$main_image_link = wp_get_attachment_url( $attachment_id );
$image_title = esc_attr( get_the_title( $attachment_id ) );
$image = wp_get_attachment_image(
$attachment_id,
apply_filters( 'single_product_small_thumbnail_size', 'shop_single' ),
0,
$attr = array(
'title' => $image_title,
'alt' => $image_title
)
);
echo apply_filters( 'woocommerce_single_product_image_thumbnail_html', sprintf( '<a href="%s" class="elevatezoom-gallery" title="%s"><img class="lily_zoom" src="%s" alt="%s" data-zoom-image="%s"></a>', $main_image_link, $image_caption, $image_link, $image_title, $main_image_link), $attachment_id, $post->ID );
}
echo '</div>';
echo'</div>';
echo '<div class="pagination" style="width:13%; display:block;">';
echo '<div class="slider slider-nav" role="toolbar">';
foreach ( $attachment_ids as $attachment_id ) {
$totem_single_image = wp_get_attachment_image_src( $attachment_id, 'medium', true );
$image_link = $totem_single_image[0];
$main_image_link = wp_get_attachment_url( $attachment_id );
$image_title = esc_attr( get_the_title( $attachment_id ) );
$image = wp_get_attachment_image(
$attachment_id,
apply_filters( 'single_product_small_thumbnail_size', 'shop_single' ),
0,
$attr = array(
'title' => $image_title,
'alt' => $image_title
)
);
echo apply_filters( 'woocommerce_single_product_image_thumbnail_html', sprintf( '<img src="%s" alt="%s"></a>', $image_link,$image_title), $attachment_id, $post->ID );
}
echo '</div>';
echo '</div>';
}
echo '</div>';
}
function show_product_images(){
global $post, $woocommerce, $product;
echo '<div class="images lily-main-image">';
if ( has_post_thumbnail() ) {
$image_caption = get_post( get_post_thumbnail_id() )->post_excerpt;
$main_image_link = wp_get_attachment_url( get_post_thumbnail_id() );
$image = get_the_post_thumbnail(
$post->ID,
apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ),
array(
'title' => get_the_title( get_post_thumbnail_id() ),
'data-zoom-image' => $main_image_link,
'id' => 'totemImgZoom'
)
);
$attachment_count = count( $product->get_gallery_attachment_ids() );
// echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<img width="320px"src="%s" id="totemImgZoom" data-zoom-image="%s" title="%s" alt="">', $main_image_link, $main_image_link, $image_caption), $post->ID);
}
else {
// echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<img class="zoomImage" src="%s" alt="%s"/>', wc_placeholder_img_src(), __( 'Placeholder', 'woocommerce' ) ), $post->ID );
}
do_action( 'woocommerce_product_thumbnails' );
do_action( 'woocommerce_output_related_products');
echo '</div>';
}
좋아, 여기에 해결책이 있습니다.
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
add_action( 'woocommerce_before_single_product_summary', 'woocommerce_output_related_products', 25);
function woocommerce_output_related_products(){
$args = array(
'posts_per_page' => 4,
'columns' => 4,
'orderby' => 'rand'
);
woocommerce_related_products( apply_filters( 'woocommerce_output_related_products_args', $args ) );
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다