 Itamar
WPML Supporter since 02/2016
Languages:
English (English )
Timezone:
Asia/Jerusalem (GMT+03:00)
|
Hi,
Thanks for your response on this issue.
I'm sorry for forgetting to mention how to activate the "Multilingual Content Setup" option. You can activate it in WPML -> Settings -> Custom Fields Translation. See the option: Show "Multilingual Content Setup" meta box on post edit screen. Please see the attached screenshot.
But I understand your developers checked for custom fields but didn't find anything, correct?
In any case, I've passed on your findings to our compatibility team.
Regards,
Itamar.
|
 Giulio
|
I’m forwarding a screenshot showing, on the left, a product in the primary language, and on the right, the same product in a secondary language. This is the only relevant difference we’ve been able to identify so far.
Regarding the activation of the “Multilingual Content Setup” option – what exactly should we expect? I’m asking because we want to avoid any issues on our live site, so we’d like to understand in advance what will happen. We need to proceed cautiously if enabling a new option.
|
 Itamar
WPML Supporter since 02/2016
Languages:
English (English )
Timezone:
Asia/Jerusalem (GMT+03:00)
|
Hi,
Thanks for the screenshot.
You provided all the needed information, so you do not need to enable the “Multilingual Content Setup” option. In any case, and for your information, the “Multilingual Content Setup” option just allows the display of the custom fields on each post or page editing screen.
Our compatibility team developer explained the following:
If "_wc_facebooksync_enabled" is not set on the translation, it defaults to the plugin’s setting, which is "TRUE", meaning the translations will sync.
The client could change the plugin's default setting to "Don't sync," then manually update each product in the original language to "Sync." However, this would be tedious, manual work!
To summarize, Everything is working as expected, but we can escalate this as a feature request.
Please let us know if you want us to escalate this issue as a feature request to our developers.
Please consider that our developers might reject this request because they have a broader perspective. And even if they accept it, it might take time to release it.
Regards,
Itamar.
|
 Giulio
|
Alright, understood.
I’d definitely like to submit this as a feature request. It seems that with relatively little effort, we could achieve a significant improvement in performance.
I’d like to highlight once more that every time a product page is opened – in any language – a connection to Facebook is made.
Not to mention the feed that updates every 24 hours, which also consumes resources. Just imagine the impact this could have on large catalogues. I really think it’s worth looking into further…
Thank you for your attention and for the time you’ve dedicated to this matter.
|
 Itamar
WPML Supporter since 02/2016
Languages:
English (English )
Timezone:
Asia/Jerusalem (GMT+03:00)
|
Hi,
The issue has been escalated as a feature request to our compatibility team. However, they have found that Facebook for WooCommerce made the WPML integration. They are adding the WPML > Languages > Facebook Visibility section to our menu. We can still communicate the feature request, but it's out of our hands. Our compatibility team has checked their code and found the function is_product_sync_enabled:
public function is_product_sync_enabled() {
/**
* Filters whether product sync is enabled.
*
* @since 1.10.0
*
* @param bool $is_enabled whether product sync is enabled
* @param \WC_Facebookcommerce_Integration $integration the integration instance
*/
return (bool) apply_filters( 'wc_facebook_is_product_sync_enabled', 'yes' === get_option( self::SETTING_ENABLE_PRODUCT_SYNC, 'yes' ), $this );
}
Our compatibility developer said that maybe hooking a custom filter can work. He couldn't test it. But suggested you test it if you want:
add_filter( 'wc_facebook_is_product_sync_enabled', function( $is_enabled, $integration ) {
$product_id = $integration->get_product()->get_id();
$product_lang = apply_filters( 'wpml_post_language_details', null, $product_id );
if ( is_array( $product_lang ) && isset( $product_lang['language_code'] ) ) {
$default_lang = apply_filters( 'wpml_default_language', null );
if ( $product_lang['language_code'] !== $default_lang ) {
return false; // Block sync
}
}
return $is_enabled;
}, 10, 2 );
**** Important! Please make a full site backup (files and DB) before you proceed with those steps****
Since this seems to be out of our hands, but in the hands of Automatic (the authors of Facebook for WooCommerce), we want to set expectations. With another issue where the fix was in their code, we have already been waiting for a couple of years for it. You can learn about it here.
https://wpml.org/errata/facebook-for-woocommerce-multi-currency-is-not-supported/
hidden link
To possibly speed up things, we suggest you also contact them.
Best Regards,
Itamar.
|
 Giulio
|
Thank you, Itamar – and thanks to your colleague as well. Your support has been truly valuable. We’ll definitely run a test to see whether the filter works and can help us resolve the issue in question.
As for contacting Automattic, we’re frankly steering clear of that for the time being. We’ve also noticed from Facebook’s back-end that they’ve introduced a beta feature allowing for the management of different catalogue feeds based on language. We fear that reaching out to them might not lead to a solution and could end up being a waste of time.
Once again, thank you for your help – we really appreciate it.
|
 Giulio
|
Hi Itamar, I’m briefly reopening the thread to let you know that we’ve resolved the issue – although we had to modify your code to get it working properly.
Here’s a quick summary from our developer:
The original logic and the wc_facebook_is_product_sync_enabled hook could theoretically have worked – although it seems more suited to global synchronisation – but the implementation references a non-existent function, which caused an error as soon as the filter was activated.
After further investigation, we found another hook - wc_facebook_should_sync_product – which seemed more appropriate for our use case. We tested and implemented it, adding a small optimisation: to avoid repeated database queries, the default language is determined only once per request and reused for any subsequent calls.
When opening the backend of a product in English (a secondary language), the check now correctly identifies that the product should not be synchronised, and avoids running redundant checks within the same page load.
On the backend, viewing a product in the primary language shows no changes (Facebook for WooCommerce notifications and Meta product details remain visible). But when switching to a secondary language, the notification is no longer shown and the metabox updates accordingly.
Based on all this, it seems the modification is working as expected.
Thanks again for your support and availability!
add_filter( 'wc_facebook_should_sync_product', function( $should_sync, $product ) {
static $products;
static $default_lang;
if ( ! isset( $products ) ) {
// Initializing static variable
$products = [];
} elseif ( \in_array( $product->get_ID(), $products ) ) {
// Sync already stopped for this product
return false;
}
if ( ! isset( $default_lang ) ) {
// Getting standard lang only one time per hit, thanks to the static variable
$default_lang = apply_filters( 'wpml_default_language', null );
}
// Getting product lang and checking...
$product_lang = apply_filters( 'wpml_post_language_details', null, $product->get_ID() );
if (
$default_lang
&& is_array( $product_lang )
&& isset( $product_lang['language_code'] )
&& $product_lang['language_code'] !== $default_lang
) {
// Avoiding later checks in the same hit
$products[] = $product->get_ID();
// Stopping sync for this product
return false;
}
// Nothing done
return $should_sync;
}, 10, 2 );
|
 Itamar
WPML Supporter since 02/2016
Languages:
English (English )
Timezone:
Asia/Jerusalem (GMT+03:00)
|
Hi,
Thank you for taking the extra mile and sharing your solution with us!
I've sent it to our compatibility team.
Regards,
Itamar.
|