Khaled
Khaled

Reputation: 55

WP All Import CSV Loop through List

Using Wordpress, Woocommerce, WP ALL IMPORT Plugin to import products. My CSV has a JSON formatted data and a php List formatted data.

Example: a column colors in JSON format and another named food in PHP List format.

{
    "Color-1": "Red",
    "Color-2": "Green"
}

List:

[ "Pizza", "Burger", "Salad", "Pasta", "Sushi" ]

In the function editor in the plugin, I wrote a simple function to process the data:

<?php
function processData($jsonObject, $array) {
    // Decode JSON data into PHP array
    $object = json_decode($jsonObject, true);

    // Check for JSON decode errors
    if ($object === null) {
        return 'Error decoding JSON data.';
    }

    // Initialize result string
    $output = '';

    // Loop through the associative array and format the key-value pairs
    foreach ($object as $key => $value) {
        $output .= "$key $value\n";
    }

    // Format the array elements
    foreach ($array as $item) {
        $output .= $item . "\n";
    }

    // Return the result
    return $output;
}
?>

Then in the description text editor i used the function like this:

[processData({colorscolomn[1]}, {foodcolomn[1]})]

The json did work perfectly no problem. But I have tried everything for the list and it just never shows. Am I missing something?

How can i loop through a list in wp all import programtically in php?

Here are some screenshots to illustrate what I'm talking about:

enter image description here

enter image description here

Upvotes: 1

Views: 118

Answers (0)

Related Questions