Title: foreach loop
Last modified: January 25, 2025

---

# foreach loop

 *  Resolved [mariakos](https://wordpress.org/support/users/mariakos/)
 * (@mariakos)
 * [1 year, 4 months ago](https://wordpress.org/support/topic/foreach-loop-3/)
 * Hello, I have this kind of XML file:
 *     ```wp-block-code
       <products><crosssales><crosssale>11996</crosssale><crosssale>54020</crosssale></crosssales></products>
       ```
   
 * and I want to loop the **crosssale **value in order to add them **comma separeted**
   to the specific WC field “**Cross-Sells**“. According to your doc and if I am
   not mistaken I have this code:
 *     ```wp-block-code
       [FOREACH({crosssales/crosssale})]{.}[SEPARATOR,][ENDFOREACH]
       ```
   
 * But cross-sells products does not inserted at all. The values inside XML file
   is “**SKU**“s values.. Any help on that or ideas, please?

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Trey](https://wordpress.org/support/users/ix3/)
 * (@ix3)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/foreach-loop-3/#post-18273344)
 * Hey [@mariakos](https://wordpress.org/support/users/mariakos/),
 * You can use the XPath inside the FOREACH loop for this:
 *     ```wp-block-code
       {crosssales/crosssale}
       ```
   
 * Since the index is removed (the [1] in the XPath), WP All Import will loop through
   all instances of “crosssale” and output a comma-delimited list of them.
 * Also, for future reference, you can test the output of FOREACH loops and XPaths
   by placing them in the Content section of the import and clicking the “Preview”
   button.
 *  Thread Starter [mariakos](https://wordpress.org/support/users/mariakos/)
 * (@mariakos)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/foreach-loop-3/#post-18277766)
 * Hello [@ix3](https://wordpress.org/support/users/ix3/) thank you for your answer
 * The **preview tip**, was very helpful! Thanks a lot for that, I did not pass 
   from my mind
 * Although, I tried this one:
 * [FOREACH({crosssales/crosssale})]{.}[ENDFOREACH]
 * but I am getting all the crossale in a line.. Thus I have this: 1199654020
 * How to add comma seperated delimiter? and if I tried this one:
 * [FOREACH({crosssales/crosssale})]{.}[SEPARATOR,][ENDFOREACH] like I mentioned
   above, in the preview description content, I got this error:
 * _“Error parsing content: Unexpected token COMMA, statement was expected.”_
 * any help on that, on how to add comma delimiter please!;
 *  Thread Starter [mariakos](https://wordpress.org/support/users/mariakos/)
 * (@mariakos)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/foreach-loop-3/#post-18277827)
 * Hello again [@ix3](https://wordpress.org/support/users/ix3/)
 * I end up with this solution:
 * [FOREACH({crosssales/crosssale})]{.}**,**[ENDFOREACH]
 * added a comma after {.} .. Although, there is a trail comma. I have run the import
   and for one record and check the cross sales products are fine. Meaning there
   no errors I guess (orphans products, corrupted import or whatever0, correct? 
   Is this solution correct?
 * thanks in advance
 *  Plugin Author [Trey](https://wordpress.org/support/users/ix3/)
 * (@ix3)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/foreach-loop-3/#post-18278062)
 * Hi [@mariakos](https://wordpress.org/support/users/mariakos/),
 * Your solution should work fine. It would also work to put this in the field with
   no FOREACH loop:
 *     ```wp-block-code
       {crosssales/crosssale}
       ```
   

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘foreach loop’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce-xml-csv-product-import/assets/icon-256x256.png?
   rev=2570167)
 * [WP All Import – Product Import for WooCommerce](https://wordpress.org/plugins/woocommerce-xml-csv-product-import/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce-xml-csv-product-import/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce-xml-csv-product-import/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce-xml-csv-product-import/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce-xml-csv-product-import/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce-xml-csv-product-import/reviews/)

## Tags

 * [foreach loop](https://wordpress.org/support/topic-tag/foreach-loop/)

 * 4 replies
 * 2 participants
 * Last reply from: [Trey](https://wordpress.org/support/users/ix3/)
 * Last activity: [1 year, 3 months ago](https://wordpress.org/support/topic/foreach-loop-3/#post-18278062)
 * Status: resolved