less than a minute read • Updated 9 minutes ago
Pass session variables through the cart
How to store custom data in the Foxy cart session and access it in the transaction datafeed.
Session variables let you store custom data in a customer’s cart session that is not tied to any specific product. This data is available in the cart JSON and is included in the transaction datafeed when an order is completed — useful for syncing custom fields between your system and Foxy.
How to set it up
Add any parameter prefixed with h: to a cart link or form:
https://YOURSTORE.foxycart.com/cart?name=Product+Name&price=10.00&h:customer_id=12345
Multiple session variables can be added in the same request:
https://YOURSTORE.foxycart.com/cart?name=Product+Name&price=10.00&h:customer_id=12345&h:affiliate_id=ABC
Accessing session variables in JavaScript
Session variables are available in FC.json.custom_fields:
FC.client.on('ready.done', function() {
console.log(FC.json.custom_fields.customer_id);
});
Adding session variables without adding a product
Use cart=view to add session variables to the cart without adding a product:
FC.client.on('ready.done', function() {
FC.client.request('https://' + FC.settings.storedomain + '/cart?h:foo=bar');
});
Notes
Session variables are not tied to products — they persist for the life of the session regardless of what products are in the cart.
Maximum value length is 700 characters.
Do not sign
h:values if using link and form validation.Session variables are included in the transaction XML datafeed on a completed order.