php 在woocommerce中展示最畅销的产品
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 在woocommerce中展示最畅销的产品相关的知识,希望对你有一定的参考价值。
<!-- the most sold products -->
<div class="container">
<div class="card-checkout">
<div class="card-checkout">
<h2 class="text-muted text-center">پر فروش ترین محصولات</h2>
</div>
<div class="row">
<?php
$args = array(
'post_type' => 'product',
'meta_key' => 'total_sales',
'orderby' => 'meta_value_num',
'posts_per_page' => 8,
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
global $product;
$currency = get_woocommerce_currency_symbol();
$price = get_post_meta( get_the_ID(), '_regular_price', true);
$sale = get_post_meta( get_the_ID(), '_sale_price', true); ?>
<div id="custom-queries-mouse-hover" class="col-xs-3 col-md-3 col-lg-3">
<div class="card-profile card-plain">
<a id="id-<?php the_id(); ?>" href="<?php the_permalink(); ?>"title="<?php the_title(); ?>">
<?php if (has_post_thumbnail( $loop->post->ID )): ?>
<div class="col-lg-12">
<?php echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); ?>
</div>
<?php else : echo '<img src="'.woocommerce_placeholder_img_src().'" alt="product placeholder Image" width="100%" height="100%" />'; ?>
<?php endif; ?>
<div class="col-lg-12">
<div class="content">
<h6 class="card-title margin-top-30 text-center"><?php the_title(); ?></h6>
<?php if($sale) : ?>
<h6 class="category text-muted text-center"><del><?php echo $price; echo $currency; ?></del> <?php echo $sale; echo $currency; ?></h6>
<?php elseif($price) : ?>
<h6 class="category text-muted text-center"><?php echo $price; echo $currency; ?></h6>
<?php endif; ?>
<div class="footer">
<?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>
</div>
</div>
</div>
</a>
</div>
<div class="col-lg-12">
<div class="content">
</div>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</div>
</div>
</div>
<!-- end of the most sold products -->
以上是关于php 在woocommerce中展示最畅销的产品的主要内容,如果未能解决你的问题,请参考以下文章