Home›Supporto›Assistenza in italiano›[Assegnato] Fatal Error when saving a product: Array callback must have exactly two elements in Post.php
[Assegnato] Fatal Error when saving a product: Array callback must have exactly two elements in Post.php
Questo è il forum di assistenza tecnica di WPML, il plug-in multilingue di WordPress.
La sua lettura è permessa a tutti, ma la pubblicazione è riservata esclusivamente ai clienti di WPML. Il team di WPML risponde sul forum 6 giorni su 7, 22 ore su 24.
I am experiencing a critical Fatal Error when trying to save or update a product in WooCommerce. The issue seems to be related to the woocommerce-multilingual plugin during the synchronization process.
Symptoms: When I click "Update" or "Publish" on a product, the site crashes with the following error.
Error Log:
Fatal error: Uncaught Error: Array callback must have exactly two elements in /var/www/webroot/ROOT/wp-content/plugins/woocommerce-multilingual/classes/Synchronization/Component/Post.php:69
Stack trace:
#0 /var/www/webroot/ROOT/wp-content/plugins/woocommerce-multilingual/classes/Synchronization/Component/Post.php(50): WCML\Synchronization\Component\Post->managePostParent()
#1 /var/www/webroot/ROOT/wp-content/plugins/woocommerce-multilingual/classes/Synchronization/Manager.php(159): WCML\Synchronization\Component\Post->run()
... [rest of the stack trace]
I have important additional information regarding the Fatal Error Array callback must have exactly two elements.
The error only occurs when an external plugin updates a custom field via API. We use a plugin called "Sirio WooSync" (connected to our ERP) that updates a specific custom field for Price Lists.
The Workflow causing the crash:
The ERP triggers an API update for a custom price field on a product.
WooCommerce Multilingual tries to sync this change (managePostParent runs).
The Fatal Error happens immediately, blocking the update.
Environment:
PHP: 8.3.24 (LiteSpeed)
WooCommerce: 10.4.3
WCML: 5.5.3.1
External Plugin: Sirio WooSync v1.1.0
It seems WCML fails to handle the synchronization hook triggered by this specific API update under PHP 8.3 rules. Can you verify if WCML\Synchronization\Component\Post.php can be patched to handle this type of external update safely?
Thanks for reaching out to WPML Support. I'm Prosenjit from the WPML Development Team, and I'll be happy to help you with this issue.
I understand the problem and appreciate you providing such detailed information — it's very helpful for the investigation.
Since you have a custom setup for updating products via API, I've conducted a preliminary code review based on the stack trace and the specific line where the error occurs. Here's what I found:
At the line where the fatal error is triggered, the code is trying to call `$translationsLanguages` as a function using `$translationsLanguages($translationID)`. However, according to the method signature, `$translationsLanguages` is actually defined as an array parameter (`array<int, string> $translationsLanguages`), not a callable function.
PHP 8.3 has stricter validation for array callbacks. When PHP encounters `$translationsLanguages($translationID)`, it interprets this as an attempt to use an array as a callback function. Since the array doesn't have exactly two elements in the expected callback format, it triggers the fatal error: "Array callback must have exactly two elements."
Based on this preliminary investigation, the issue appears to be in how the code is calling this parameter. Given the method signature, could you please try updating the code as shown below and see if it resolves the issue?
- Go to /wp-content/plugins/woocommerce-multilingual/classes/Synchronization/Component/, open Post.php and scroll to the line 69
- Replace the entire line with the following code:
Important: Please make sure to take a full backup of your site before making any code changes.
Please test the code update and let me know the results:
- If the fix works: I'll escalate this internally and work to include the fix in the next WPML update so it's available for everyone.
- If the issue persists: Please reach out, and I'll be happy to conduct a deeper investigation. Given the complexity of your custom API setup, there may be additional factors at play that we'll need to examine more closely.
Either way, I'm here to help ensure this gets fully resolved for you.
I've just verified the same version you're using (5.5.3.1), and I can confirm that the folder structure does exist in that version. Additionally, since the stack trace explicitly shows this file path and filename in the error message, the file must be present in your installation — the error couldn't reference it otherwise.
Could you please access your site's file system using either FTP or your hosting control panel's File Manager and then check again?
If you find that the file is indeed missing, I'd recommend:
1. Taking a complete backup of your site first
2. Deactivating and deleting the WooCommerce Multilingual plugin
3. Reinstalling it fresh from your WPML account
However, before we proceed with any of these steps, please let me know what you find when you check the file system. This will help us determine the best course of action.
Let me know, please! I'm here to guide you through each step if needed!