Automattic\WooCommerce\Admin\API\Reports\Stock
Controller::add_wp_query_filter
Add in conditional search filters for products.
Method of the class: Controller{}
No Hooks.
Returns
String.
Usage
$result = Controller::add_wp_query_filter( $where, $wp_query );
- $where(string) (required)
- Where clause used to search posts.
- $wp_query(object) (required)
- WP_Query object.
Controller::add_wp_query_filter() Controller::add wp query filter code WC 10.6.2
public static function add_wp_query_filter( $where, $wp_query ) {
global $wpdb;
$stock_status = $wp_query->get( 'stock_status' );
if ( $stock_status ) {
$where .= $wpdb->prepare(
' AND wc_product_meta_lookup.stock_status = %s ',
$stock_status
);
}
if ( $wp_query->get( 'low_in_stock' ) ) {
// We want products with stock < low stock amount, but greater than no stock amount.
$no_stock_amount = absint( max( get_option( 'woocommerce_notify_no_stock_amount' ), 0 ) );
$low_stock_amount = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 1 ) );
$where .= "
AND wc_product_meta_lookup.stock_quantity IS NOT NULL
AND wc_product_meta_lookup.stock_status = 'instock'
AND (
(
low_stock_amount_meta.meta_value > ''
AND wc_product_meta_lookup.stock_quantity <= CAST(low_stock_amount_meta.meta_value AS SIGNED)
AND wc_product_meta_lookup.stock_quantity > {$no_stock_amount}
)
OR (
(
low_stock_amount_meta.meta_value IS NULL OR low_stock_amount_meta.meta_value <= ''
)
AND wc_product_meta_lookup.stock_quantity <= {$low_stock_amount}
AND wc_product_meta_lookup.stock_quantity > {$no_stock_amount}
)
)";
}
return $where;
}