Advertisement
humayun180

list best selling products in woocommerce

Mar 26th, 2019
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.87 KB | None | 0 0
  1. <?php
  2. https://docs.woocommerce.com/document/woocommerce-shortcodes/
  3. https://stackoverflow.com/questions/42765910/how-can-i-list-best-selling-products-in-woocommerce
  4.  
  5. <?php
  6. $args = array(
  7.     'post_type' => 'product',
  8.     'meta_key' => 'total_sales',
  9.     'orderby' => 'meta_value_num',
  10.     'posts_per_page' => 1,
  11. );
  12. $loop = new WP_Query( $args );
  13. while ( $loop->have_posts() ) : $loop->the_post();
  14. global $product; ?>
  15. <div>
  16. <a href="<?php the_permalink(); ?>" id="id-<?php the_id(); ?>" title="<?php the_title(); ?>">
  17.  
  18. <?php if (has_post_thumbnail( $loop->post->ID ))
  19.         echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog');
  20.         else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="product placeholder Image" width="65px" height="115px" />'; ?>
  21.  
  22. <h3><?php the_title(); ?></h3>
  23. </a>
  24. </div>
  25. <?php endwhile; ?>
  26. <?php wp_reset_query(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement