WC_Report_Most_Stocked

WC_Report_Most_Stocked.

Defined (1)

The class is defined in the following location(s).

/includes/admin/reports/class-wc-report-most-stocked.php  
  1. class WC_Report_Most_Stocked extends WC_Report_Stock { 
  2.  
  3. /** 
  4. * Get Products matching stock criteria. 
  5. * @param int $current_page 
  6. * @param int $per_page 
  7. */ 
  8. public function get_items( $current_page, $per_page ) { 
  9. global $wpdb; 
  10.  
  11. $this->max_items = 0; 
  12. $this->items = array(); 
  13.  
  14. // Get products using a query - this is too advanced for get_posts :( 
  15. $stock = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 0 ) ); 
  16.  
  17. $query_from = "FROM {$wpdb->posts} as posts 
  18. INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id 
  19. INNER JOIN {$wpdb->postmeta} AS postmeta2 ON posts.ID = postmeta2.post_id 
  20. WHERE 1=1 
  21. AND posts.post_type IN ( 'product', 'product_variation' ) 
  22. AND posts.post_status = 'publish' 
  23. AND postmeta2.meta_key = '_manage_stock' AND postmeta2.meta_value = 'yes' 
  24. AND postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) > '{$stock}' 
  25. "; 
  26.  
  27. $query_from = apply_filters( 'woocommerce_report_most_stocked_query_from', $query_from ); 
  28.  
  29. $this->items = $wpdb->get_results( $wpdb->prepare( "SELECT posts.ID as id, posts.post_parent as parent {$query_from} GROUP BY posts.ID ORDER BY CAST(postmeta.meta_value AS SIGNED) DESC LIMIT %d, %d;", ( $current_page - 1 ) * $per_page, $per_page ) ); 
  30. $this->max_items = $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" );