我想问一下woo-commerce特色产品功能。我在 function.php 中为这样的特色产品创建:
function get_featured_product(){
$tax_query[] = array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => 'featured',
'operator' => 'IN',
);
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => $products,
'orderby' => $orderby,
'order' => $order == 'asc' ? 'asc' : 'desc',
'tax_query' => $tax_query
);
$query = new WP_Query( $args );
ob_start();
?>
<div class="row">
<div class="col-md-12">
<div class="row">
<?php
while ( $query->have_posts() ) : $query->the_post(); global $product; ?>
<div class="col-md-4">
<?php
if ( has_post_thumbnail( $query->post->ID ) )
echo get_the_post_thumbnail( $query->post->ID, 'full' );
else
echo '<img src="' . woocommerce_placeholder_img_src() . '" alt="Placeholder" width="65px" height="115px" />';
?>
<div class="content" style="padding: 0 20px;">
<h3><?php the_title(); ?></h3>
<p>
<?php echo $product->get_price_html(); ?>
</p>
<div class="row">
<div class="col-xs-3 col-md-3">
<a href="#"><img src="http://localhost/wellliveflorist/wp-content/uploads/2018/04/compare-pink.png" width="25" heigh="25" style="float: left;"></a>
</div>
<div class="col-xs-6 col-md-6" style="text-align: center;">
<?php
woocommerce_template_loop_add_to_cart( $loop->post, $product );
?>
</div>
<div class="col-xs-3 col-md-3">
[ti_wishlists_addtowishlist]
</div>
</div>
</div>
</div>
<?php
endwhile;
?>
</div>
</div>
</div><?php
return ob_get_clean();
wp_reset_query();
}
add_shortcode('featured_product', 'get_featured_product');
但是当我点击心形图标(愿望清单)时,只会得到一个 id,换句话说,愿望清单按钮只会得到 1 个 id,无论你在另一个产品中点击什么,仍然会得到错误的 id 产品。有谁知道,我应该改变什么?