[英]Linking Woocommerce product image and 'add to cart' to product page
I'm setting up a featured products area on my website on the homepage, and it works fine at the moment but I'd also like to make the images clickable and once clicked I want them to go to the product page it self. 我正在主页上的网站上设置一个特色产品区域,目前可以正常使用,但我也想使图像可单击,一旦单击,我希望它们自行转到产品页面。 Also, I'd like the woocommerce_template_loop_add_to_cart to also go to the product page after adding to the cart.
另外,我希望woocommerce_template_loop_add_to_cart添加到购物车后也可以转到产品页面。
My code: 我的代码:
<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();
?>
Thanks! 谢谢!
change this 改变这个
echo get_the_post_thumbnail( $loop->post->ID, 'shop_catalog' );
to this 对此
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.