Skip Navigation

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

Problem:
The client was unable to filter out products from a specific category on the front page using WPML for their multilingual WooCommerce site. The provided code snippet worked in the default language (Czech) but not in the translated language (English).
Solution:
We pointed out that the English category had only one product translated, and for the filter to take effect in the second language, the client needed to translate the rest of the products.
If this solution doesn't look relevant, please open a new support ticket.

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 7 replies, has 2 voices.

Last updated by janP-65 1 year, 3 months ago.

Assisted by: Andreas W..

Author Posts
January 16, 2024 at 7:56 pm #15192019

janP-65

Can not confirm the issue on sandbox:
hidden link

About to take a copy of the client's site for testing

January 16, 2024 at 9:23 pm #15192259

Andreas W.
WPML Supporter since 12/2018

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Hello,

I would like to offer to have a closer look at the problem and request temporary access (wp-admin and FTP) to the website to investigate this issue further.

You can find the required fields below the comment section when you log in to leave the next reply. The information you provide is private, which means only you and I can see and access it.

IMPORTANT
Please be sure to make a backup copy of the website and database before allowing us access.
If you can't see the wp-admin / FTP fields, your post and website credentials are set as PUBLIC. DO NOT publish the data unless you see the required wp-admin / FTP fields.

I may have to install a plugin called "All In One WP Migration" to make a copy of the website where I can investigate the issue further.

However, I would also be very grateful if you could provide a staging site or copy of the website from your server yourself for this purpose.

If you have any questions about creating such a staging site, you can consult your hosting provider. Just take note that WPML should be registered on this site again.

If you are unable to provide such a copy of the site for testing, please let me know on this ticket.

The private response form looks like this:
hidden link

Next time you reply, click "I still need assistance."

Video:
hidden link

Please note that we are obliged to request this information individually on each ticket. We may not access any access information not specifically submitted on this ticket in the private response form.

Best regards
Andreas

January 17, 2024 at 9:47 am #15193837

janP-65

I would like to add there is also issue with filtering product on translated version of woocommerce. With default language filters are present but in translated language are not. Please see attached screenshots. Filters based on tags works, filters based on attributes does not.
I'm not sure, but WP implements attributes in same way as categories, so it might be releated to my issue mentioned above.

default_lang.png
translated_lang.png
January 17, 2024 at 2:59 pm #15195647

Andreas W.
WPML Supporter since 12/2018

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Hello,

A questions:

You are using this snippet:

// Hide products in specific category on front page
		add_filter( 'woocommerce_product_query_tax_query', 'exclude_products_from_fp', 10, 2 );
		function exclude_products_from_fp( $tax_query, $query ) {
			$tax_query[] = array(
				'taxonomy'  => 'product_cat',
				'field'     => 'term_id',
				'terms'     => array('125'),
				'operator'  => 'NOT IN',
			);
		return $tax_query;
		}

This is trying to hide the English translation of the product category Vinyl.

According to my test, you will need to use the ID of the original category and then hide both in both languages.

Are you trying to achieve to hide "Vinyl" only in English?

Best regards
Andreas

January 17, 2024 at 3:13 pm #15195691

janP-65

that is residue of my previous debugging of this issue. My goal is to hide product category "Merchandise" on front page in both languages.

This is my original approach:

// Hide products in specific category on front page
add_filter( 'woocommerce_product_query_tax_query', 'exclude_products_from_fp', 10, 2 );
function exclude_products_from_fp( $tax_query, $query ) {
    if( is_front_page() ){ // this also might be a issue, is '/en' considered as frontpage?
        $tax_query[] = array(
            'taxonomy'  => 'product_cat',
            'field'     => 'slug',
            'terms'     => array('merchandise'), // 'merchandise-en' also doesn't work on english lang
             'operator'  => 'NOT IN',
        );
    }
    return $tax_query;
}
January 17, 2024 at 3:26 pm #15195710

Andreas W.
WPML Supporter since 12/2018

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Then this does the job:

// Hide products in specific category on front page
		add_filter( 'woocommerce_product_query_tax_query', 'exclude_products_from_fp', 10, 2 );
		function exclude_products_from_fp( $tax_query, $query ) {
			$tax_query[] = array(
				'taxonomy'  => 'product_cat',
				'field'     => 'term_id',
				'terms'     => array('58'),
				'operator'  => 'NOT IN',
			);
		return $tax_query;
		}

But I see it does not work in English this way. I will keep testing.

January 17, 2024 at 3:34 pm #15195791

Andreas W.
WPML Supporter since 12/2018

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Your English category only has a product count of "1" as only one product is translated.

You need to translate the products to have the filter take effect in the second language.

January 20, 2024 at 12:53 pm #15207138

janP-65

I confirm, it works. Thank you for your assistance