2013-07-09 10:48:56 +00:00
< ? php
2019-03-12 22:26:53 +00:00
/**
* WC_Report_Low_In_Stock .
*
2020-08-05 16:36:24 +00:00
* @ package WooCommerce\Admin\Reports
2019-03-12 22:26:53 +00:00
*/
2014-09-20 19:58:32 +00:00
2019-03-12 22:26:53 +00:00
defined ( 'ABSPATH' ) || exit ;
2013-07-09 10:48:56 +00:00
2014-09-20 19:58:32 +00:00
if ( ! class_exists ( 'WC_Report_Stock' ) ) {
2018-03-05 18:59:17 +00:00
require_once dirname ( __FILE__ ) . '/class-wc-report-stock.php' ;
2014-09-20 19:58:32 +00:00
}
2013-07-09 10:48:56 +00:00
/**
2019-03-12 22:26:53 +00:00
* Low stock report class .
2013-07-09 10:48:56 +00:00
*/
class WC_Report_Low_In_Stock extends WC_Report_Stock {
2014-08-31 07:19:13 +00:00
/**
2015-11-03 12:28:01 +00:00
* No items found text .
2014-08-31 07:19:13 +00:00
*/
public function no_items () {
2019-03-12 22:26:53 +00:00
esc_html_e ( 'No low in stock products found.' , 'woocommerce' );
2014-08-31 07:19:13 +00:00
}
/**
2015-11-03 12:28:01 +00:00
* Get Products matching stock criteria .
2016-01-05 10:08:12 +00:00
*
2019-03-12 22:26:53 +00:00
* @ param int $current_page Current page number .
* @ param int $per_page How many results to show per page .
2014-08-31 07:19:13 +00:00
*/
public function get_items ( $current_page , $per_page ) {
global $wpdb ;
2013-07-09 10:48:56 +00:00
$this -> max_items = 0 ;
$this -> items = array ();
$stock = absint ( max ( get_option ( 'woocommerce_notify_low_stock_amount' ), 1 ) );
$nostock = absint ( max ( get_option ( 'woocommerce_notify_no_stock_amount' ), 0 ) );
2018-03-05 18:59:17 +00:00
$query_from = apply_filters (
2019-03-12 22:26:46 +00:00
'woocommerce_report_low_in_stock_query_from' ,
$wpdb -> prepare (
"
FROM { $wpdb -> posts } as posts
INNER JOIN { $wpdb -> wc_product_meta_lookup } AS lookup ON posts . ID = lookup . product_id
WHERE 1 = 1
AND posts . post_type IN ( 'product' , 'product_variation' )
AND posts . post_status = 'publish'
AND lookup . stock_quantity <= % d
AND lookup . stock_quantity > % d
" ,
$stock ,
$nostock
)
2018-03-05 18:59:17 +00:00
);
2015-01-13 13:34:48 +00:00
2019-03-13 10:06:49 +00:00
$this -> items = $wpdb -> get_results ( $wpdb -> prepare ( " SELECT SQL_CALC_FOUND_ROWS posts.ID as id, posts.post_parent as parent { $query_from } ORDER BY posts.post_title DESC LIMIT %d, %d; " , ( $current_page - 1 ) * $per_page , $per_page ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$this -> max_items = $wpdb -> get_var ( 'SELECT FOUND_ROWS();' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
2014-08-31 07:19:13 +00:00
}
}