This last release candidate got delayed but one I think was worth the wait. I’m excited to announce that CoCart Lite v3.1 Release Candidate 4 is now available for testing! You can either download it directly from GitHub or install the CoCart Beta Tester plugin.
This release applies a few adjustments but more importantly I added a feature last minute, again, that users have been wanting and that is to set the price of an item as it’s being added to the cart.
A few new filters have also been introduced to help extend CoCart further should you need it.
See below for more details.
For a full recap on what’s new in v3.1 see the following previous posts before continuing:
- CoCart Lite v3.1 Beta 1
- CoCart Lite v3.1 Beta 2
- CoCart Lite v3.1 Release Candidate 2
- CoCart Lite v3.1 Release Candidate 3
What’s New since CoCart Lite v3.1 Release Candidate 3?
- NEW: Ability to set the price of the item you add to the cart with new cart cache system. – Simple Products and Variations ONLY!
- Enhanced: Clearing the cart will now return cart response and add original message response to the notices instead.
- Enhanced: Added shipping label to shipping details returned.
- Tweaked: Cron job for cleanup sessions and removed WooCommerce cron job for cleanup sessions as it is not needed.
- Tweaked: Updated Twitter handle for setup wizard.
- Uninstall: Will reschedule WooCommerce cron job for cleanup sessions.
- Dev: Introduced new filter
cocart_add_item_query_parameters
to allow developers to extend the query parameters for adding an item. - Dev: Introduced new filter
cocart_add_items_query_parameters
to allow developers to extend the query parameters for adding items. - Dev: Introduced new filter
cocart_cart_query_parameters
to allow developers to extend the query parameters for getting the cart. - Dev: Introduced new filter
cocart_override_cart_item
to override cart item for anything extra. - Dev: Introduced new filter
cocart_cart_shipping_label
to change the label “Shipping” to something else you prefer.
Set Price While Adding to Cart
This particular function is something that is normally programmed based on conditions that allows you to override the set price with the help of using WooCommerce’s action hook woocommerce_before_calculate_totals
.
The only possible option that was available at the time was for the store to have a WooCommerce extension called “Name Your Price” installed and pass the price via item data
.
curl -X POST https://example.com/wp-json/cocart/v2/cart/add-item \ -H "Content-Type: application/json" \ -d '{ "id": "129", "quantity": "1", "item_data": { "nyp": 24 } }'
However, that was more specific to validating the customers inputted price when adding any product to the cart that enabled the feature.
Now you can set the price how you like without any additional requirements using the new price parameter.
curl -X POST https://example.com/wp-json/cocart/v2/cart/add-item \ -H "Content-Type: application/json" \ -d '{ "id": "129", "quantity": "1", "price": 24 }'
To achieve this supported feature, a new cache system had to be created that would store a copy of the modified version of the item in session.
This is then used to set the new price before the totals are calculated.
That’s it. As long as that item is in the cart with the custom price, the sub-total will calculate based on that.
If the item is removed from the cart and is added again without the custom price, the original price will be used.
Database changes
This release does not introduce any changes to the database.
Documentation
Currently being updated but you can find some of the new examples above. Check again soon or follow CoCart on Twitter for updates.
Testing
If you discover any bugs during the testing process, please let me know by logging a report on the GitHub repository. There I can manage it better and get on the issue asap.