Get value of custom product attributes?

I can add custom product attributes such as &color=green&size=XXL as documented here:

https://wiki.foxycart.com/v/2.0/cheat_sheet

Is there a way to extract the values of these custom attributes with FC.json? For example, I can get price, code and weight of the first item in the cart with:

FC.json.items[0].price
FC.json.items[0].code
FC.json.items[0].weight

But FC.json.items[0].color doesn't work.
Comments
  • This is for use with live rate shipping modifications by the way.

    https://wiki.foxycart.com/v/2.0/snippets/live_rate_shipping_modification
  • fc_adamfc_adam FoxyCart Team
    @ptheroux,

    Good question. Any custom attributes for a products will be accessible within FC.json.items[0].options - which is an array of the options which you can loop through to find the one you're after. Also for reference, you can explore the JSON by outputting FC.json in your browser's console when you're on the cart or checkout - and you'll be able to then see the structure of the information.
  • Thanks. that seems to work. If anyone else is interested, the code looks something like this:

    for (var j = 0; j < FC.json.items[0].options.length; j++) {
    this_class = FC.json.items[0].options[j].class;
    this_name = FC.json.items[0].options[j].name;
    this_value = FC.json.items[0].options[j].value;
    }
Sign In or Register to comment.