javascriptreactjse-commercecommerce.js

how to create extra field when capturing checkout in commerce js


i am using commerce js on my website and i want to create an extra field for getting phone number from user but commerce js does'nt have any documentation about extra_field. can any one tell me how to add it

i also created extra field in commerce js dashboard

commerce js dashboard

here is my order data object

const orderData = {
        line_items: checkoutToken.line_items,
        customer: {
          firstname: shippingData.firstName,
          lastname: shippingData.lastName,
          email: shippingData.email,
        },
        shipping: {
          name: "International",
          street: shippingData.address1,
          town_city: shippingData.city,
          county_state: shippingData.shippingSubdivision,
          postal_zip_code: shippingData.zip,
          country: shippingData.shippingCountry,
        },
        fulfillment: { shipping_method: shippingData.shippingOption },
        payment: {
          gateway: "stripe",
          stripe: {
            payment_method_id: paymentMethod.id,
          },
        },
        extra_fields: {
         contact: shippingData.contact,//its not working
        }
};

Solution

  • When capturing the order, provide the extra_fields object with each extra field ID as the key and the value you want to use.

    extra_fields: { [extraFieldId]: 'your custom field value' }

    from https://commercejs.com/docs/api/?shell#capture-order