Deprecated: preg_match() errors when using parentheses in shipping method costs.
-
Hi,
I’ve started seeing this error in my logs. In my case it seems to relate to shipping calculations. As soon as I add parentheses in the shipping method cost and save it throws the error. If I remove them and save it does not.
Does not break:
8 * [qty]
Breaks:
( 8 * [qty] )
Also breaks:
4 + ( 8 * [qty] )
I’m currently running PHP 8.1.29 with Woocommerce 9.0.2 but rolling back to Woocommerce 8.7.1 (and others) doesn’t change the situation. This is in a blank test environment with the Storefront theme and no other plugins.
Hope you can help.
-
Hey there, @bbceg! Thanks for contacting us. I’m happy to help you.
I tried this formula on my website and was not able to replicate the issue.
Were exactly do you see this error message?
Can you please share some screenshots to help us investigate this further? I recommend using https://snipboard.io. You can share the direct link to the image as a response to this topic.
We need screenshots of:
- WooCommerce > Settings > Shipping
- WooCommerce > Settings > Shipping > Click on Edit on a Shipping Zone
- WooCommerce > Settings > Shipping > Click on Edit on a Shipping Zone > Click on edit on each shipping method so we can check the specific settings
- The error message
Furthermore, I’d like to understand your site properly. Please share with us the necessary information below for us to investigate the issue further:
System Status Report which you can find via WooCommerce > Status > Get system report > Copy for support.
Fatal error logs (if any) under WooCommerce > Status > Logs. Then you can use the selector to search for Fatal Errors.
You could copy and paste your reply here or paste it via https://gist.github.com/ and send the link here.Looking forward to your reply.
Have a wonderful day!
Hi @carolm29,
Thanks for this. The error is in my logs.
Here are the screenshots requested:
- Shipping: https://snipboard.io/i5YnOa.jpg
- Zone: https://snipboard.io/ikfZwU.jpg
- Rate: https://snipboard.io/ykDmVu.jpg
- Error (with Ajax add to cart buttons disabled): https://snipboard.io/ThSdAa.jpg
Error in logs (with Ajax add to cart buttons enabled):
2024/07/05 17:18:02 [error] 17350#17350: *94 FastCGI sent in stderr: "PHP message: PHP Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /c/Solutions/wordpress/wp-content/plugins/woocommerce/includes/libraries/class-wc-eval-math.php on line 162" while reading response header from upstream, client: 192.168.1.50, server: wordpress.localdev, request: "POST /?wc-ajax=add_to_cart HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "wordpress.localdev", referrer: "https://wordpress.localdev/shop/"
And the system report:
WordPress Environment
WordPress address (URL): https://wordpress.localdev
Site address (URL): https://wordpress.localdev
WC Version: 9.0.2
Legacy REST API Package Version: The Legacy REST API plugin is not installed on this site.
Action Scheduler Version: ? 3.7.4
Log Directory Writable: ?
WP Version: 6.5.5
WP Multisite: –
WP Memory Limit: 512 MB
WP Debug Mode: ?
WP Cron: ?
Language: en_GB
External object cache: – Server Environment
Server Info: nginx/1.22.1
PHP Version: 8.1.29
PHP Post Max Size: 8 MB
PHP Time Limit: 30
PHP Max Input Vars: 1000
cURL Version: 7.81.0
OpenSSL/3.0.2
SUHOSIN Installed: –
MySQL Version: 8.0.37-0ubuntu0.22.04.3
Max Upload Size: 2 MB
Default Timezone is UTC: ?
fsockopen/cURL: ?
SoapClient: ?
DOMDocument: ?
GZip: ?
Multibyte String: ?
Remote Post: ?
Remote Get: ? Database
WC Database Version: 9.0.2
WC Database Prefix: wp_
Total Database Size: 5.23MB
Database Data Size: 3.37MB
Database Index Size: 1.86MB
wp_woocommerce_sessions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_woocommerce_api_keys: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_woocommerce_attribute_taxonomies: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_woocommerce_downloadable_product_permissions: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
wp_woocommerce_order_items: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_woocommerce_order_itemmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_woocommerce_tax_rates: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
wp_woocommerce_tax_rate_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_woocommerce_shipping_zones: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_woocommerce_shipping_zone_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_woocommerce_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_woocommerce_payment_tokens: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_woocommerce_payment_tokenmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_woocommerce_log: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_actionscheduler_actions: Data: 0.02MB + Index: 0.16MB + Engine InnoDB
wp_actionscheduler_claims: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_actionscheduler_groups: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_actionscheduler_logs: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_affiliate_wp_affiliatemeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_affiliate_wp_affiliates: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_affiliate_wp_campaigns: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_affiliate_wp_coupons: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_affiliate_wp_creatives: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_affiliate_wp_customermeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_affiliate_wp_customers: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_affiliate_wp_notifications: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_affiliate_wp_payouts: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_affiliate_wp_referralmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_affiliate_wp_referrals: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_affiliate_wp_rest_consumers: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_affiliate_wp_sales: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_affiliate_wp_visits: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_commentmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_comments: Data: 0.02MB + Index: 0.09MB + Engine InnoDB
wp_links: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_options: Data: 2.03MB + Index: 0.06MB + Engine InnoDB
wp_postmeta: Data: 0.05MB + Index: 0.03MB + Engine InnoDB
wp_posts: Data: 0.05MB + Index: 0.06MB + Engine InnoDB
wp_term_relationships: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_term_taxonomy: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_termmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_terms: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_usermeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_users: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
wp_wc_admin_note_actions: Data: 0.06MB + Index: 0.02MB + Engine InnoDB
wp_wc_admin_notes: Data: 0.08MB + Index: 0.00MB + Engine InnoDB
wp_wc_category_lookup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_wc_customer_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_wc_download_log: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_wc_order_coupon_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_wc_order_product_lookup: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
wp_wc_order_stats: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
wp_wc_order_tax_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_wc_product_attributes_lookup: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_wc_product_download_directories: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_wc_product_meta_lookup: Data: 0.02MB + Index: 0.09MB + Engine InnoDB
wp_wc_rate_limits: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_wc_reserved_stock: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_wc_tax_rate_classes: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_wc_webhooks: Data: 0.02MB + Index: 0.02MB + Engine InnoDB Post Type Counts
attachment: 1
page: 10
post: 2
product: 2
revision: 5
shop_order: 5 Security
Secure connection (HTTPS): ?
Your store is not using HTTPS. Learn more about HTTPS and SSL Certificates.
Hide errors from visitors: ?Error messages should not be shown to visitors. Active Plugins (1)
WooCommerce: by Automattic – 9.0.2 Inactive Plugins (2)
AffiliateWP: by AffiliateWP – 2.9.6.1
AffiliateWP - Affiliate Portal: by Sandhills Development
LLC – 1.1.3
Classic Editor: by WordPress Contributors – 1.6.3
WooCommerce Stripe Gateway: by WooCommerce – 8.4.0
API Enabled: –
Force SSL: –
Currency: GBP (£)
Currency Position: left
Thousand Separator: ,
Decimal Separator: .
Number of Decimals: 2
Taxonomies: Product Types: external (external)
grouped (grouped)
simple (simple)
variable (variable)
Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog)
exclude-from-search (exclude-from-search)
featured (featured)
outofstock (outofstock)
rated-1 (rated-1)
rated-2 (rated-2)
rated-3 (rated-3)
rated-4 (rated-4)
rated-5 (rated-5)
Connected to WooCommerce.com: –
Enforce Approved Product Download Directories: –
HPOS feature enabled: –
Order datastore: WC_Order_Data_Store_CPT
HPOS data sync enabled: – Logging
Enabled: ?
Handler: Automattic\WooCommerce\Internal\Admin\Logging\LogHandlerFileV2
Retention period: 30 days
Level threshold: –
Log directory size: 5 KB WC Pages
Shop base: #14 - /shop/
Basket: #15 - /basket/
Checkout: #16 - /checkout/
My account: #17 - /my-account/
Terms and conditions: ? Page not set Theme
Name: Storefront
Version: 4.6.0
Author URL: https://woocommerce.com/
Child Theme: ? – If you are modifying WooCommerce on a parent theme that you did not build
personally we recommend using a child theme. See: How to create a child theme
WooCommerce Support: ? Templates
Overrides: – Admin
Enabled Features: activity-panels
analytics
product-block-editor
coupons
core-profiler
customize-store
customer-effort-score-tracks
import-products-task
experimental-fashion-sample-products
shipping-smart-defaults
shipping-setting-tour
homescreen
marketing
mobile-app-banner
navigation
onboarding
onboarding-tasks
product-custom-fields
remote-inbox-notifications
remote-free-extensions
payment-gateway-suggestions
shipping-label-banner
subscriptions
store-alerts
transient-notices
woo-mobile-welcome
wc-pay-promotion
wc-pay-welcome-page
Disabled Features: minified-js
new-product-management-experience
pattern-toolkit-full-composability
product-pre-publish-modal
settings
async-product-editor-category-field
launch-your-store
product-editor-template-system
Daily Cron: ? Next scheduled: 2024-07-05 17:09:15 +01:00
Options: ?
Notes: 123
Onboarding: skipped Action Scheduler
Complete: 18
Oldest: 2024-07-04 16:11:46 +0100
Newest: 2024-07-05 17:16:23 +0100
Failed: 8
Oldest: 2023-03-07 12:07:23 +0000
Newest: 2024-07-04 17:13:27 +0100
Pending: 1
Oldest: 2024-07-06 16:13:38 +0100
Newest: 2024-07-06 16:13:38 +0100 Status report information
Generated at: 2024-07-05 17:30:48 +01:00
`Hi @bbceg,
I just tried this on a clean install of WooCommerce and I’m not getting any errors when using parentheses on my shipping formulas. I tried this one from your initial thread: ( 8 * [qty] ):
I was able to create it, save it, edit it and save it again without any issues.
I didn’t get any errors on my screen, neither on my WooCommerce logs, nor on my hosting PHP logs. I also have the Ajax add to cart enabled, and debug mode enabled on my PHP config.
This is really interesting, as you don’t have any other active plugins and are using a default theme. You’re even on the oldest version of PHP (I’m trying with 8.2.20). Maybe I’m missing something here?
Thanks!
-OPHi @omarfpg
Thanks for investigating. Please can you try disabling Ajax add to cart to to see if that makes a difference?
Hi @bbceg
I have tried disabling the Ajax add to cart option as you suggested, but I still couldn’t replicate the issue you’re experiencing. The shipping formula with parentheses is working fine in my test environment, even with the Ajax add to cart feature disabled.
However, are you trying to troubleshoot this issue in your local development environment? If that’s the case, why not experiment with a different local development setup, such as WAMP, or perhaps on a live site?
In the meantime, I suggest re-downloading your PHP and ensuring all the required extensions are enabled or testing a different PHP version to see if that resolves the issue.
Furthermore, if you plan to calculate shipping charges based on the quantity of the product, you don’t need to use the first bracket. Instead, you can simply use 20 * [qty]. More info: https://woocommerce.com/document/flat-rate-shipping/#advanced-costs
I wish I could help more, but hopefully, this gets you going in the right direction.
Thanks for looking @shameemreza . Did you have WP_DEBUG enabled when you did those tests?
Hi @bbceg
Yes, I always enable WP Debug mode right after each test and development installation. Because it’s crucial for debugging and troubleshooting technical issues.
I hope this clarifies your concern. If you have any other questions, feel free to ask.
Hi there ?? ,
We haven’t heard from you in a while; this is to check if you’ve been able to proceed with the troubleshooting steps provided before and if you still need help.
Thanks!
-OPHi @omarfpg ,
Sorry you’ve had to chase. I recently upgraded my PHP version to 8.2 hoping this would fix the problem but there has been no change. I am using the old cart rather than the block-based version in @shameemreza ‘s demo which might explain why he didn’t see an error but I’d still expect errors in the logs when updating via the admin or elsewhere.
I’m not sure what else to suggest. I’m only really raising it in case something needs to be fixed before a PHP update completely drops support for a null second parameter in preg_match.
However if you can’t replicate I guess there’s not much that can be done and it makes sense to close the issue…
Hello bbceg
Thank you for your reply.
I appreciate the steps you have taken to resolve this issue.
However since we cannot replicate the issue nor we have received any other reports, this may be a site-specific issue.Please don’t hesitate to contact us again if you have any questions or have new info to share.
We are here to help ??Best regards.
Hi @bbceg,
I went ahead and tried this one again; this time, I used the classic cart and checkout shortcode versions of it and disabled the Ajax add-to-cart option to better replicate the environment you’re using, as per your messages.
I also switched my currency to GBP, the thousand separator to “,” and the decimal point to “.”, as shown in your System Status Report, I have wp_debug enabled and remained on WooCommerce 9.0.2 for the tests. Here’s my own SSR.
I’m afraid I’m still unable to replicate this issue. Here’s a quick video of my tests:?https://share.zight.com/Wnu8g8Ob. I’d be inclined to think this is an issue with your server or your PHP. Is there a way for you to test this or ask your hosting provider about it?
One more thing, I just noticed this is in the Square forum, not the WooCommerce forum, so I’m going to mark this as resolved for now. Feel free to start a new thread in the WooCommerce forums to continue troubleshooting this one.
Thanks!
-OPNo worries @omarfpg thanks for trying again. Closing it seems the sensible option for now – not least because it’s in the wrong forum, I completely missed that too!
- You must be logged in to reply to this topic.