• 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 7 replies - 16 through 22 (of 22 total)
  • Thread Starter sagescrub

    (@sagescrub)

    @ihereira the ticket number is 5562824. Thank you for looking into this.

    Saif

    (@babylon1999)

    Hello @sagescrub,

    Thank you for sharing the ticket number!

    I can see the last reply from a Happiness Engineer suggested disabling the WP-Optimize plugin, clearing the cache within WP Engine, and fixing your theme’s outdated templates. I don’t see a reply from you confirming if you’ve tried the steps above.

    If that doesn’t solve the problem, feel free to open a new ticket and mentioned the ticket number so we know what has been done already.

    Cheers!

    Thread Starter sagescrub

    (@sagescrub)

    @babylon1999

    Thank you for your reply. So far the issue happened 3 times in January. I don’t want to disable our WP-Optimize plugin and wait 2-3 weeks or more to be sure because it will hurt our SEO score. The error happens on the homepage and that page is important for our SEO.

    In December the error happened 19 times. I think it was higher because we had more traffic to our site for holiday sales.

    I already checked the theme templates and there are no issues there.

    The stack trace is originating from WooCommerce Payments (via multicurrency component) and then goes into WooCommerce code from there. I think there need to be some checks in the places that empty_cart is called, or else WooCommerce Payments needs to make some checks before WC_Session_Handler->init() is called.

    Again, our site is not multicurrency enabled so that functionality is not a concern.

    As you can see others are also experiencing this issue as indicated by @ihereira so I urge you to make some checks in the code. Since this is difficult to reproduce, if you insist that reproducing the issue is a requirement to improve the code, we may be at a stand still.

    I’ve done what I can to reproduce the issue or understand where it is coming from but I am at a loss.

    I hope you can use the stack trace I’ve provided to add some conditional checks in the multicurrency code so that this error can be eliminated, regardless of the mystery why it is happening. Do you agree this is a good approach?

    Hi there @sagescrub,

    I’m sorry to hear that error is still occurring. As my colleague had mentioned in your ticket back in September, he’d performed a check of the code related to that function then:

    The wc_empty_cart appears to have also been depreciated and I am not seeing a record of WooCommerce Payments hooking into that function.

    https://github.com/woocommerce/woocommerce/blob/5239cf62e74ba9284578e73d97353dc1e10c8fa4/plugins/woocommerce/includes/wc-deprecated-functions.php#L251

    We haven’t seen any other reports of this so it’s safe for us to suspect the problem is likely with the combination of active plugins and the hosting environment. More specifically, we haven’t seen the issue on WP Engine sites so it could be the one active plugin that trying to optimize the environment.

    I will ask our developers to take another look in the meantime, but at this point a conflict test isolating WooCommerce/WooCommerce Payments on your site is our best bet for finding more data to work with here. If you’re able to do this on a staging site within the same hosting environment, that would be ideal.

    Let me know if you have any questions. Thanks!

    Thread Starter sagescrub

    (@sagescrub)

    @thracefulton thank you for your reply. You are correct, woocommerce payments does not call wc_empty_cart directly. But it interfaces with the woocommerce plugin through WooCommerce->initialize_session which does call wc_empty_cart. In that case my suggestion is to ensure that initialize_session is not called to early. There must be a way to check for that. Do you agree?

    As already mentioned earlier, this is not reproducing in our staging site. Trust me I tried! My hunch is that it this issue is traffic dependent. The major difference between our staging and live site is that our live site receives many magnitudes more traffic and possibly use case scenarios we are not considering in our staging environment.

    Hi again @sagescrub,

    Thanks for your patience!

    You are correct, woocommerce payments does not call wc_empty_cart directly. But it interfaces with the woocommerce plugin through WooCommerce->initialize_session which does call wc_empty_cart. In that case my suggestion is to ensure that initialize_session is not called to early. There must be a way to check for that. Do you agree?

    It appears this is correct, at least in part. I was able to confirm the error is thrown in WooCommerce, not WooCommerce Payments; it appears it is being triggered by wc_load_cart().

    Our developers pointed out this planned fix that was built in December, which is now a part of WooCommerce 7.4 Beta 1 being testing as we speak.

    Feel free to follow along with that pull request there for any updates, and with any luck that issue will be resolved in that future release.

    Thanks!

    Thread Starter sagescrub

    (@sagescrub)

    @thracefulton that is wonderful! Thank you for looking into this more closely and for sharing the progress of the planned fix. I look forward to see if this also resolves the issue in our website. It looks promising – fingers crossed!

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