SHARE
TWEET

list best selling products in woocommerce

humayun180 Mar 26th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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(); ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top