[英]Linking Woocommerce product image and 'add to cart' to product page
我正在主頁上的網站上設置一個特色產品區域,目前可以正常使用,但我也想使圖像可單擊,一旦單擊,我希望它們自行轉到產品頁面。 另外,我希望woocommerce_template_loop_add_to_cart添加到購物車后也可以轉到產品頁面。
我的代碼:
<div class="featured-products">
<h1 class="featured-products">Featured Products</h1>
<?php
$meta_query = WC()->query->get_meta_query();
$meta_query[] = array(
'key' => '_featured',
'value' => 'yes'
);
$args = array(
'post_type' => 'product',
'stock' => 1,
'showposts' => 4,
'orderby' => 'date',
'order' => 'DESC',
'meta_query' => $meta_query
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
<li>
<?php
if ( has_post_thumbnail( $loop->post->ID ) )
echo get_the_post_thumbnail( $loop->post->ID, 'shop_catalog' );
else
echo '<img src="' . woocommerce_placeholder_img_src() . ' />';
?>
<p><?php the_title(); ?></p>
<p><?php echo $product->get_price_html(); ?></p>
<?php
woocommerce_template_loop_add_to_cart( $loop->post, $product );
?>
</li>
<?php
endwhile;
wp_reset_query();
?>
謝謝!
改變這個
echo get_the_post_thumbnail( $loop->post->ID, 'shop_catalog' );
對此
echo sprintf('<a href="%s">%s</a>', get_the_permalink( $loop->post->ID ), get_the_post_thumbnail( $loop->post->ID, 'shop_catalog' ) );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.