CoCart v2.6.0 Release Candidate 1

CoCart is getting better and by that I mean with backwards compatibility, listening to users feedback and optimized better for future releases of WooCommerce.

WooCommerce 4.5 will be released on the 8th September which CoCart will release v2.6.0 just hours before so you can update with ease.

WooCommerce decided to bring back their REST API to the core of WooCommerce which changed a few things with the loading of the REST API but also made it better for CoCart Lite and the coming update of CoCart Pro. ?

With that change I was able to evaluate the code base for CoCart Lite and make some adjustments to keep CoCart maintained as is but opened more opportunities, some based on what my users have been asking for.

One thing I did apply is to check the site environment before CoCart is activated. This way users are actually notified if the environment does not meet the plugin minimum requirements before activating.

Previous notifications were added for WordPress and WooCommerce only telling users they had to upgrade either but not the environment.

While checks are in place to prevent the plugin from causing any fatal error if either requirement don’t meet once the plugin is activated, checking the site environment was missing.

So now if any of the plugin requirements do not meet, the plugin will automatically deactivate. It also means I won’t have to worry of getting support tickets from users who don’t have those minimum requirements.

I have also given site owners a little more control over CoCart which can be controlled via their wp-config.php file. This ensures only the site owner can perform certain actions.

Again this is a minor release and no changes to the CoCart API have changed.

Changelog

  • NEW: Added backwards compatibility for when set_customer_session_cookie() function is called.
  • NEW: Site environment is now checked before plugin activates.
  • NEW: Plugin will not activate if CoCart Pro v1.1.0 or above is installed.
  • Enhanced: Plugin to be better optimized for future releases of WooCommerce and to allow it to be packaged with CoCart Pro so user’s will not require CoCart Lite if Pro is installed.
  • Improved: uninstall.php file and now will only clear plugin data and remove the database table if COCART_REMOVE_ALL_DATA constant is set to true in user’s wp-config.php. This is to prevent data loss when deleting the plugin from the backend and to ensure only the site owner can perform this action.
  • Improved: Handling of admin menu by moving to it’s own class.
  • Tweaked: Admin notices to not redirect only to the plugins page once notice is dismissed. Will redirect to the current admin page.
  • Dev: Introduced the ability to white label the plugin. Meaning hide CoCart from the backend. (Admin menu, plugin links, plugin notices including WC admin inbox notices and WC system status information). All you have to do is set a constant COCART_WHITE_LABEL to true in user’s wp-config.php file.
  • Dev: New filter cocart_authenticate to override the determined user ID when authenticating. NOTE This will only be active if not already authenticated.
  • Tested: Compatible with WooCommerce v4.5.0

Testing

If you’d like to dive in and help test this new release, a handy CoCart Beta Tester allows you to download the latest beta version or release candidates from the CoCart GitHub repository before final release.

If you discover any bugs during the testing process, please let me know by logging a report in GitHub.

Thanks to all of my testers and contributors!

CoCart v2.1.2 Release Candidate 5

Final release candidate for v2.1.2 introducing support to prevent caching CoCart if you have WP REST API Cache plugin installed.

Testing has been going well so I am confident to release on the 4th June, 2020

Changelog

* NEW: Prevent CoCart from being cached with [WP REST API Cache plugin](https://wordpress.org/plugins/wp-rest-api-cache/).
* Tweaked: Check if product exists first before validating further.
* Tweaked: `cocart_update_cart_validation` filter passes `$current_data` fully.
* Tweaked: If validation for adding or updating item returned an error return error response.
* Dev: Added schema for cart route.
* Dev: Added schema for adding item route.
* Dev: Passed `$product_type` for `cocart_add_cart_item_data` filter.

If you discover any bugs during the testing process, please let me know by logging a report in GitHub.

Look forward to your feedback.

Thank you.

?

CoCart v2.1.2 Release Candidate 4

Changelog

Another minor release candidate that adds more validation. This time for when an item is updated.

Fixed: Cart removes items correctly if the product is no longer purchasable when cart contents is fetched.
Tweaked: Update item now validates if the product is sold individually to prevent item from updating if true.
Dev: Added filter cocart_update_cart_validation to allow plugin developers to pass their own validation before item is updated in the cart.

If you discover any bugs during the testing process, please let me know by logging a report in GitHub.

Look forward to your feedback.

?

CoCart v2.1.2 Release Candidate 3

After not having a smooth release for v2.1, for the last 2 weeks I have been working on fixing the issue. I’m pleased to say the issue is now fixed but before I can 100% confirm that I need your help to test it further in case anything else was missed.

Version 2.1 was removed from WordPress.org so users cant rollback to it and I have reverted the stable version to v2.0.13 until this release is ready.

Here is the comparison log from v2.0.13

If you discover any bugs during the testing process, please let me know by logging a report in GitHub.

Thanks to all of the testers and contributors!

What’s New?

Synchronised Carts

One of the issues users reported with v2.1 was that the carts were no longer in sync. This is because CoCart runs it’s own session handler to support guest customers but for a registered customer their carts were not matching.

This was because on the web version of your store, it was still utilizing WooCommerce core session handler and reading data from their session table.

This has been corrected so now both your web and headless store use the same session handler. ✅

CoCarts session handler is 100% compatible with any WooCommerce extension or custom code you may have applied to your store as the handler was forked and tweaked to add support for guest customers. It’s practically the same… only better. ?

Validating Products More

Variable products can be a hard time to manage and based on feedback, forgetting to pass or unable to pass the variation ID was one parameter users were failing to set correctly. Now you don’t have to as CoCart will get the variation ID based on the attributes you provide. ?

Even the attributes get validation so encase you forgot to pass required attributes you will now be told which attributes you forgot. If a variable product is not valid it will not add to the cart.

Speaking of not adding products. Password protected products can not be added either now.

Full Changelog from v2.1 to v2.1.2

* NEW: Added support for guest customers.
* NEW: Carts in session are stored in a new database table.
* NEW: Carts are in sync across the web store and your headless store.
* 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.
* NEW: Variable products are now validated and can find variation ID from attributes if not already set.
* NEW: Prevent password protected products from being added to the cart.
* Changed: Parameter used to set cart key. Previously `id` now `cart_key`. The `id` used as fallback if still used.
* Removed: Parameter to re-calculate totals once item was updated.
* Tweaked: Clear carts debug tool now clears saved carts as well.
* 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: Synchronize carts over to CoCart's session table in the database 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.2.x
> This update replaces WooCommerce core session handler with CoCart's. 100% compatible.

CoCart v2.1.0 Release Candidate 4

This is a small update to correct a bug for when setting the cart key via the id parameter so it is not overridden by the cookie set. This ensures the correct cart is returned if you are specifying a cart should the current cookie not update.

In addition to this patch I have also added a new route to enable you to provide a logout option for your customers. ?

curl -X POST https://example.com/wp-json/cocart/v1/logout

The reason for this addition is because developers were not clearing the cookie which stores the customers ID or cart key which is then used to load the cart on future requests so you don’t have to re-authenticate the customer per API request.

However, for additional debugging purposes I have added a filter that will override the cookie check so you don’t have to clear the cookie to test each customers cart.

Simply apply this snippet to your functions.php file and your good to go.

add_filter( 'cocart_override_cookie_check', function() { return true; });

Oh and since setting the cart via the id parameter did not update the cart expiry. I made another tweak so now it does. ?

Simply download and install the release candidate below, follow the work in progress documentation and report back to me if you come across a bug or have any questions.

Just a little reminder that I’m aiming to have v2.1 released on 8th May, 2020 unless another release candidate is required before then so get testing. ?

I want to say thank you for those who have been testing and reporting back feedback so far. It means a lot and I’m not just saying that.

Here’s what Joel from jppdesigns.co.uk had to say.

What can I say this thing has it all. It is the “Missing WooCommerce REST API plugin” without it I was managing users cart myself in weird and wonderful but hacky ways. NOT GOOD and so vulnerable. Then I stumbled upon CoCart and with the help of Seb I got it working how I needed it and he has been supporting me with even the smallest of queries. Really appreciate your work and continued support Seb.

Joel Pierre-Powell

CoCart v2.1.0 Release Candidate Available Now

Today is a special day. Today I’m very excited to share finally… a release candidate for CoCart v2.1 that has been months in the works and finally gets to see the light of day.

This release is a major milestone with many improvements. You have asked and been patient, now you shall receive. Support for guest customers. ?

Guest Customers ?

The long awaited feature is now available with the help of a new session handler. This session handler runs only during a CoCart API request meaning a guest customer will not have it’s cart items shared across between your web store and app.

Carts are stored for 30 days in the database and expired carts are cleared within a 6 hour window twice a day. Should there be an empty cart, they are set to expire within 6 hours. This helps reduce database overload.

Each session is now unique. No more shared carts.

There are also two methods of support for guest customers. By cookie or manually setting a unique cart key. The choice is yours.

Product Validation ✅

I have introduced new product handlers for when a product is being added to the cart as well as better validation methods. I have also introduced similar filters that are in the core of WooCommerce that will allow 3rd Party plugins or official WooCommerce extensions to include their product validations with ease.

With this improvement I have also added a minor validation for variable products to which they can not be added without a variation ID. This will be improved further over the next releases.

I have also made sure you can not add an external product by mistake.

Transfer Cart ?

A new requested feature is also available and that is to be able to transfer a cart from your headless store to the web store in order for your customers to checkout and pay for their order.

This helps those who are not using a payment gateway API such as Stripe to create orders and take payment within the app.

All responses are now filterable ?

Not all responses were filterable before. Now for each API request you get a successful or an error response, you can filter the response to change what they say or return. This allows for developers to have more options with their development.

Totals are automatically recalculated ?

To improve customer interaction and development requirements, the cart totals are recalculated once an item has been added to the cart or an item in the cart has been updated.

The additional parameter refresh_totals that was required before to do this can be removed from your query if you already used it.

This was not the case before as I was matching how WooCommerce handle the cart on the front-end which was not beneficial via an API and users were getting confused a lot about the totals not updating so now you don’t have to.

API Improvements

Because of the session changes made, if you are adding items to the cart via the web and then try to view the cart via the API via the browser, it will return blank.

The front-end and the API are two separate areas now in order to fully support sessions for guest customers. This is the same even if you are logged in.

I have also introduced a debug logging system to record the events of each request. This is only enabled via a filter.

<?php
add_filter( 'cocart_logging', function() { return true; });

Some code structure improvements have also been made in order to allow extending the API better, tested with WooCommerce v4.1 and this coming release will now require that you have version 5.0 of WordPress installed and PHP version 7 minimum.

The minimum version of WooCommerce required is now v3.6. This is to insure the code is kept up to date with latest changes in WooCommerce and secure.

Stats ?

As of writing this post, 79.3% of the plugin user base is now using version 2 which is fantastic.

The remaining user base is split across 2 versions. Version unknown is 6.3% and Version 1 still around 14.5%.

How do I test?

Simply download and install the release candidate below, follow the work in progress documentation and report back to me if you come across a bug or have any questions.

I’m aiming to have v2.1 released on 8th May, 2020 unless another release candidate is required before then so get testing.

P.S. If you haven’t already joined the community I recommend that you do and also take a look at the public roadmap to view what’s in development and what could be coming next.

Changelog for this release

  • 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.
  • 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 or 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.
  • Tested: Compatible with WooCommerce v4.1