Excited to announce that CoCart Lite 2.7 is now publicly available! It has been in development since September 2020 and has been updated with 57 commits and 2 contributors.
This is a minor release but does come with a small change which is easily correctable on your end. Further details about that below. Everything else is backwards compatible with the previous version.
As always, it is recommend to create a backup of your site before updating.
What’s new in CoCart v2.7?
This release fixes a few bugs (two of which have been fixed by the CoCart community) and improved backwards compatibility with sites still using WooCommerce lower than version 4.3.0. As always, CoCart is tested with the latest release (v4.6) of WooCommerce to ensure compatibility is maintained.
More validation has been applied and now any data via the parameters are sanitized for more stable results.
FAIR WARNING!!! I made a grave error in the documentation when I released CoCart Lite version 2.1. In that release I introduced the ability to add an item to the cart via a SKU ID but forgot to correct the parameter table.
Some may have used this option already, others may have not. The parameter in question is the
product_id which is no longer meant to be a integer value but a string value.
Since little validation was applied to the REST API at the time, this was not addressed properly.
This has now been corrected in the documentation so you need to make sure the value passed via the
product_id parameter is a string and not integer when adding a product to the cart. Not changing this before updating CoCart Lite to v2.7 will result in an error. So please make the correction before updating.
Internal Use Supported
CoCart makes sure that the cart and session is not loaded on every REST API request that is not a CoCart route. After discussing a specific issue a developer was having, a new filter
cocart_is_rest_api_request was added in order to allow developers to run their own API check-up should CoCart be used internally via a custom REST API of their own.
This will help with any functions being undefined from CoCart.
To provide more control over the response returned for each API (excluding logout, count-items and totals), I have created a new filterable response.
This can be used to return what ever you like should you not use any of the filters available before hand. In order to first use the new filterable response, you need to set this filter
cocart_return_default_response to false so the new filtered responses are enabled.
A new feature added is the cart key returned via the header response. This is helpful for frameworks that don’t support cookies.
Once the first item is added the cart key is returned under
X-CoCart-API and can then be used to continue loading that cart via the
This is also helpful for when you are loading a cart in session to the web version of the store as you now know the cart key without looking it up.
Notable fixes and improvements
- Enhanced: Variable validation by removing parameters not used.
- Enhanced: REST API parameters sanitized and validated.
- Fixed: Undefined class constant E_WC_ADMIN_NOTE_MARKETING for those who are using WooCommerce lower than version 4.3.0. Thanks to @dmchale
- Fixed: If stock not available when updating item, return error. Thanks to @pauld8
- Fixed: Product ID validation should the ID not be present. Also returns correct product ID should SKU ID be used instead.
This release does not introduce any changes to the database.
The documentation has also been improved. Based on the user feedback, I have made things a little easier to navigate if you don’t use the search bar (under the CoCart logo).
I have done this by re-organized some of the content to be more categorized allowing you to quickly find specific things you want to do with CoCart or even support the use of CoCart within your own WooCommerce extension.
You will also now find quick links for applying specific filters. I have also included an example of adding a product to the cart via a SKU ID and updated the index JSON response to show the updated schema applied to some of the API’s.
It’s also important to know that I have made sure that the
cart_key parameter is applied to all API property tables including the documentation for CoCart Pro.
You can download the latest release of CoCart Lite here or visit Dashboard → Updates to update the plugin from your WordPress admin screen.
As usual, if you spot any other issues in the CoCart Lite, please log them in detail on GitHub.