Skip Navigation

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

Problem:
You are trying to use a product tag as a display rule in GeneratePress, but WPML is not replacing the product tag ID from the default language to the translated language product tag ID during translation. This issue occurs because WPML is copying _generate_element_display_conditions 1:1 without replacing the product tag ID.
Solution:
To resolve this issue, you need to modify the GeneratePress conditions file to include a WPML filter that correctly translates the product tag ID. Here are the steps:
1. Open the

app/public/wp-content/plugins/gp-premium/elements/class-conditions.php

file.
2. Locate the

Show depending on location conditionals

section around line 327.
3. Replace the existing code with the following snippet to include a WPML workaround:

// Show depending on location conditionals.<br />if ( ! $show ) {<br />foreach ( (array) $conditionals as $conditional ) {<br />// WPML Workaround for compsupp-7507<br />if ( class_exists('Sitepress') ) {<br /><br />$post_type = get_post_type( $conditional['object'] );<br />$term = get_term( $conditional['object'] );<br /><br />if ( $conditional['rule'] == 'product:taxonomy:product_tag' && $term && ! is_wp_error( $term ) ) {<br />$conditional['object'] = apply_filters( 'wpml_object_id', $conditional['object'], $term->taxonomy, TRUE );<br />}<br />else if ( $post_type ) {<br />$conditional['object'] = apply_filters( 'wpml_object_id', $conditional['object'], $post_type, TRUE );<br />} else if ( $term && ! is_wp_error( $term ) ) {<br />$conditional['object'] = apply_filters( 'wpml_object_id', $conditional['object'], $term->taxonomy, TRUE );<br />}<br />}<br />

This modification should ensure that WPML correctly translates the product tag ID in _generate_element_display_conditions.

If this solution does not apply to your case, or if it seems outdated, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If you still need assistance, please open a new support ticket at WPML 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 6 replies, has 2 voices.

Last updated by Osama Mersal 7 months, 1 week ago.

Assisted by: Osama Mersal.

Author Posts
July 26, 2024 at 5:06 pm #16009464

dawidZ-5

Background of the issue:
I am trying to use the product tag as a display rule for an element in GeneratePress. GeneratePress saves this display location to _generate_element_display_conditions in wp_postmeta with my selected product_tag id from the default language. The array looks like this: array ( 0 => array ( 'rule' => 'product:taxonomy:product_tag', 'object' => '202', ), ). During translation, WPML is copying _generate_element_display_conditions 1:1 without replacing the product_tag id from the default language to the translated language product_tag id.

Symptoms:
WPML is not replacing the product_tag id from the default language to the translated language product_tag id during translation.

Questions:
Why is WPML not replacing the product_tag id from the default language to the translated language product_tag id?
How can I ensure that WPML correctly translates the product_tag id in _generate_element_display_conditions?

July 28, 2024 at 1:09 pm #16012170

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

Thanks for contacting WPML forums support. I'll be glad to help you today.

First of all, sorry for the late reply; it was due to a higher workload.

Please hidden link">log in to this sandbox and install the GeneratePress plugin.

After that, please try to replicate the issue. If it's replicable, please let me know how to reproduce it so I can consult our compatibility team.

Best regards,
Osama

July 29, 2024 at 1:04 pm #16016164

dawidZ-5

To reproduce:
1. Create product and translate that product
2. Create product tag and translate tag
3. add tag to product
4. Create generatepress element
5. select product tag as display rules
6. translate generatepress element

generatepress element is visible only on default language (English) product

July 29, 2024 at 2:57 pm #16016746

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

Thanks for replicating the issue. I checked the issue and found a workaround using a manual approach.

Please check the following steps:

1- Edit the translated element using the WP editor
2- Select the translated tag
3- Check the translated product on the front end

I'll consult our compatibility team regarding this issue and check if they have another workaround.

Best regards,
Osama

August 7, 2024 at 2:51 pm #16048719

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

Thanks for your patience. Please check the following steps:

1- Open the app/public/wp-content/plugins/gp-premium/elements/class-conditions.php file
2- Inside GeneratePress_Conditions::show_data(), look for the following snippet (around line 327):

// Show depending on location conditionals.
if ( ! $show ) {
	foreach ( (array) $conditionals as $conditional ) {

3- Replace it with:

// Show depending on location conditionals.
if ( ! $show ) {
	foreach ( (array) $conditionals as $conditional ) {
// WPML Workaround for compsupp-7507
if ( class_exists('Sitepress') ) {

	$post_type = get_post_type( $conditional['object'] );
	$term = get_term( $conditional['object'] );

	if ( $conditional['rule'] == 'product:taxonomy:product_tag' && $term && ! is_wp_error( $term ) ) {
		$conditional['object'] = apply_filters( 'wpml_object_id', $conditional['object'], $term->taxonomy, TRUE );
	}
	else if ( $post_type ) {
		$conditional['object'] = apply_filters( 'wpml_object_id', $conditional['object'], $post_type, TRUE );
	} else if ( $term && ! is_wp_error( $term ) ) {
		$conditional['object'] = apply_filters( 'wpml_object_id', $conditional['object'], $term->taxonomy, TRUE );
	}
}

I've applied the steps to the sandbox site. Kindly check this hidden link">page.

Best regards,
Osama

August 7, 2024 at 3:49 pm #16049097

dawidZ-5

Hi,
I tested this issue on the Sandbox site and the fix works there.

Will this fix be included in the next update?
Because if I manually replace the contents of the plug-in file, it will be overwritten on the next update.

August 7, 2024 at 5:34 pm #16049524

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

This fix is in the GeneratePress files, not the WPML files, so we will contact the author and let him know our findings. However, I don't know if it will be added in the next version.

Best regards,
Osama