Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.04 KB | None | 0 0
  1.  
  2. <?php /** Template Name: ProccesingXml **/ /*get_header();*/ //header("Content-Type: text/xml"); ?>
  3.     <?php
  4.  
  5.     global $woocommerce;
  6.  
  7.  
  8.     $args = array(
  9.         'post_type' => 'shop_order',
  10.         'post_status'       => 'publish',
  11.         'posts_per_page' => -1,
  12.         'tax_query' => array(
  13.             array(
  14.                 'taxonomy' => 'shop_order_status',
  15.                 'field' => 'slug',
  16.                 'terms' => array('wc-wachtbetaling')
  17.             )
  18.         )
  19.     );
  20.  
  21.  
  22.     $xmlDoc = new DOMDocument('1.0', 'UTF-8');
  23.     $root = $xmlDoc->appendChild($xmlDoc->createElement("root"));
  24.  
  25.  
  26.     $userIDS = array();
  27.     $orderLines = array();
  28.  
  29.  
  30.     $customer_orders = get_posts(apply_filters('woocommerce_my_account_my_orders_query', array(
  31.         'numberposts' => -1,
  32.         'post_type' => wc_get_order_types('view-orders'),
  33.         'post_status' => array('wc-wachtbetaling') // wc-processing
  34.     )));
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41. foreach ($customer_orders as $bestelling)
  42. {
  43.     $userID = get_post_meta($bestelling->ID, '_customer_user', true);
  44.  
  45.     if (!in_array($userID, $userIDS)) {
  46.         $userIDS[] = $userID;
  47.     }
  48.  
  49.  
  50.     $order_id = $bestelling->ID;
  51.  
  52.     $order = wc_get_order();
  53.     $order = new WC_Order($order_id);
  54.  
  55.     $oneLine = new stdClass();
  56.     $oneLine->order_ID = $order_id;
  57.     $oneLine->date = $bestelling->post_date;
  58.     $oneLine->dateyear = date("d-m-Y", strtotime($bestelling->post_date));
  59.     $oneLine->amount = $order->order_total;
  60.     $oneLine->amount_no_tax = $order->get_total() - $order->get_total_tax();
  61.     $oneLine->user = $userID;
  62.  
  63.     $orderLines[] = $oneLine;
  64.  
  65. }
  66.  
  67.  
  68. echo var_dump($orderLines);
  69.  
  70.    /* while ( $loop->have_posts() ) : $loop->the_post();
  71.  
  72.         echo var_dump(get_post_meta($loop->post->ID));
  73.  
  74.         if (!in_array($userID, $userIDS)) {
  75.             $userIDS[] = $userID;
  76.         }
  77.         $order_id = $loop->post->ID;
  78.  
  79.         $order = wc_get_order();
  80.         $order = new WC_Order($order_id);
  81.  
  82.         $oneLine = new stdClass();
  83.         $oneLine->order_ID = $order_id;
  84.         $oneLine->date = $bestelling->post_date;
  85.         $oneLine->dateyear = date("d-m-Y", strtotime($bestelling->post_date));
  86.         $oneLine->amount = $order->order_total;
  87.         $oneLine->amount_no_tax = $order->get_total() - $order->get_total_tax();
  88.         $oneLine->user = $userID;
  89.  
  90.         $orderLines[] = $oneLine;
  91.  
  92.         ?>
  93.     <?php endwhile; ?>*/
  94.  
  95.  
  96.  
  97.     $finalData = array();
  98.  
  99.     $count = 0;
  100.     foreach ($userIDS as $user) {
  101.         $User = $root->appendChild($xmlDoc->createElement("user"));
  102.         $userOrders = array();
  103.         $userData = array();
  104.         $ordernumbers = array();
  105.  
  106.  
  107.         foreach ($orderLines as $Order) {
  108.             if ($Order->user == $user && $count == 0 && !in_array($Order, $userOrders)) {
  109.                 $userOrders[] = $Order;
  110.  
  111.                 $order = new WC_Order($Order->order_ID);
  112.  
  113.                 $ordernummer = $order->get_order_number();
  114.  
  115.                 $factuurdatum = $Order->dateyear;
  116.                 $bedrag = $Order->amount;
  117.                 $userDisplay = $order->billing_company;
  118.  
  119.                 if(empty($userDisplay)){
  120.                     $userDisplay = get_user_by('ID', $user)->user_email;
  121.                 }
  122.  
  123.                 $bedragExBtw = $Order->amount_no_tax;
  124.  
  125.                 if(!empty($userDisplay)) {
  126.                     $orderA = array(
  127.                         'gebruiker' => $userDisplay,
  128.                         'ordernummer' => $ordernummer,
  129.                         'factuurdatum' => $factuurdatum,
  130.                         'bedrag Ex. BTW' => $bedragExBtw,
  131.                         'bedrag Inc. BTW' => $bedrag
  132.                     );
  133.  
  134.                     $userData[] = $orderA;
  135.                 }
  136.  
  137.  
  138.                 /*$xmlOrder = $User->appendChild($xmlDoc->createElement("order"));
  139.                 $xmlOrdernummer = $xmlOrder->appendChild($xmlDoc->createElement("ordernummer", $ordernummer));
  140.                 $xmlFactuurdatum = $xmlOrder->appendChild($xmlDoc->createElement("factuurdatum", date('d-m-Y', strtotime($factuurdatum))));
  141.                 $bedrag = $xmlOrder->appendChild($xmlDoc->createElement("bedrag", "€ " . $bedrag));
  142. */
  143.                 if(!in_array($userData,$finalData)){
  144.                     $finalData[] = $userData;
  145.                 }
  146.  
  147.             }
  148.         }
  149.  
  150.  
  151.     }
  152. //echo var_dump($finalData);
  153.     /*
  154. wp_mail('jascha@socialbrothers.nl', 'test', 'tteessttt');
  155.     $xmlDoc->preserveWhiteSpace = false;
  156.     $xmlDoc->formatOutput = true;
  157.     $xmlSave = $xmlDoc->saveXML();
  158.     //    return $xmlSave;
  159.     //        echo $xmlSave;*/
  160.  
  161.  
  162.     function cleanData(&$str)
  163.     {
  164.         $str = preg_replace("/\t/", "\\t", $str);
  165.         $str = preg_replace("/\r?\n/", "\\n", $str);
  166.         if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
  167.     }
  168.  
  169.     // filename for download
  170.     $filename = "website_data_" . date('Ymd') . ".xls";
  171.  
  172.     //header("Content-Disposition: attachment; filename=\"$filename\"");
  173.     //header("Content-Type: application/vnd.ms-excel");
  174.  
  175.  
  176.     ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement