Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
If you're experiencing an issue where your shopping cart works fine when WPML is deactivated, but you encounter an error with WooCommerce Multilingual activated, it might be due to a compatibility problem with the OnSale Page for WooCommerce plugin.

Solution:
The error occurs in the

pre_get_posts

method within the OnSale Page for WooCommerce plugin. The plugin is passing a NULL value because it expects a non-NULL return which WPML does not provide. To fix this, you can modify the plugin's code as follows:

public function pre_get_posts( $q ) {<br />if(!$q->query)<br />return;<br />$onsale_page_id = $this->get_main_wpml_id(wc_get_page_id( 'onsale' ));<br />if($onsale_page_id != -1 && $onsale_page_id != NULL){

This is a temporary workaround. Since the plugin is not compatible with WPML, you can suggest that the plugin's authors join our Go Global Program to achieve compatibility. Alternatively, you can contact the plugin's support for a permanent solution.

If this solution doesn't seem relevant to your issue, please open a new support ticket in our support forum.

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.

Tagged: 

This topic contains 15 replies, has 2 voices.

Last updated by Bruno Kos 1 year, 5 months ago.

Assisted by: Bruno Kos.

Author Posts
January 22, 2024 at 2:28 pm #15212069

Bruno Kos
WPML Supporter since 12/2018

Languages: English (English ) German (Deutsch ) French (Français )

Timezone: Europe/Zagreb (GMT+02:00)

The issue is with OnSale Page for WooCommerce (https://wordpress.org/plugins/on-sale-page-for-woocommerce/)

The problem is in \Woocommerce_onsale_page_Public::pre_get_posts in wp-content/plugins/on-sale-page-for-woocommerce/public/class-woocommerce-onsale-page-public.php

There they do:

	public function pre_get_posts( $q ) {
		
		if(!$q->query)
			return;
		$onsale_page_id = $this->get_main_wpml_id(wc_get_page_id( 'onsale' )); 
				
		if($onsale_page_id != -1 ){

However, because the value is not set, and because they pass it to custom logic that tries to obtain value (WPML never returns -1 for example) the value returned is NULL
So the logic below is executed and corrupts the query.

Instead of the above you can do:

	public function pre_get_posts( $q ) {
		
		if(!$q->query)
			return;
		$onsale_page_id = $this->get_main_wpml_id(wc_get_page_id( 'onsale' )); 
				
		if($onsale_page_id != -1 && $onsale_page_id != NULL){

However the plugin is not compatible with WPML so you can ask them to join our https://wpml.org/documentation/support/go-global-program/ or use the above workaround until they resolve it (if they are interested, you can open a support thread with them also).

January 26, 2024 at 4:22 pm #15231158

gavinT-6

we deactivated and deleted the woo commerce on sale page and the cart and the page returned to working order.
thanks to Amit and WPML for their work. Gavin