PHP-файл для пользовательского CSV-файла экспорта woocommerce - PullRequest
0 голосов
/ 13 января 2019

Я создал php-код для ежедневного экспорта заказов из woocommerce через rest api, но я не могу правильно преобразовать данные json в csv-файл. Большое спасибо за вашу помощь.

 <?php
    $url = https://www.xxxxx.com/it/wp-json/wc/v3/orders?consumer_key=ck_be00e6768gh3641895fc113739ac2a266714a35b&consumer_secret=cs_69472477jki134fcea354c83a600be8e20eaf629&after=".date("Y-m-d")."T00:00:00Z&before=".date("Y-m-d")."T23:59:59Z&page=1&orderby=id&order=asc";
    $options = array(
    "http" => array(
    "header"  => "Content-type: text/json\r\n",
    "method"  => "GET",
    "content" => json_encode($request)
    ),
    );
    $context  = stream_context_create($options);
     //Decode the JSON and convert it into an associative array.
    $result = json_decode(file_get_contents($url, false, $context), true);
    //Give our CSV file a name.
    $nome ="my-orders-". date("Y-m-d").".csv";
    $csvFileName = $nome;
    //Open file pointer.
    $fp = fopen($csvFileName, 'w');
    //Loop through the associative array.
    foreach($result as $fields){
     //Write the row to the CSV file.
    fputcsv($fp, $fields, ','); 
    } 
    //Finally, close the file pointer.
    fclose($fp);  
    print_r($result); 
    ?>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...