Troubleshooting Common PHP Errors in Variation Swatches for WooCommerce
Content
Variation Swatches for WooCommerce is a powerful tool for enhancing your product pages, but like any complex plugin, it can sometimes conflict with your site's environment, leading to PHP errors. Based on community reports, here are the most common errors and their solutions.
1. Call to a member function on bool/null (e.g., get_children(), get_parent_id(), is_type())
Error Example: Fatal error: Uncaught Error: Call to a member function get_children() on bool
Why it happens: This is one of the most frequent errors. It typically occurs when the plugin tries to perform an action on a product or product variation object that does not exist or has not been loaded correctly. This can be triggered by outdated theme/plugin code, a conflict with another plugin (like import/export tools), or a corrupted product in your database.
How to fix it:
- Plugin/Theme Conflict Test: This is the most critical first step.
- Temporarily deactivate all plugins except WooCommerce and Variation Swatches.
- Switch your theme to a default WordPress theme like Storefront or Twenty Twenty-Four.
- Check if the error persists. If it disappears, reactivate your plugins and theme one by one to identify the culprit.
- Check for Corrupted Products: The error often happens on specific variable products. Try editing or re-creating the product where the error occurs.
- Ensure Everything is Updated: Confirm your WordPress, WooCommerce, and Variation Swatches plugins are all running the latest versions. Many of these errors are patched in subsequent updates.
2. PHP Warnings and Notices (Trying to access array offset, Illegal string offset)
Error Example: Notice: Trying to access array offset on value of type bool or Warning: Illegal string offset "160-x-230"
Why it happens: These are not fatal errors but indicate that the code is trying to read data from a variable that is either empty or not an array. This is common when an attribute term has no image assigned or when there is an unexpected data structure from a third-party plugin or theme.
How to fix it:
- Configure Attribute Terms: If you are using image or color swatches, ensure all applicable attribute terms have an image or color assigned in Products -> Attributes -> Configure Terms.
- Update PHP: These notices became more prevalent with stricter type checking in PHP 7.4 and 8.0. While the plugin should be compatible, ensuring you are on a supported plugin version is key. The development team often releases patches for these notices.
- Enable Debugging Temporarily: Add the following lines to your
wp-config.phpfile to see if other underlying issues are present. Remember to disable this on a live site afterwards.define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true ); // Logs errors to wp-content/debug.log define( 'WP_DEBUG_DISPLAY', false ); // Hides errors from the screen
3. Call to undefined function (e.g., wc_string_to_bool(), wc_esc_json())
Error Example: Fatal error: Uncaught Error: Call to undefined function wc_esc_json()
Why it happens: This error is almost always caused by an outdated version of WooCommerce. The plugin is trying to use a function that was introduced in a newer version of WooCommerce than the one installed on your site.
How to fix it:
- Go to your WordPress admin dashboard and navigate to Dashboard -> Updates.
- Ensure WooCommerce is updated to the latest available version.
- After updating, clear your site's cache if you use a caching plugin.
4. preg_match() Argument Must Be String
Error Example: CRITICAL Uncaught TypeError: preg_match(): Argument #2 ($subject) must be of type string, array given
Why it happens: This error suggests that a function expecting a string value (like a product variation name) is receiving an array instead. This is a specific type of conflict, often occurring when saving variable products and can be related to how other plugins or custom code interact with product data.
How to fix it:
- Perform the Plugin/Theme Conflict Test outlined in section 1. Plugins that bulk edit products or variations are common causes.
- If the error is isolated to a specific product, check the data for that product's variations for any irregularities.
General Best Practices to Prevent Errors
- Keep Everything Updated: Regularly update WordPress, your theme, WooCommerce, and all plugins, including Variation Swatches. Updates often include critical bug fixes and compatibility patches.
- Use a Staging Site: Always test major updates on a staging copy of your live site before applying them to production.
- Check Requirements: Before updating, verify that your server meets the minimum requirements for the new version of the plugin, particularly the PHP version.
If you continue to experience issues after trying these steps, it is recommended to search for your specific error message on the WordPress support forums for this plugin, as other users may have encountered and solved the same problem.
Related Support Threads Support
-
Wp reference errorhttps://wordpress.org/support/topic/wp-reference-error/
-
(POST ERROR) Unauthorised AJAX Calls via Freemiushttps://wordpress.org/support/topic/post-error-unauthorised-ajax-calls-via-freemius/
-
Warning on PHP 8https://wordpress.org/support/topic/warning-on-php-8/
-
PHP 8 Supporthttps://wordpress.org/support/topic/php-8-support-6/
-
Problem after updatinghttps://wordpress.org/support/topic/problem-after-updating-8/
-
Failed to load resource: net::ERR_CONNECTION_TIMED_OUThttps://wordpress.org/support/topic/failed-to-load-resource-neterr_connection_timed_out/
-
Errorhttps://wordpress.org/support/topic/error-1707/
-
some error on woocommerce terms api when install this pluginhttps://wordpress.org/support/topic/some-error-on-woocommerce-terms-api-when-install-this-plugin/
-
PHP fatal error on latest release (2.0.5)https://wordpress.org/support/topic/php-fatal-error-on-latest-release-2-0-5/
-
Error on serverhttps://wordpress.org/support/topic/error-on-server-5/
-
Issue with “Clearing WooCommerce Transients”https://wordpress.org/support/topic/issue-with-clearing-woocommerce-transients/
-
Plugin not working (2 different servers)https://wordpress.org/support/topic/plugin-not-working-2-different-servers/
-
My admin site is slow because your domain is DOWNhttps://wordpress.org/support/topic/my-admin-site-is-slow-because-your-domain-is-down/
-
Fatal error: Uncaught Error:https://wordpress.org/support/topic/fatal-error-uncaught-error-90/
-
HTTP508 and 503 errorshttps://wordpress.org/support/topic/http508-and-503-errors/
-
preg_match errorhttps://wordpress.org/support/topic/preg_match-error-5/
-
2 NOTICES PHPhttps://wordpress.org/support/topic/2-notices-php/
-
attempt to read property id on null in line 69https://wordpress.org/support/topic/attempt-to-read-property-id-on-null-in-line-69/
-
Crash the websitehttps://wordpress.org/support/topic/crash-the-website/
-
Fatal Errorhttps://wordpress.org/support/topic/fatal-error-4302/
-
Null pointer when upgrading to woo 5.0https://wordpress.org/support/topic/null-pointer-when-upgrading-to-woo-5-0-2/
-
An error of type E_ERROR was caused on line 53 of the filehttps://wordpress.org/support/topic/an-error-of-type-e_error-was-caused-on-line-53-of-the-file/
-
class-getwooplugins-admin-menus.php on line 271https://wordpress.org/support/topic/class-getwooplugins-admin-menus-php-on-line-271/
-
malware warninghttps://wordpress.org/support/topic/malware-warning-5/
-
id of non-objecthttps://wordpress.org/support/topic/id-of-non-object/
-
critical error on websitehttps://wordpress.org/support/topic/critical-error-on-website-24/
-
Fatal errorhttps://wordpress.org/support/topic/fatal-error-3729/
-
REST error since version 2.021https://wordpress.org/support/topic/rest-error-since-version-2-021/
-
Fatal error: Allowed memory sizehttps://wordpress.org/support/topic/revert-update-please/
-
Admin errorhttps://wordpress.org/support/topic/admin-error-18/
-
PHP Warning: Illegal string offset “160-x-230”https://wordpress.org/support/topic/php-warning-illegal-string-offset-160-x-230/
-
WooCommerce 4.6.0 broke the website screen customizationhttps://wordpress.org/support/topic/woocommerce-4-6-0-broke-the-website-screen-customization/
-
Undefined index: cb in plugins/variation-swatches-for-woocommerce/includes/classhttps://wordpress.org/support/topic/undefined-index-cb-in-plugins-variation-swatches-for-woocommerce-includes-class/
-
Error when using WP All Importhttps://wordpress.org/support/topic/error-when-using-wp-all-import/
-
Errors csshttps://wordpress.org/support/topic/errors-css-2/
-
PHP 7.4 notice for attribute terms without imageshttps://wordpress.org/support/topic/php-7-4-notice-for-attribute-terms-without-images/
-
Após a última atualização 1.1.19, os hook estão dando conflitoshttps://wordpress.org/support/topic/apos-a-ultima-atualizacao-1-1-19-os-hook-estao-dando-conflitos/
-
My website broke!! (Fatal Error)https://wordpress.org/support/topic/my-website-broke-fatal-error/
-
Error after updating woocommercehttps://wordpress.org/support/topic/error-after-updating-woocommerce-2/
-
Issues / errorshttps://wordpress.org/support/topic/issues-errors/
-
Uninstallation errorshttps://wordpress.org/support/topic/uninstallation-errors/
-
PHP Fatal error: Uncaught Error: Call to a member function get_children()https://wordpress.org/support/topic/php-fatal-error-uncaught-error-call-to-a-member-function-get_children-2/
-
Message wordpress: your site has a technical problemhttps://wordpress.org/support/topic/message-wordpress-your-site-has-a-technical-problem/