• Resolved mariakos

    (@mariakos)


    Hello, I have this kind of XML file:

    <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:

    [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 Support Trey

    (@ix3)

    Hey @mariakos,

    You can use the XPath inside the FOREACH loop for this:

    {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

    (@mariakos)

    Hello @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

    (@mariakos)

    Hello again @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 Support Trey

    (@ix3)

    Hi @mariakos,

    Your solution should work fine. It would also work to put this in the field with no FOREACH loop:

    {crosssales/crosssale}
Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.