Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

Important bug fix in WooCommerce 3.1 for WordPress multisite

Recently WooCommerce has released v3.1, it was not a major update. But has some good new features and enhancements along with bug fixes. This version has had over 1600 commits from 84 contributors.

One of the major change is that now WooCommerce persistent carts are compatible with the WordPress multisite.

Yes, you read it correctly, the WooCommerce persistent carts were not compatible with the WordPress multisite. So, if you have a multisite and one of your customer had complained about the missing cart or unwanted carts then its WooCommerce persistent cart which was causing the issue on your site. It will be replicated when your subdomain at least one product share the same ID.

What was the issue?

Let’s look at the code before v3.1

Above function is executed each time when the user updates the cart on your store and it will store the customer’s updated cart information. It is storing the user’s cart details in the user_meta table, it does not store any subdomain id for that user’s cart.

Now, consider the following setup of the WordPress multisite.

  1. A multisite setup:
    your-site.com/ (Network Site)
    your-site.com/demo_one/ (Site One, WooCommerce activated)
    your-site.com/demo_two/ (Site Two, WooCommerce activated)
    your-site.com/demo_three/ (Site Three, WooCommerce activated)
  2. Create some products in SITE One (your-site.com/demo_one/) and SITE Third (your-site.com/demo_three/), but we need to make sure at least one product share the same ID on each site.
  3. Open a browser and login to the network ( your-site.com/ ). And add a product with an overlapping ID in your cart on Site One (your-site.com/demo_one/).
  4. Open another browser and login to the network ( your-site.com/ ). Now browse to SITE Third (your-site.com/demo_three/) and now you find a product in your Cart which you had added for site First.

Here, it’s important that user which you are logged in do not have any cart information or any session, let’s say login to the site for the first time. If loggedin user had any history of the cart then it would restore the cart from that session instead of the user meta.

So, here when I logged into the Third site it will load the cart with the cart details which was added at the site One. Here, take a note that I have not yet added the product to the cart in site Third, I just went to the cart page.

As the new user does not have any session of the carts then the WooCommerce will load the data from the user_meta. Check the below code snippet.

Subdomain site one
Subdomain site one

 

Subdomain site three
Subdomain site three

To overcome the issue of the cart which is not created by the customer on the WordPress multisite, WooCommmerce has now added the blog id for the persistent cart.

Now, persistent cart in the v3.1 is stored as below.

Now they have blog_id for storing the user cart. Now, each stored persistent cart have the blog id.

One of our plugins Abandoned cart need to store the loggedin users latest cart information, so we have used the WooCommecerce persistent cart. After WooCommerce 3.1 our plugin was not storing the latest cart information of the loggedin users.

get_user_meta( $user_id, ‘_woocommerce_persistent_cart_’ . get_current_blog_id(), true );

To overcome the issue we have used above code to retrieve the persistent cart of the logged in users.

If you are a developer and you have used the WooCommecerce persistent cart then you must change your code and use the blog id for retrieving the persistent cart

If you want to check the discussion on the issue then you can check here.

Browse more in: Code Snippets, WooCommerce

Share It:

Subscribe
Notify of
0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x