- Status
- Open
- Reported for
- WPML Multilingual & Multicurrency for WooCommerce 5.3.2
- Topic tags
- Bug
Overview of the issue
The WooCommerce Status Dashboard widget may display an incorrect count for products that are low in stock. This issue arises when products are translated, as the widget counts translations of a product as separate items.
Workaround
Please, make sure of having a full backup of your site before proceeding.
- Open your theme’s functions.php file.
- Add the following code:
add_filter( 'woocommerce_status_widget_low_in_stock_count_pre_query', 'filter_counts' ); function filter_counts( $var ){ global $wpdb; $stock = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 1 ) ); $nostock = absint( max( get_option( 'woocommerce_notify_no_stock_amount' ), 0 ) ); $lowinstock_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( product_id ) FROM {$wpdb->wc_product_meta_lookup} AS lookup INNER JOIN {$wpdb->posts} as posts ON lookup.product_id = posts.ID INNER JOIN {$wpdb->prefix}icl_translations as translations ON posts.ID=translations.element_id WHERE stock_quantity <= %d AND stock_quantity > %d AND posts.post_status = 'publish' AND translations.source_language_code IS NULL", $stock, $nostock ) ); return $lowinstock_count; }