I’m working on a workflow to generate delivery slip for woocommerce. To do that I need to provide the PDF generator API with the delivery slip content: order id, customer address, order date etc… but also list of ordered product with descriotion.
I’m now struggeling with product description as I need it to be an agragation of the product name and all the attributes (options).
For example:
Product name: A fancy t-shirt
Attributes:
color: blue
size : medium
At the end of the workflow I’d like to have something like:
My issue here is that when I loop the product attribute to update the description by adding the each attribute I end with as many product description as the number of attribute.
For example:
[
{
"product_description":
"my product description\nSize : Small"
},
{
"product_description":
"my product description\nColor : Orange"
}
]
How can I have at then end only one result with all the attributes ?
Hey ! Thanks for trying, but unfrotunaltely this is not what I expect. In you result you ave twice the same product but with different attribute. I need one product only with a concatenated attributes like:
Yes, that’s it. Interesting solution, thanks !
In between I have also been able to do that using code node with a Javascript function which is doing a similar action.
It works but I feel that both options are a bit complicated just to concatenate strings. Simple variable management would be so much clearer and easy to setup.
Thanks a lot for your help !
For those who are interested, here is my javascript function:
The issue is that your loop is creating a separate output item for each attribute instead of updating a single string. Each time the loop runs, it references the original “my product description” and appends only the current attribute, which is why you get two separate results.
The best solution is to avoid the loop entirely and format the string in a single step.
The Solution
First, remove the Split Out , Loop Over Items , and Aggregate nodes from your workflow.
Next, after your “Set attributes” node, add a new Set node. Inside this new node, create a field named product_description.
This expression takes the initial description and the full attributes array. The .map() function transforms the array into a cleaner format (like [“Size : Small”, “Color : Orange”]), and the .join(‘\n’) function combines them into a single string separated by new lines. Finally, it returns the complete, properly formatted description in one go.