Support your extension for the new CoCart API

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 FilterCoCart Filter
woocommerce_cart_item_namecocart_cart_item_name
woocommerce_cart_item_pricecocart_cart_item_price
woocommerce_cart_item_quantitycocart_cart_item_quantity
woocommerce_cart_item_subtotalcocart_cart_item_subtotal
All filters use the same arguments and are in the same order.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.