Fix low stock report due to NULL _low_stock_amount
Empty meta values are not stored from WC 3.6+. _low_stock_amount could be NULL. This fixes the low stock queries.
This commit is contained in:
parent
d4f1e6bbd8
commit
684c526d1e
|
@ -129,16 +129,19 @@ class WC_Admin_REST_Products_Controller extends WC_REST_Products_Controller {
|
|||
|
||||
if ( $wp_query->get( 'low_in_stock' ) ) {
|
||||
$low_stock_amount = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 1 ) );
|
||||
$where .= " AND lis_postmeta2.meta_key = '_manage_stock'
|
||||
AND lis_postmeta2.meta_value = 'yes'
|
||||
AND lis_postmeta.meta_key = '_stock'
|
||||
AND lis_postmeta.meta_value IS NOT NULL
|
||||
AND lis_postmeta3.meta_key = '_low_stock_amount'
|
||||
$where .= "
|
||||
AND manage_stock_meta.meta_value = 'yes'
|
||||
AND stock_meta.meta_value IS NOT NULL
|
||||
AND (
|
||||
lis_postmeta3.meta_value > ''
|
||||
AND CAST(lis_postmeta.meta_value AS SIGNED) <= CAST(lis_postmeta3.meta_value AS SIGNED)
|
||||
OR lis_postmeta3.meta_value <= ''
|
||||
AND CAST(lis_postmeta.meta_value AS SIGNED) <= {$low_stock_amount}
|
||||
(
|
||||
low_stock_amount_meta.meta_value > ''
|
||||
AND CAST(stock_meta.meta_value AS SIGNED) <= CAST(stock_meta.meta_value AS SIGNED)
|
||||
)
|
||||
OR (
|
||||
low_stock_amount_meta.meta_value <= ''
|
||||
AND CAST(stock_meta.meta_value AS SIGNED) <= {$low_stock_amount}
|
||||
)
|
||||
OR low_stock_amount_meta.meta_value IS NULL
|
||||
)";
|
||||
}
|
||||
|
||||
|
@ -161,9 +164,10 @@ class WC_Admin_REST_Products_Controller extends WC_REST_Products_Controller {
|
|||
}
|
||||
|
||||
if ( $wp_query->get( 'low_in_stock' ) ) {
|
||||
$join .= " INNER JOIN {$wpdb->postmeta} AS lis_postmeta ON {$wpdb->posts}.ID = lis_postmeta.post_id
|
||||
INNER JOIN {$wpdb->postmeta} AS lis_postmeta2 ON {$wpdb->posts}.ID = lis_postmeta2.post_id
|
||||
INNER JOIN {$wpdb->postmeta} AS lis_postmeta3 ON {$wpdb->posts}.ID = lis_postmeta3.post_id";
|
||||
$join .= " INNER JOIN {$wpdb->postmeta} AS stock_meta ON {$wpdb->posts}.ID = stock_meta.post_id AND stock_meta.meta_key = '_stock'
|
||||
INNER JOIN {$wpdb->postmeta} AS manage_stock_meta ON {$wpdb->posts}.ID = manage_stock_meta.post_id AND manage_stock_meta.meta_key = '_manage_stock'
|
||||
LEFT JOIN {$wpdb->postmeta} AS low_stock_amount_meta ON {$wpdb->posts}.ID = low_stock_amount_meta.post_id AND low_stock_amount_meta.meta_key = '_low_stock_amount'
|
||||
";
|
||||
}
|
||||
|
||||
return $join;
|
||||
|
|
Loading…
Reference in New Issue