It's easy to add custom product attributes to items using "product-attr-xxx". Custom
attributes are added as comma separated values to your item description in the Google
Shopping Cart. But what if you need to identify what they actually refer to?
The sample below is such a case. In each product below, you will need to know where
to print the text provided by your customer. A string of comma separated values
is insufficient.
This sample shows one way of accomplishing this. Note that this expands on the same sample
code provided in this web site. As such it may contain other functions/features
not necessarily relevant to this topic.
PayCircuit T-shirt
Price: $29.99
Color: Black
Brand: Paycircuit
Description The best shirt ever
Text to print on front:
Text to print on back:
Text to print on sleeves:
PayCircuit Coffee Mug
Price: $5.99
Text to print around mug:
Text to print on bottom of mug:
Source/Reference
JavaScript
This should be in <head> of your HTML
file, or you can create a .js file and reference it for easier management.
This code:
Modifies the product-attr-xxx text to allow you to identify each attribute
Important Notes:
Using this code prevents the Cart script from identifying the same item that already
exists in the cart. That is, if the add to cart button for the same item is clicked,
a new line item is added to the cart instead of increasing quantity.
Be aware of possible truncation: Maximum number of characters is unknown at this
time. Limiting number of characters for text input is highly recommneded. See HTML
source below for samples.
Only attributes with values set are "captured". That is, if no text is provided,
the attribute is not used.
Copy the code below and modify the
following for this to work:
Provide your own Merchant ID (replace the mid=000000000000000 with your own merchant
ID)
post-cart-to-sandbox="true" is for Sandbox testing with your Sandbox Merchant ID
post-cart-to-sandbox="false" for production/live use with your Production Merchant
ID
Usage Tips:
As stated, controlling maximum number of characters for text boxes is recommended.
This sample limits text entry to 50 characters (maxlength="50").
Use short descriptive attributes: i.e. product-attr-sleeves, product-attr-text-bottom.
They are used to identify the value: sleeves: text on sleve text-bottom: Hello, World