WC_Report_Low_In_Stock

WC_Report_Low_In_Stock.

Defined (1)

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

/includes/admin/reports/class-wc-report-low-in-stock.php  
  1. class WC_Report_Low_In_Stock extends WC_Report_Stock { 
  2.  
  3. /** 
  4. * No items found text. 
  5. */ 
  6. public function no_items() { 
  7. _e( 'No low in stock products found.', 'woocommerce' ); 
  8.  
  9. /** 
  10. * Get Products matching stock criteria. 
  11. * @param int $current_page 
  12. * @param int $per_page 
  13. */ 
  14. public function get_items( $current_page, $per_page ) { 
  15. global $wpdb; 
  16.  
  17. $this->max_items = 0; 
  18. $this->items = array(); 
  19.  
  20. // Get products using a query - this is too advanced for get_posts :( 
  21. $stock = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 1 ) ); 
  22. $nostock = absint( max( get_option( 'woocommerce_notify_no_stock_amount' ), 0 ) ); 
  23.  
  24. $query_from = apply_filters( 'woocommerce_report_low_in_stock_query_from', "FROM {$wpdb->posts} as posts 
  25. INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id 
  26. INNER JOIN {$wpdb->postmeta} AS postmeta2 ON posts.ID = postmeta2.post_id 
  27. WHERE 1=1 
  28. AND posts.post_type IN ( 'product', 'product_variation' ) 
  29. AND posts.post_status = 'publish' 
  30. AND postmeta2.meta_key = '_manage_stock' AND postmeta2.meta_value = 'yes' 
  31. AND postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) <= '{$stock}' 
  32. AND postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) > '{$nostock}' 
  33. " ); 
  34.  
  35. $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 posts.post_title DESC LIMIT %d, %d;", ( $current_page - 1 ) * $per_page, $per_page ) ); 
  36. $this->max_items = $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" );