1 <?php
2 if ( ! defined( 'ABSPATH' ) )
3 exit;
4
5 if ( ! class_exists( 'WC_Report_Stock' ) )
6 require_once( 'class-wc-report-stock.php' );
7
8 9 10 11 12 13 14 15
16 class WC_Report_Out_Of_Stock extends WC_Report_Stock {
17
18 19 20
21 public function no_items() {
22 _e( 'No out of stock products found.', 'woocommerce' );
23 }
24
25 26 27 28 29
30 public function get_items( $current_page, $per_page ) {
31 global $wpdb;
32
33 $this->max_items = 0;
34 $this->items = array();
35
36
37 $stock = absint( max( get_option( 'woocommerce_notify_no_stock_amount' ), 0 ) );
38
39 $query_from = "FROM {$wpdb->posts} as posts
40 INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id
41 INNER JOIN {$wpdb->postmeta} AS postmeta2 ON posts.ID = postmeta2.post_id
42 WHERE 1=1
43 AND posts.post_type IN ('product', 'product_variation')
44 AND posts.post_status = 'publish'
45 AND (
46 postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) <= '{$stock}' AND postmeta.meta_value != ''
47 )
48 AND (
49 ( postmeta2.meta_key = '_manage_stock' AND postmeta2.meta_value = 'yes' ) OR ( posts.post_type = 'product_variation' )
50 )
51 ";
52
53 $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 ) );
54 $this->max_items = $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" );
55 }
56 }