Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 15:00 9:00 – 15:00 9:00 – 15:00 9:00 – 15:00 9:00 – 15:00 - -
- - - - - - -

Supporter timezone: Asia/Yerevan (GMT+04:00)

This topic contains 6 replies, has 2 voices.

Last updated by Christopher Amirian 1 year, 2 months ago.

Assisted by: Christopher Amirian.

Author Posts
December 6, 2023 at 6:32 pm #15011529

dmitrijsH

Hello,

In the admin dashboard (Woocommerce status box), the low stock products are counted in all the languages. For example, the screenshot below shows 36 products out of stock whereas in the reality there are 14 low stock products + translations.

Please let me know how to avoid triple-counting.

Kind regards,

low stock count.png
December 9, 2023 at 10:28 am #15028765

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

Would you please follow the steps below?

- IMPORTANT STEP! Create a backup of your website. Or better approach will be to test this on a copy/staging version of the website to avoid any disruption of a live website.
- Go to "WordPress Dashboard > Plugins" and deactivate all plugins except Woocommerce, Woocommerce Multilingual, WPML Multilingual CMS and WPML String Translation.
- Check if you can still recreate the issue.
- If not, re-activate your plugins one by one and check the issue each time to find out the plugin that causes the problem.

If the issue persists, please see if the workaround below works? (it is for another synching issue with stock status, not exactly yours which is counting both original and translated ones)

https://wpml.org/forums/topic/stock-status-doesnt-change-when-order-placed-on-2nd-language/#post-12896941

Make sure you have a backup before following the steps above.

If the issue still persists, I'd appreciate it if you could replicate the issue on the clean installation below so I can report this to second-tier support.

I installed WordPress, WPML, Woocommerce, and Woocommerce Multilingual and imported some sample products.

hidden link

Thanks.

December 9, 2023 at 11:16 am #15028975

dmitrijsH

Hello,

I tried on my stage site, no luck and then I went to your sandbox.

I translated sunglasses and set it to low stock (1 pc). The box shows that there are two products low in stock but it is only one item + one translation. Please see the image.

Kind regards,

Screenshot 2023-12-09 121444.png
December 10, 2023 at 2:55 pm #15031545

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

Thank you. I reported this. I will get back to you as soon sI have an update.

Thanks.

December 13, 2023 at 1:01 pm #15054775

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

The issue is escalated to the developers to fix.

For now, you can use the workaround below.

Add the code below to the functions.php of your theme:

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;
}

Thanks.

December 15, 2023 at 10:42 pm #15076207

dmitrijsH

Hello,

Thank you. The snippet has helped for the low stock products. It would be great to have it in one of the next plugin updates.

Kind regards,

December 16, 2023 at 11:47 am #15077223

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

Yes, that is the plan.

Thanks.