CoCart v2.1 is now available!

Updated: 23rd May, 2020

CoCart v2.1 was removed from WordPress.org due to an unforeseen issue that affected some variations to the API to not work.

I’m very excited to announce that CoCart 2.1 is now available. It has been in development since July 2019 and has about 254 commits since the last update a month ago.

This is a minor release, which means everything is backward compatible with the previous version.

What’s new in 2.1?

In short… magic! ? Checkout this post for all the details.

I have also improved the content and structure of the documentation making it easier to find what you need.

This scene from Beauty and the Beast movie is one of my favourites and in a strange small way sings this release.

Enjoy! ?

Changelog

  • NEW: Added support for guest customers.
  • NEW: Carts in session are stored in a new database table.
  • NEW: Added plugin details to WooCommerce System Status.
  • NEW: Added uninstall.php file to delete table and options.
  • NEW: Able to transfer a cart from your headless store to the web.
  • NEW: Added handlers to improve product validation and extended support for other product types.
  • NEW: Can now add items to cart using a products SKU ID.
  • NEW: When an item is updated, removed or restored… the cart totals are re-calculated.
  • NEW: Added option to logout customer.
  • Removed: Parameter to re-calculate totals once item was updated.
  • Tweaked: Products that are no longer purchasable and are already in the cart are removed from the cart.
  • Tweaked: Stop redirect to getting started page if plugin was activated and was already installed before.
  • Tweaked: Prevent redirect to getting started page if multiple plugins activated at once.
  • Dev: Clear all carts stored in session via the Tools section of WooCommerce System Status.
  • Dev: Cart expiration can be filtered if the default 30 days is not to your liking.
  • Dev: Generated customer ID can be filtered before storing cart in the database and creates a cookie on the customer’s device.
  • Dev: Added filter cocart_add_to_cart_validation to allow plugin developers to pass their own validation before item is added to the cart.
  • Dev: Added filters to override the product name cocart_product_name and product title cocart_product_title when getting the cart contents.
  • Dev: Added filter cocart_item_thumbnail_src to override the source URL of the product thumbnail when getting the cart contents.
  • Dev: Added filter cocart_add_to_cart_quantity to override the quantity when adding an item.
  • Dev: Added filter cocart_add_cart_item_data so other plugins can pass cart item data when adding an item.
  • Dev: Added filters so the returned response messages can be changed.
  • Dev: Added conditional filter for returning a cart item.
  • Dev: Added hook cocart_user_switched to allow something to happen if a user has switched.
  • Dev: Added hook cocart_load_cart to manipulate the merged cart before it set in session.
  • Dev: Added hook cocart_load_cart_override to manipulate the overriding cart before it set in session.
  • Dev: Added hook cocart_item_added_updated_in_cart for when an item was added again but updated in cart.
  • Dev: Added a new class that handles logging errors.
  • Dev: Added filters to admin notices to extend the length of time they hide.
  • Dev: Added filter to override cookie check for authenticated users.
  • Tested: Compatible with WooCommerce v4.1.x

CoCart 2.0.13 RC2

March has been a busy month for everyone and if you have been keeping your plugins updated then you will have noticed the few silent releases recently that I have been pushing out.

This particular release however will be making a change to the quantity parameter.

The value type for quantity by default in WooCommerce is integer meaning that it only allows numeric values to be used in order to add or update an item to the cart.

The change requested by @metemaddar makes the value type a float allowing decimal values to be passed.

In order for this to work the `woocommerce_stock_amount filter must also be changed to validate the float value. This has been done for you.

It’s important that this release is validated as it affects total and tax calculations and I do not wish to break those who are using the default value type.

This is the first community contribution and I hope there will be more in the future. I urge you to test only on a local or staging site.

To test CoCart 2.0.13 RC2, download the release candidate here (zip).

If you find a problem, please report the bug.

FYI

Since 2.0.13 is in a release candidate stage, only bug fixes will be made.

For Developers: A new filter has also been added for sold individual products. cocart_add_to_cart_sold_individually_quantity this matches the filter in the core of WooCommerce – woocommerce_add_to_cart_sold_individually_quantity

If you use the filters, both values must match.

Happy testing! ?

Authenticating with WooCommerce: Here’s how you can do it

Before now, WooCommerce authentication method was left open so any 3rd party REST API could use there authentication method. This gave no limits for users to authenticate with CoCart.

However, due to the added restriction for just their REST API, (which could change in the future as WordPress will provide a more generic version) CoCart could no longer authenticate the WooCommerce way on either version of CoCart’s API.

But have no fear as today version 2.0.5 provides a small update to re-enable WooCommerce’s authentication method again for CoCart.

CoCart users can now authenticate the #WooCommerce way again. ?

On top of the update, I’m going to show you how to authenticate the WooCommerce way.

Please Note

The guide below is assuming you are making requests with HTTPS.

First if you haven’t already created any keys you will need to go the advanced section in your WooCommerce settings.

From there you need to press Add key button. Then select the user who will be using the key. Set the permissions to READ/WRITE so all of the CoCart API is accessible. Enter a description if you wish and then press Generate API key button.

You will then be presented with your consumer key and secret which you will need to copy before moving away from the page as warned to the user in the screenshot below.

Once you have your key created you can then make any authenticated request with CoCart like so.

Fetching the cart while authenticating

If you would like to understand more about authenticating with WooCommerce read the authentication section in their REST API documentation.

Happy coding!

CoCart v2 now released

Today marks the first release of the new API that introduces it’s own namespace, major improvements including better responses and new ways to return a response to reduce API requests in your app.

If you have been following the development of version 2 then you already know that for developers it is now possible to filter in additional data.

To share some of the examples on what you can do with CoCart v2 I have created a side plugin that provides various tweaks that you can apply to further enhance CoCart to your needs.

Feel free to contribute other examples that you have applied yourself.

The API

The new API uses the same parameter properties and includes some new ones. The route for the API has also changed including some of the endpoints.

Below you will see a comparison of the route and endpoint changes.

Legacy API

  • wc/v2/cart
  • wc/v2/cart/add
  • wc/v2/cart/calculate
  • wc/v2/cart/cart-item
  • wc/v2/cart/clear
  • wc/v2/cart/count-items
  • wc/v2/cart/totals

New API

  • cocart/v1/get-cart
  • cocart/v1/add-item
  • cocart/v1/calculate
  • cocart/v1/clear
  • cocart/v1/count-items
  • cocart/v1/item
  • cocart/v1/totals

You can still use the legacy API if you are already using it and not yet ready to use the new API but you will miss out on all the new enhanced features.

Upgrading is easy. As I said, the new API uses the same parameter properties so switching over is a breeze. The documentation provides all the details on the new parameter properties.

Minimum Requirements

While it is still possible to use CoCart with WooCommerce v3.X.X it is better to be updated to at least v3.6.X for better performance and security. With the upcoming release of WooCommerce 3.7, I will be updating the minimum required version of WooCommerce to 3.6 in the future.

I have to do this to keep up with the code changes within the WooCommerce ecosystem and to be able to deliver the best experience for my users.

If you have any questions or feedback around the decision for this change, please feel free to leave them in the comments.

Changelog

Here is the full changelog on what’s new in CoCart.

  • NEW: REST API namespace. CoCart is now an individual API and is no longer nested with WooCommerce’s core REST API.
  • NEW: Check to see if the cart is set before falling back to the cart in session if one exists.
  • NEW: Get a specific customers cart via their customer ID number.
  • NEW: Product title also returns besides just the product name when getting the cart.
  • NEW: Product price also returns when getting the cart.
  • Changed: Filter and Action Hook names in new API.
  • Improved: Complexity of functions for better performance and usage.
  • Tweaked: Added checking for items already in the cart.
  • Tweaked: Check if cart is empty before removing an item.
  • Tweaked: Responses for adding, updating, removing and restoring items to return whole cart if requested.
  • Tweaked: Responses for updating items to return the quantity of item along with message.
  • Tweaked: Totals can now return once calculated if requested.
  • Tweaked: Totals now return from session and can be returned pre-formatted if requested.
  • Tweaked: New option to refresh cart totals once item has been added or updated.
  • Dev: Added action hooks for getting cart, cart is cleared, item added, item removed and item restored.
  • Dev: Added filter to allow additional checks before the item is added to the cart.
  • Dev: Added filter to apply additional data to return when cart is returned.
  • Dev: Added filter to change the size of the thumbnail returned.
  • Dev: Added new option to return cart raw if requested.

Progress on CoCart Pro

Now that CoCart v2 is released you can expect to see CoCart Pro very soon.

If you look at the features page, you will already see some of the features that are coming to CoCart Pro. Development on the remaining core features that I have planned are near completion.

With plans for supporting popular official WooCommerce extensions in future updates, support for WooCommerce Subscriptions (which is by far the most popular) is the first supported.

Prices for CoCart Pro has already been released and if you have signed up to the newsletter you will be given a discount for the first year once launched so don’t miss out.

Showcase your store

I’m looking to showcase stores built using CoCart whether it’s a web app, desktop app or a smartphone app for Android and iOS. If you are interested in being featured, please contact me to discuss.

That’s it.

Enjoy CoCart v2 🙂

CoCart v1.1.0 Released

1.1.0 is a “minor” release; this version is backwards compatible with sites running versions of WooCommerce greater than or equal to v3.0.

No changes were made in this release only to ensure CoCart remains working the same with WooCommerce v3.6 or greater.

My thanks for Andrew Singh and gelaxe for reporting the issue and testing the RC release and thanks to Andy Keith for explaining the change required in his article.


CoCart 1.1.0 RC1

Greetings all! WooCommerce 3.6 was released a couple of days ago which provided a performance improvement which is great, however, due to that improvement the Cart was no longer loading during REST API requests.

So for any of you who are already using CoCart and updated to WooCommerce 3.6, CoCart would die. Not cool!

But don’t worry for I have a patch in this release candidate that fixes the issue and requires your feedback to help me catch any further issues I may have missed before the final release.

To test CoCart 1.1.0 RC1, download the release candidate here (zip).

FYI

Since 1.1.0 is in a release candidate stage, only bug fixes will be made.

Think you’ve found a bug? Please post in detail to Github.