• Resolved sagescrub

    (@sagescrub)


    Hello,

    WooCommerce Payments plugin is generating an unhandled exception on our website: “Call to undefined function wc_empty_cart()”

    The error only occurs once or twice a day on a well trafficked site, so it is not easy to reproduce. But I am including the stack trace below so you can review the issue. From the stack trace you can see that WooCommerce plugin is loaded, but the function wc_empty_cart is not available, so perhaps there is a timing issue regarding when initialize_session() can be called?

    fatal_handlerUncaught Error: Call to undefined function wc_empty_cart() in /wp-content/plugins/woocommerce/includes/class-wc-session-handler.php:372 Stack trace: #0 /wp-content/plugins/woocommerce/includes/class-wc-session-handler.php(363): WC_Session_Handler->forget_session() #1 /wp-content/plugins/woocommerce/includes/class-wc-session-handler.php(99): WC_Session_Handler->destroy_session() #2 /wp-content/plugins/woocommerce/includes/class-wc-session-handler.php(71): WC_Session_Handler->init_session_cookie() #3 /wp-content/plugins/woocommerce/includes/class-woocommerce.php(861): WC_Session_Handler->init() #4 /wp-content/plugins/woocommerce-payments/includes/multi-currency/MultiCurrency.php(913): WooCommerce->initialize_session() #5 /wp-content/plugins/woocommerce-payments/includes/multi-currency/MultiCurrency.php(614): WCPay\MultiCurren

Viewing 15 replies - 1 through 15 (of 22 total)
  • Mirko P.

    (@rainfallnixfig)

    Hi there!

    Thanks for getting in touch.

    Do you mind sharing a copy of your site’s System Status? You can find it via WooCommerce > Status. Select “Get system report” and then “Copy for support”. Once you’ve done that, paste it here in your response.

    Additionally, I’d suggest enabling debug logging in WordPress to check if we’re able to log more info and errors there to locate the culprit. Follow the steps here for debugging in WordPress:

    https://github.com/woocommerce/woocommerce/wiki/Using-WP_DEBUG_LOG-to-log-errors

    Cheers.

    Thread Starter sagescrub

    (@sagescrub)

    @rainfallnixfig , I’ve enabled debug logging on the server, so next time it happens I’ll share anything related. Do you have a way for me to send you the System Report privately? Thank you!

    Hi @sagescrub

    I’ve enabled debug logging on the server, so next time it happens I’ll share anything related

    Thanks, that’ll be helpful.

    Do you have a way for me to send you the System Report privately?

    Since this is a public forum, anyone can step in to help and not only plugin support staff. For this reason, the forums do not have any private communication options.

    If you’d rather not post your System Status here, feel free to use tools like https://pastebin.com/ or even Google Docs where you can control the visibility or even delete the SSR, depending on the tool. You can paste it there and share with us a link to it.

    Thread Starter sagescrub

    (@sagescrub)

    Margaret, thank you for that suggestion. Here is the paste of the WooCommerce Status: https://pastebin.com/VUJCSzC5

    Thread Starter sagescrub

    (@sagescrub)

    The error just happened again. Here is the relevant content from the debug.log. Unfortunately it doesn’t seem to give more help than the original stack trace that I shared.

    [31-Aug-2022 23:28:21 UTC] PHP Fatal error:  Uncaught Error: Call to undefined function wc_empty_cart() in /[redacted]/wp-content/plugins/woocommerce/includes/class-wc-session-handler.php:372
    Stack trace:
    #0 /[redacted]/wp-content/plugins/woocommerce/includes/class-wc-session-handler.php(363): WC_Session_Handler->forget_session()
    #1 /[redacted]/wp-content/plugins/woocommerce/includes/class-wc-session-handler.php(99): WC_Session_Handler->destroy_session()
    #2 /[redacted]/wp-content/plugins/woocommerce/includes/class-wc-session-handler.php(71): WC_Session_Handler->init_session_cookie()
    #3 /[redacted]/wp-content/plugins/woocommerce/includes/class-woocommerce.php(861): WC_Session_Handler->init()
    #4 /[redacted]/wp-content/plugins/woocommerce-payments/includes/multi-currency/MultiCurrency.php(913): WooCommerce->initialize_session()
    #5 /[redacted]/wp-content/plugins/woocommerce-payments/includes/multi-currency/MultiCurrency.php(614): WCPay\MultiCurren in /[redacted]/wp-content/plugins/woocommerce/includes/class-wc-session-handler.php on line 372
    Mirko P.

    (@rainfallnixfig)

    Hi there,

    Thanks for the system status and server logs.

    There are no further indications of what may be causing the PHP fatal error in the logs. As a next step, I’d suggest following these points:

    1. Create a staging site
    2. Update all your software including WordPress, WooCommerce and WooCommerce Payments
    3. Run a WooCommerce database update to match the core version

    Can you check at this point if you still see fatal errors?

    Let us know your findings.

    Thread Starter sagescrub

    (@sagescrub)

    Thank you for this suggestion Mirko. We do already have a staging site with the same plugins, including WooCommerce Payments. The only difference is that payments are in test mode.

    Unfortunately I have not seen this error from the staging site. I suspect that is because the live site receives a lot of traffic, while the staging site receives very little in comparison.

    As I mentioned the live site sees this error on average 1-2 times a day, but the time and frequency is not exactly consistent. That is what leads me to believe the amount of traffic has some influence on the error being generated, but I can’t prove that.

    In any case, it may be helpful for you to know that I have never experienced the error myself. I am receiving log notices when the error happens, but it is some public user outside of our team.

    Is the stack trace not enough to help you troubleshoot?

    Why would wc_empty_cart() not be defined, when the stack trace clearly shows execution already happening in the WooCommerce plugin?

    To start answering that question I see in the WooCommerce plugin that /includes/wc-cart-functions.php is included dynamically in three places. That file is where the function wc_empty_cart() resides.

    Therefore I ask: Is it possible that in some scenarios WooCommerce Payments calls WooCommerce->initialize_session() before wc_empty_cart() is available? I suspect that may be the case.

    Thread Starter sagescrub

    (@sagescrub)

    This error continues to happen once every day or so.

    Hello,
    Sorry to hear that issue persists.

    The reasons are variable, for example, it could be a conflict. To isolate the issue you can perform the following steps:

    • Temporarily switch your theme to Storefront
    • Disable all plugins except for WooCommerce and WooCommerce Payments
    • Try to reproduce the issue on your site, repeat the steps that are affecting the site’s normal behavior

    At this point check if the issue is still present, if not, it means there was a conflict and you can reactivate the theme and plugins gradually one by one and check again after each reactivation until the cause of the issue is found.

    You can use this plugin to help you out (It can remember what plugins were active when you switch it back on):
    https://www.ads-software.com/plugins/meks-quick-plugin-disabler/

    You can find a more detailed explanation on how to do a conflict test here.

    Let us know if this makes a difference.

    Thread Starter sagescrub

    (@sagescrub)

    Igor,

    As I mentioned in a previous post the issue is difficult to reproduce. Actually I have never seen the error in my browser. I am only finding it in the error log once or twice a day on average. The issue is not yet reproducible on our staging site, so I think there is some factor of traffic or an edge case we have not identified.

    Since it is a live site I cannot disable plugins for several days to see if the error stops appearing, as that would jeopardize the function of the website and the business.

    So I hope you can find a savvier approach to solving this elusive issue. Did you see the question at the end of my Sept 1st post (last 3 paragraphs)? Are you able to answer those questions? I am hoping the stack trace is enough for you to start troubleshooting. The stack trace starts with the WooCommerce Payments function: #5 /nas/content/live/onewillow/wp-content/plugins/woocommerce-payments/includes/multi-currency/MultiCurrency.php(616)

    • This reply was modified 2 years, 5 months ago by sagescrub.

    Hello,

    Is the stack trace not enough to help you troubleshoot?

    Why would wc_empty_cart() not be defined, when the stack trace clearly shows execution already happening in the WooCommerce plugin?

    To start answering that question I see in the WooCommerce plugin that /includes/wc-cart-functions.php is included dynamically in three places. That file is where the function wc_empty_cart() resides.

    Therefore I ask: Is it possible that in some scenarios WooCommerce Payments calls WooCommerce->initialize_session() before wc_empty_cart() is available? I suspect that may be the case.

    We’ll need to take a deeper dive, please contact us at WooCommerce.com > My Account > Support. You may need to create an account before you can access that page.

    Important: Please include a link to this forum thread.

    Looking forward to hearing from you. Thanks.

    Thread Starter sagescrub

    (@sagescrub)

    Igor, I went ahead and opened a support ticket like you suggested and referenced this thread. Thank you

    Did you ever solve this? I am experiencing the same issue, and have been for some time. This has persisted through theme changes, multiple plugin changes, etc. We are completely updated on WP/Woo/all plugins and themes.

    Thread Starter sagescrub

    (@sagescrub)

    No this issue hasn’t been solved. We are still getting the error regularly. But no customers have complained about issues tied to this, that I can tell. Nonetheless its still annoying and concerning to have this error continue.

    Hi, @sagescrub

    I’m sorry to hear about this. I could not find the ticket created, sorry, can you provide us the ticket number, please?

    @chrisfontes

    We can help you to investigate further, please create your own thread for your issue – here.

    We want to make sure that every user’s issues receive their own thread with proper attention.

    Thanks.

Viewing 15 replies - 1 through 15 (of 22 total)
  • The topic ‘Call to undefined function wc_empty_cart()’ is closed to new replies.