With CoCart v3 near a code freeze, I’m excited to share that the new API is more connected to the front-end of WooCommerce than before.
New matching filters are included for the cart response so you can connect any of the filters you may have already used in your WooCommerce extension to filter the cart template to do the same for CoCart.
For example, your extension may have changed how the subtotal displays in the cart using woocommerce_cart_item_subtotal
.
The same can be done for CoCart using cocart_cart_item_subtotal
returning the same results and using the same arguments the filter uses.
This enables your extension to be compatible no matter what the store owner decides to use. Its that simple and only one additional line of code is required.
Take WooCommerce Free Gift Coupons extension for example. All that is required for the subtotal to match via the REST API is to apply the matching filter like so.
add_filter( 'cocart_cart_item_price', array( 'WC_Free_Gift_Coupons', 'cart_item_price' ), 10, 2 );
Matching filters
WooCommerce Filter | CoCart Filter |
---|---|
woocommerce_cart_item_name | cocart_cart_item_name |
woocommerce_cart_item_price | cocart_cart_item_price |
woocommerce_cart_item_quantity | cocart_cart_item_quantity |
woocommerce_cart_item_subtotal | cocart_cart_item_subtotal |
If you need any assistance, you can join me and other developers in the CoCart Community via Slack.
I look forward to seeing more WooCommerce extensions supporting CoCart.
P.S. Not all matching filters can just be placed, some results may have to return formatted a little differently depending on how you have developed your extension for that particular area.