Please make sure to update to WPML 4.3.5 and check our list of Known Issues before reporting

Hi, Amit here, I am the WPML Support Manager, our current ticket queue is high, update your WPML plugins and make sure you meet the minimal requirements for running WPML before reporting an issue please - many tickets are resolved doing that

Please look at our updated list of Known Issues and you can also use our support search to find helpful information and of course review our documentation before opening a ticket.

If you do need to open a ticket please make sure to provide us with all the needed information as described in this page

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.

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

Problem:

The plugin is not compatible but works out of the box. But you need to translate the related products IDs by setting the _wcrp_related_ids to 'Translate'. The following steps will EliminatE the need to translate the _wcrp_related_ids field with Woocommerce custom related product Version 1.3.2.

Solution:

1. Edit the /wp-content/plugins/woo-custom-related-products/woocommerce/single-product/related.php file with your code editor.

2. Move line 29 to line 21.

global $post;

3. Replace line 22 with:

if ($related_products || get_post_meta($post->ID, '_wcrp_related_ids')) :

4. Add the following line after line number 44:

$related_product = apply_filters('wpml_object_id', $related_product, 'product', true);

5. Make sure that the field _wcrp_related_ids is set to 'Copy'.

6. Update the original product and its translation.

Now you should be able to see the correct and translated related products.

This workaround might not work anymore if you update the Woocommerce custom related product plugin. We will not support or maintain this workaround.

This topic contains 15 replies, has 2 voices.

Last updated by Kristoff Henry 2 weeks, 3 days ago.

Assigned support staff: Itamar.

Author Posts
August 5, 2019 at 7:27 pm #4342789

Kristoff Henry

I am trying to: have custom related product appear automatically on translated products

Link to a page where the issue can be seen:
hidden link
and translation:
hidden link
hidden link

I expected to see:
the related products (translated) listed at the bottom of the page on the translated pages as wel

Instead, I got: no related products

I refer to my earlier support thread when the site was still under development:
https://wpml.org/forums/topic/custom-related-products-only-partially-translated-2/
Then I got it to work, now it no longer works. I have recreated all steps of the above support thread, but still nothing appears.

August 6, 2019 at 9:33 am #4345791

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi.

I've read the other ticket and also our internal documentation about this case.
First please check that it is not a cache issue by clearing all the cache on your site.

I can see that the version of Woo Custom Related Products has changed to 1.3.2. So it might be that things have changed on the plugin's files and the workaround does not work anymore. For this, we'll need once again to replicate the issue on a clean WordPress installation.

I created a test website with a clean WordPress install. You can access it through this link:
hidden link
Through this link, you will be automatically logged in. (If nobody logs in the test site will be available for one week from today.)
Could you please install the Woo Custom Related Products and see if the issue is replicable on a clean WordPress installation?
Please configures WPML as it is configured on your site.
Please also make sure that you are installing the latest version of the plugin.

Another thing that you can check, although it is not the desired solution, is if things work if you downgrade the Woo Custom Related Products to the previous version.

I look forward to your reply!

Itamar.

August 13, 2019 at 10:48 am #4387135

Kristoff Henry

Hi Itamar,

I tried to replicate the issue on the sandbox site but didn't succeed.
In the mean time I also did a lot of testing on a staging version of the live site and found the strangest behaviour: re-installing the previous version of the woocommerce related product plug-in did not solve the problem.

However this is what I found:

- If I deactivate the woocommerce related product plug-in, all related products re-appear on the translated pages.
- When I then re-activate the plug-in the re-appeared related products are still there on the translated pages, but only for the products visited when the plugin was deactivated.
- This is not stable, related products tend to disappear after a while, sometimes in one, sometimes in both translated languages.
- Deleting cache files or clearing cache for a page during the proces does not change anything.

Please advise

Kind regards,
Kristoff

August 13, 2019 at 5:56 pm #4390109

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi, Kristoff.

Currently, when I check the links that you gave me to where I can see the issue, it seems that the issue is solved. I can see the related products. Please see the attached screenshots.
At the beginning of this thread, I couldn't see them.
Can you see that it is OK now?
Have you fixed this issue already?

Regards,
Itamar.

August 13, 2019 at 9:17 pm #4390827

Kristoff Henry

No Itamar,
I haven’t solved the issue

It is because I deactivated the plugin like I explained above. But that is hardly the solution 🙂

Kind regards,
Kristoff

August 14, 2019 at 8:43 pm #4397441

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi.

This is weird. I don't understand how the related products still show if you deactivate the plugin (woocommerce related product ) that is in charge of displaying them.
Is this the plugin that you have the issue with?
https://wordpress.org/plugins/woo-custom-related-products/

Can you please try the following procedure?
I suspect that there is a collision with the theme or another plugin that might cause this problem. If possible, get your site into a minimum environment. Minimum environment means switching to a default WordPress theme like Twentyseventeen and no plugins activated except WPML, WooCommerce without it add-ons except the WooCommerce Custom Related Products plugin.
Is it possible for you to try it?
You will need first to check if the problem persists when just the theme is switched to Twentyseventeen (for example). If it persists then deactivate all plugins except the WPML and its add-ons and WooCommerce itself. Then please check if the problem persists. If it does not persist, so start by activating the plugins one by one and check when the problem comes back, then report to me which was the culprit plugin.

**** Important! Please make a full site backup (files and DB) before you proceed with those steps****


*** If your site is a live site you might want first to try those procedures in a staging environment or a snapshot of your site on your local server or another server. ***

Note: I'll be able to reply here early next week.

Thank you for your patience,
Itamar.

August 22, 2019 at 2:46 pm #4440517

Kristoff Henry

Hi Itamar,

I worked on a clone of the site and it seems that when I turn off the "WooCommerce Multilingual" plug-in that the custom related products re-appear on the translated pages. So there seems to be something not quite right there.

I then went to the live site and switched off that same plug-in and got the same result.
So I left it off for the time being, but of course would need to solve the root cause.

Hope this helps!

August 25, 2019 at 9:34 am #4453741

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi.

I'm sorry for not understanding which plugin you deactivated. I now understand that you are talking about the WooCommerce Multilingual plugin. When working with WPML and WooCommerce, this plugin needs to be active. So, of course, that we need to continue to debug this issue and see where the problem is.

Can you please confirm that after updating the Woo Custom Related Products plugin to its latest version, you again implemented all the workarounds that were suggested on the previous ticket here?
https://wpml.org/forums/topic/custom-related-products-only-partially-translated-2/

Also, it is not clear to me whether you have tried my suggestion from the last reply about the minimum environment. Please update me on this as well.

If you still need help from me and my above suggestion not solving the issue, please share with me access to the staging site that you have where the issue can be replicated.

If you need further help with this, please share the access details to your site with me.
I'm enabling a private message for the next reply.

Privacy and Security Policy

We have strict policies regarding privacy and access to your information. Please see:
https://wpml.org/purchase/support-policy/privacy-and-security-when-providing-debug-information-for-support/

**IMPORTANT**

- - Please make a backup of site files and database before providing us access. --

Thanks,
Itamar.

August 27, 2019 at 5:52 pm #4468849

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi, Kristoff.

I can see the issue on your staging site. When WooCommerce Multilingual is active, the related products do not show.
Can you please confirm that the field that I'm showing on the screenshot is where you insert the related products?

In this thread when I asked you to try and replicate the issue on a sandbox site you wrote to me this: "I tried to replicate the issue on the sandbox site but didn't succeed."
Does it mean that the issue didn't happen on the sandbox site?
Did the related products shown for the translated product?

Meanwhile, I'm consulting our compatibility developer about this issue.

Thanks,
Itamar.

August 27, 2019 at 7:33 pm #4469449

Kristoff Henry

Hi Itamar,

Yes, this is indeed the field where I am inserting the related products.

On the sandbox account I wasn't able to replicate the issue and yes, products appeared. The site with the problem is quite a large site with a lot of settings in WPML and I tried to replicate as best as I could, but cannot guarantee it was an exact copy.

Honestly, I've spent numerous hours already during the last couple of months on various copies of the site trying to replicate, pin down the root cause or solve this issue, that I am beginning despair.

Hope you can help

August 29, 2019 at 1:53 pm #4481521

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi.

First, please let me start by noting here the summary of this issue that began with the other ticket that you had opened when you first encountered the problem. It is this ticket.
https://wpml.org/forums/topic/custom-related-products-only-partially-translated-2/

1. The Woo Custom Related Products plugin is not officially compatible with WooCommerce Multilingual. I'm not sure if it was mentioned before, but it is important to mention it.

2. You had a problem with this plugin because it didn't work as expected on the translated products.

3. A first solution was given to you. The solution was to set the _wcrp_related_ids to 'Translate'.

4. You asked for a better solution as the first one would require a lot of work from you.

5. We offered a second solution. A custom solution. The solution was to add the following line at this file of the plugin wp-content/plugins/woo-custom-related-products/woocommerce/single-product/related.php after line 44.

$related_product = apply_filters('wpml_object_id', $related_product, 'product', true);

6. The solution was working on our test site but was not working on your site.

7. We've continued to help you, and we found that the problem is that you are overwriting the template in your child theme here: /symo-theme/woocommerce/single-product/related.php. So we specified that the fix should go there.

8. And this solved the issue on your site.

9. With the latest version of Woo Custom Related Products 1.3.2, the issue (or a variant of it) appeared again, and you asked us to help you still.

10. I've discussed this issue with our compatibility second-tier supporter. And he asked me to try and replicate the issue on a fresh WordPress installation with the latest version of Woo Custom Related Products (1.3.2).

11. I could replicate the issue on the fresh installation. The new version of Woo Custom Related Products 1.3.2 is not working with the custom fix we have provided before. It does still work if you set the _wcrp_related_ids field to 'Translate'.

12. Therefore I've escalated the issue once again to our compatibility team.

I need to emphasize the following. Our support policy at the following link states that we cannot produce custom code solutions for our users. When you need custom coding, which extends WPML functionality, we recommend using our WPML certified contractors system. https://wpml.org/contractors/. And also the help that we can give for compatibility issues is limited. Especially if the plugin is not officially compatible with WPML as the Woo Custom Related Products plugin. So if our compatibility team would be able once more to find a custom fix for this issue then, of course, that I'll share it with you here. But please let me add the following disclaimer. We will not be able to support this fix in the future in case it will not work anymore.. If our compatibility team is not able to find a fix this time, then we will not be able to help anymore. If that were the case, I would suggest you consider contacting one of our certified partners from this link: https://wpml.org/contractors/
With our contractors, you might get the custom assistance you need to get on with your project.

I'll keep you updated here when I have a response from our compatibility team.

Best Regards,
Itamar.

September 3, 2019 at 12:29 pm #4504439

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi.

Here is the workaround as suggested by our compatibility developer.

1. Edit the /wp-content/plugins/woo-custom-related-products/woocommerce/single-product/related.php file with your code editor.

2. Move line 29 to line 21.

global $post;

3. Replace line 22 with:

if ($related_products || get_post_meta($post->ID, '_wcrp_related_ids')) :

4. Add the following line after line number 44:

$related_product = apply_filters('wpml_object_id', $related_product, 'product', true);

5. Make sure that the field _wcrp_related_ids is set to 'Copy'.

6. Update the original product and its translation.

Now you should be able to see the correct and translated related products.
It worked for me on this new test site. You can see this product, for example.
hidden link
If you want to check things on this test site here is the link to the admin section.
hidden link

I hope that this workaround is helpful to you.

Regards,
Itamar.

September 6, 2019 at 7:52 pm #4527209

Kristoff Henry

My issue is resolved now. Thank you!

September 8, 2019 at 9:15 am #4530997

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Great, I'm glad that it is solved now!
Good luck with your web projects 🙂
Itamar.

November 20, 2019 at 10:19 am #4978577

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

For anyone who might have this issue. Here is what our compatibility developer write.

We put together a small snippet that translates the related product ids on the fly to make it work:

add_action( 'init', 'wcrp_wpml_loaded' );
function wcrp_wpml_loaded() {
	if ( apply_filters( 'wpml_setting', false, 'setup_complete' ) ) {
		add_filter( 'get_post_metadata', 'wcrp_translate_related_ids', 10, 4 );
	}
}
function wcrp_translate_related_ids( $value, $post_id, $meta_key, $single ) {
	global $wpdb;

	if ( '_wcrp_related_ids' === $meta_key ) {
		$ids = maybe_unserialize( $wpdb->get_var( $wpdb->prepare(
			"SELECT meta_value FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s",
			$post_id,
			$meta_key
		) ) );
		$value = array();
		foreach ( $ids as $id ) {
			$value[] = apply_filters( 'wpml_object_id', $id, get_post_type( $id ), true );
		}
		$value = array( $value );
	}

	return $value;
}

f you have a child theme, you can place this code in functions.php in the child theme. This is the quickest way.
You can see David's post here.
https://wordpress.org/support/topic/wpml-compatibility-164/#post-12147441