Woocommerce to XML Feed

Hello.

Can anybody help me or show me a way to convert from Woocommerce node to an XML Feed?

I can’t find any related examples.

Basically i just want to get some products from a woocommerce store and create an XML feed with specific columns from the products woo node.

So i managed somehow to do it but the problem is the XML feed creates n amount of feeds based on the products and not One feed with the products.

So i get the products with Woocommerce Node, Set the desired columns BUT

in the XML Node it creates 50 feeds just like how many products there are and not One feed with 50 products.

Any way to make it so all products are included inside … ?

Hey @Mulen, performing their action once for each individual item would be the default behaviour of most n8n nodes.

You could consider aggregating all of your items into a single item like so:

Afterwards, you’d have only a single XML item:

Hello @MutedJam .

Can you tell me how you did it?

Thanks.

Hey @Mulen, you can view the full code and copy it into your own n8n canvas by clicking on the link highlighted below:

If you can’t see the plugin showing the workflow it might be worth trying to reload the page while holding the Shift button, I do have this problem in Firefox sometimes.

Thanks yes, i use Firefox too and this problem occured to me.

I’ll try your workflow and adjust mine accordingly.

Thank you.

1 Like

Hey @MutedJam

I try to wrap every product inside a product tag.

I wrote this in the code

return {
  products: items.map(item => '<product>' + item.json + '</product>')
};

but it is not working.

I want to achieve an XML format like that

<products>
	<product>
		<EAN>8710522412718</EAN>
		<id>910535</id>
		<Net_Price>4.85</Net_Price>
		<Stock/>
	</product>
	<product>
		<EAN>5213006570070</EAN>
		<id>941646</id>
		<Net_Price>1.50</Net_Price>
		<Stock>221</Stock>
	</product>
	<product>
		<EAN>5202888221255</EAN>
		<id>942615</id>
		<Net_Price>7.55</Net_Price>
		<Stock>41</Stock>
	</product>
</products>

Any ideas?

Hey @Mulen, so the Function node would need to return JSON data. Meaning you’d need to return a product JSON key rather than XML, for example by running code like this:

return {
  products: items.map(item => {
    return {
      product: item.json
    }
  })
};

The conversion from JSON into XML is then handled by the subsequent XML node, returning the desired data structure:

Example Workflow:

1 Like

@MutedJam Thank you very much. I really appreciate it. It works flawless now.

1 Like