Syntax Error – Location and Suggested Fix
-
Over the last few weeks I have gotten a couple emails from my WordPress website about a fatal error caused by WooCommerce. I found the solution and wanted to share both the problem (so that it can be fixed in future versions) and the fix so anyone else who needs an immediate solution can resolve the issue on their own. My WooCommerce version is 8.1.1 but I think the error affects all versions starting from 8.0.0.
An error of type E_PARSE was caused in line 521 of the file /content/wp-content/plugins/woocommerce/src/Internal/DataStores/Orders/CustomOrdersTableController.php. Error message: syntax error, unexpected ')'
The code in question is lines 512-521 of woocommerce/src/Internal/DataStores/Orders/CustomOrdersTableController.php:
$sync_message = sprintf( // translators: %d: number of pending orders. _n( 'Sync %d pending order. You can switch data storage for orders only when posts and orders table are in sync.', 'Sync %d pending orders. You can switch data storage for orders only when posts and orders table are in sync.', $sync_status['current_pending_count'], 'woocommerce' ), $sync_status['current_pending_count'], );
The issue is the very last comma at the end of “
$sync_status['current_pending_count'],
” on line 520. There are no arguments following it and thus it is unnecessary and breaks the sprintf() function which is expecting another argument. The solution is to simply remove the comma so that the final code like this.$sync_message = sprintf( // translators: %d: number of pending orders. _n( 'Sync %d pending order. You can switch data storage for orders only when posts and orders table are in sync.', 'Sync %d pending orders. You can switch data storage for orders only when posts and orders table are in sync.', $sync_status['current_pending_count'], 'woocommerce' ), $sync_status['current_pending_count'] );
- The topic ‘Syntax Error – Location and Suggested Fix’ is closed to new replies.