1
我刪除了相關產品從單一的產品顯示woocommerce相關產品下的產品圖庫
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>';
}
這應該被標記爲答案,因爲作品完美!一個問題@Javid是否有更新代碼的方法,以便相關產品僅顯示鏈接圖像(沒有添加到購物車和所有其他默認代碼?因此,相關產品將只顯示縮略圖? – cchiera
@cchiera是的,這是可能的,你有堆棧溢出這個問題,我有點生病,明天早上看看 – Javid