co-cart / co-cart

🛒 CoCart makes it easy to decouple your WooCommerce store via a customizable REST API that takes the pain out of developing – allowing you to build fast and flexible headless stores.

Home Page:https://cocartapi.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BUG: Conflict with WooCommerce Follow Up Emails plugin extension due to hard coded session handler

Vickystha opened this issue · comments

commented

I'm experiencing an issue with CoCart plugin when browsing WordPress/WooCommerce backend. It breaks a critical page for another WooCommerce plugin (https://woocommerce.com/products/follow-up-emails/). An example URL of where the error occurs is:
http://example.com/wp-admin/admin.php?page=followup-emails-reports&tab=reportuser_view&user_id=123&email=john@example.com

The error trace is as following:

An error of type E_ERROR was caused in line 132 of the file example.com/public_html/wp-content/plugins/cart-rest-api-for-woocommerce/includes/class-cocart-woocommerce.php. Error message: Uncaught Error: Call to undefined method WC_Session_Handler::get_cart() in example.com/public_html/wp-content/plugins/cart-rest-api-for-woocommerce/includes/class-cocart-woocommerce.php:132
    Stack trace:
    #0 example.com/public_html/wp-includes/class-wp-hook.php(303): CoCart_WooCommerce::load_cart_from_session('')
    #1 example.com/public_html/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters('', Array)
    #2 example.com/public_html/wp-includes/plugin.php(470): WP_Hook->do_action(Array)
    #3 example.com/public_html/wp-content/plugins/woocommerce/includes/class-wc-cart-session.php(72): do_action('woocommerce_loa...')
    #4 example.com/public_html/wp-content/plugins/woocommerce/includes/legacy/class-wc-legacy-cart.php(274): WC_Cart_Session->get_cart_from_session()
    #5 example.com/public_html/wp-content/plugins/woocommerce-follow-up-emails/includes/addons/class-fue-a`

Another example trace:

Fatal error: Uncaught Error: Call to undefined method WC_Session_Handler::get_cart() in example.com/wp-content/plugins/cart-rest-api-for-woocommerce/includes/class-cocart-woocommerce.php:132 Stack trace: #0 example.com/wp-includes/class-wp-hook.php(303): CoCart_WooCommerce::load_cart_from_session('') #1 example.com/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters('', Array) #2 example.com/wp-includes/plugin.php(470): WP_Hook->do_action(Array) #3 example.com/wp-content/plugins/woocommerce/includes/class-wc-cart-session.php(72): do_action('woocommerce_loa...') #4 example.com/wp-content/plugins/woocommerce/includes/legacy/class-wc-legacy-cart.php(274): WC_Cart_Session->get_cart_from_session() #5 example.com/wp-content/plugins/woocommerce-follow-up-emails/includes/addons/class-fue-addon-wo in example.com/wp-content/plugins/cart-rest-api-for-woocommerce/includes/class-cocart-woocommerce.php on line 132

Following are the details of wp and plugin versions I'm using:

  • WordPress version 5.8.2
  • Current theme: Hello Elementor (version 2.3.0)
  • PHP version 7.4.25
  • CoCart Lite: Occurring on version 3.0.16 as well as 3.0.15

Prerequisites

  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • The issue still exists against the latest master branch of CoCart on GitHub (this is not the same version as on WordPress.org!)
  • I have attempted to find the simplest possible steps to reproduce the issue.
  • I have included a failing test as a pull request (Optional)
  • I have installed the requirements to run this plugin.

Steps to reproduce the issue

  1. Install WooCommerce, WooCommerce Follow Ups and CoCart Lite
  2. Should have dummy subscription purchase
  3. Visit http://example.com/wp-admin/admin.php?page=followup-emails-reports&tab=reportuser_view&user_id=123&email=john@example.com

After examining the "Follow Ups" extension I can say that because they way it's developed, it's not going to work with CoCart at this time and here is why.

  1. Where the issue is located, the default WooCommerce session handler is loaded, however, the developers have hard coded the session class that is used. There is no filter available as provided by WooCommerce so it makes stores using their own session handler with this extension much harder.
  2. CoCart loads this particular file where the error is logged after Follow Ups, so the session handler as you can see is trying to load a function that is actually part of CoCart's session handler but the WooCommerce session handler has loaded so it thinks the function does not exist.

What's odd is that a check is in place before that function is called to validate if the correct session handler has loaded before allowing it to continue. So it shouldn't be allowing to pass.

// Check the CoCart session handler is used but is NOT a CoCart REST API request.
if ( WC()->session instanceof CoCart_Session_Handler && ! CoCart_Authentication::is_rest_api_request() ) {
    return;
}

At this time a quick patch is not possible but I have made a change that should help with other WooCommerce extensions that are hard coded including "Follow Ups" for v3.1 which does provide more backwards compatibility.

You can expect to see a new test build for v3.1 soon. More details will be posted via CoCart.dev

Thank you for the report @Vickystha

commented

Thanks @seb86. Hopefully this can be resolved soon.

Closing issue for now as there has not been any further reports.