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

Lifetime is back for a limited time

As we are all facing a difficult time, I decided to bring back the lifetime tier for a limited time for those who don’t like subscriptions. New price, one time payment.

The offer ends 30th April but may extend depending on the status of the global lockdown so get it while you can.

I have also added a founder edition where you can get CoCart Pro and show your support for a low fee each week. This is a contract subscription for a year minimum so you can’t cancel the subscription until at least a year is up.

More details on this tier is linked below.

Lifetime

Unlimited websites

$359– one time

Access to all pro add-ons plus all future pro add-ons.

Includes all Pro features, plugin updates and support for unlimited websites forever.

Early access to future features.

Founder

1 website

$9/week

Includes all Pro features, all add-ons, plugin updates and support every week for 1 website contracted for 1 year minimum.

Don’t forget those who are actively helping with the pandemic selling online, you can get your subscription extended.

In general, I hope everyone is staying healthy safe at home and enjoying time with family.

If you have any questions about either tiers, please contact me.

regards,

SΓ©bastien. πŸ™‚

6 things you can do with CoCart Products

If you have previously tried WooCommerce REST-API to retrieve products, you will have found that it has a few limitations and some parameters don’t provide options designed for frontend purposes.

Order By

One of the top things that is important when retrieving products is the order.

Here are the possible options you can order products by that the WooCommerce REST-API does not offer.

  • alphabetical – Products return alphabetical
  • reverse_alpha – Products return alphabetical in reverse
  • by_stock – Products return in order by stock amount
  • review_count – Products return in order of review count
  • on_sale_first – Products return in order of products on sale first
  • featured_first – Products return in order of featured first
  • price_asc – Products return in order of price in ascending order
  • price_desc – Products return in order of price in descending order
  • sales – Products return in order of total sales
  • rating – Products return in order of average review rating
curl -X GET https://wp-demo.cocart.xyz/wp-json/cocart/v1/products?orderby=price_desc \
  -H "Content-Type: application/json" \

Show Reviews

One cool thing you can do is retrieve the product reviews along with the product details for each product or an individual product without requesting them later.

Set show_reviews as true as a parameter in your request.

curl -X GET https://wp-demo.cocart.xyz/wp-json/cocart/v1/products?show_reviews=true \
  -H "Content-Type: application/json" \

Customer’s email address and location details are not returned.

Return all Variations

This particular option was requested by many but is also one that can produce a slow query response depending on how it is used and how many variations a particular product has.

Set return_variations as true as a parameter in your request and whether your returning many products or a single variable product, all variations and it’s details will return.

curl -X GET https://wp-demo.cocart.xyz/wp-json/cocart/v1/products?return_variations=true \
  -H "Content-Type: application/json" \

Get the right image size

In the WooCommerce REST-API, products only return the original image size uploaded for the product. That can be too much bandwidth depending on the filesize of the image.

With CoCart Β¨Products, you can get the image size of your choosing for the featured product image or any in the product gallery. All WordPress image sizes including the custom sizes WooCommerce create are returned and any custom image sizes that you register personally.

All image sizes return correctly if that particular size has the image resized. If the image size was registered after the image was uploaded then you will have to use regenerate thumbnails plugin or other of your choosing in order for the size to return correctly.

Here are the sizes available:

  • thumbnail
  • medium
  • medium_large
  • large
  • woocommerce_thumbnail
  • woocommerce_single
  • woocommerce_gallery_thumbnail
  • shop_catalog
  • shop_single
  • shop_thumbnail
  • full

Filter by Category or Tag

While this not new, the difference in CoCart Products REST-API is that you filter products by the category or tag slug instead of the ID, making it easier to remember what to filter the products by… for example “tshirts” instead “25”.

curl -X GET https://wp-demo.cocart.xyz/wp-json/cocart/v1/products?category=tshirts \
  -H "Content-Type: application/json" \

Submit Product Review

WooCommerce REST-API provides the same only it allows administrator’s to submit. CoCart Products allows customers to submit a review. This is the only feature that requires authentication.

curl -X POST https://wp-demo.cocart.xyz/wp-json/cocart/v1/products/reviews \
    -u username:password \
    -H "Content-Type: application/json" \
    -d '{
      "product_id": 329,
      "review": "Naughty Dog has done it again. This game is sick. I look forward to playing this over and over again like I did the first one. 5 stars does not do it justice. Game of the year for sure.",
      "reviewer": "John Doe",
      "reviewer_email": "john.doe@example.com",
      "rating": 5
    }'

Want a feature for CoCart Products? Send in your request.

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! πŸ˜€