WooCommerce: How to add custom type product to car

2020-04-19 06:01发布

问题:

I'm building a mobile app using wooCommerce API with CoCart plugin to add custom Cart endpoints to WooCommerce

Everything works great for normal products type like simple or variable.

But my client using custom product type call 'yith-composite' that convert the product to parent and components ( children )

I need to do a custom endpoint to add this type of product to my cart in my mobile app.

The normal add to cart button on the site works great and by seening the header request from the devtoools was the following

ywcp_selection[153CE4EE-C1A0-6D39-9AD5-58B51C5AB306]: -1
attribute_pa_sphere: 7-50
ywcp_variation_id[153CE4EE-C1A0-6D39-9AD5-58B51C5AB306]: 124138
ywcp_quantity[153CE4EE-C1A0-6D39-9AD5-58B51C5AB306]: 1
ywcp_selected_product_value[153CE4EE-C1A0-6D39-9AD5-58B51C5AB306]: 102523
ywcp_selection[471BAD03-9C3B-B44E-8584-348A5F33F8A6]: -1
attribute_pa_sphere: 7-00
ywcp_variation_id[471BAD03-9C3B-B44E-8584-348A5F33F8A6]: 110356
ywcp_quantity[471BAD03-9C3B-B44E-8584-348A5F33F8A6]: 1
ywcp_selected_product_value[471BAD03-9C3B-B44E-8584-348A5F33F8A6]: 102552
quantity: 1
add-to-cart: 102491

I need to add same request but with JWT Token of the user on a custom endpoint