How to add customer details to the cart

Released in the core of CoCart in version 4.1. A cart callback was added that allows you to set the customers information to the cart.

How to use?

Make a post request at this endpoint.

/wp-json/cocart/v2/cart/update?namespace=update-customer

And pass the details of the customer for each of the fields that you require.

{
    "first_name": "Anakin",
    "last_name": "Skywalker",
    "email": "[email protected]",
    "phone": "01908672354",
    "company": "Darth Vadar LTD",
    "address_1": "70 The Crescent",
    "address_2": "", // Only if needed.
    "city": "BELFAST",
    "state": "", // Only if needed.
    "country": "GB",
    "postcode": "BT90 2PU"
}

What about shipping details?

Shipping details can only be applied if you have CoCart Plus or higher.

If your store ships items and allows customers to provide a different address other than the billing address provided. Extend the fields with a s_ prefix in front to identify the field is for shipping.

To apply the shipping address, set ship_to_different_address to true.

{
    "first_name": "Anakin",
    "last_name": "Skywalker",
    "email": "[email protected]",
    "phone": "01908672354",
    "company": "Darth Vadar LTD",
    "address_1": "70 The Crescent",
    "address_2": "",
    "city": "BELFAST",
    "state": "",
    "country": "GB",
    "postcode": "BT90 2PU",
    "s_first_name": "Sith",
    "s_last_name": "Lord",
    "s_address_1": "515 Cherry Drive",
    "s_city": "San Pablo",
    "s_state": "CA",
    "s_postcode": "94806",
    "s_country": "US",
    "s_company": "Galaxy Ruler LLC",
    "ship_to_different_address": true
}

Was this helpful to you?