Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php /** Template Name: ProccesingXml **/ /*get_header();*/ //header("Content-Type: text/xml"); ?>
- <?php
- global $woocommerce;
- $args = array(
- 'post_type' => 'shop_order',
- 'post_status' => 'publish',
- 'posts_per_page' => -1,
- 'tax_query' => array(
- array(
- 'taxonomy' => 'shop_order_status',
- 'field' => 'slug',
- 'terms' => array('wc-wachtbetaling')
- )
- )
- );
- $xmlDoc = new DOMDocument('1.0', 'UTF-8');
- $root = $xmlDoc->appendChild($xmlDoc->createElement("root"));
- $userIDS = array();
- $orderLines = array();
- $customer_orders = get_posts(apply_filters('woocommerce_my_account_my_orders_query', array(
- 'numberposts' => -1,
- 'post_type' => wc_get_order_types('view-orders'),
- 'post_status' => array('wc-wachtbetaling') // wc-processing
- )));
- foreach ($customer_orders as $bestelling)
- {
- $userID = get_post_meta($bestelling->ID, '_customer_user', true);
- if (!in_array($userID, $userIDS)) {
- $userIDS[] = $userID;
- }
- $order_id = $bestelling->ID;
- $order = wc_get_order();
- $order = new WC_Order($order_id);
- $oneLine = new stdClass();
- $oneLine->order_ID = $order_id;
- $oneLine->date = $bestelling->post_date;
- $oneLine->dateyear = date("d-m-Y", strtotime($bestelling->post_date));
- $oneLine->amount = $order->order_total;
- $oneLine->amount_no_tax = $order->get_total() - $order->get_total_tax();
- $oneLine->user = $userID;
- $orderLines[] = $oneLine;
- }
- echo var_dump($orderLines);
- /* while ( $loop->have_posts() ) : $loop->the_post();
- echo var_dump(get_post_meta($loop->post->ID));
- if (!in_array($userID, $userIDS)) {
- $userIDS[] = $userID;
- }
- $order_id = $loop->post->ID;
- $order = wc_get_order();
- $order = new WC_Order($order_id);
- $oneLine = new stdClass();
- $oneLine->order_ID = $order_id;
- $oneLine->date = $bestelling->post_date;
- $oneLine->dateyear = date("d-m-Y", strtotime($bestelling->post_date));
- $oneLine->amount = $order->order_total;
- $oneLine->amount_no_tax = $order->get_total() - $order->get_total_tax();
- $oneLine->user = $userID;
- $orderLines[] = $oneLine;
- ?>
- <?php endwhile; ?>*/
- $finalData = array();
- $count = 0;
- foreach ($userIDS as $user) {
- $User = $root->appendChild($xmlDoc->createElement("user"));
- $userOrders = array();
- $userData = array();
- $ordernumbers = array();
- foreach ($orderLines as $Order) {
- if ($Order->user == $user && $count == 0 && !in_array($Order, $userOrders)) {
- $userOrders[] = $Order;
- $order = new WC_Order($Order->order_ID);
- $ordernummer = $order->get_order_number();
- $factuurdatum = $Order->dateyear;
- $bedrag = $Order->amount;
- $userDisplay = $order->billing_company;
- if(empty($userDisplay)){
- $userDisplay = get_user_by('ID', $user)->user_email;
- }
- $bedragExBtw = $Order->amount_no_tax;
- if(!empty($userDisplay)) {
- $orderA = array(
- 'gebruiker' => $userDisplay,
- 'ordernummer' => $ordernummer,
- 'factuurdatum' => $factuurdatum,
- 'bedrag Ex. BTW' => $bedragExBtw,
- 'bedrag Inc. BTW' => $bedrag
- );
- $userData[] = $orderA;
- }
- /*$xmlOrder = $User->appendChild($xmlDoc->createElement("order"));
- $xmlOrdernummer = $xmlOrder->appendChild($xmlDoc->createElement("ordernummer", $ordernummer));
- $xmlFactuurdatum = $xmlOrder->appendChild($xmlDoc->createElement("factuurdatum", date('d-m-Y', strtotime($factuurdatum))));
- $bedrag = $xmlOrder->appendChild($xmlDoc->createElement("bedrag", "€ " . $bedrag));
- */
- if(!in_array($userData,$finalData)){
- $finalData[] = $userData;
- }
- }
- }
- }
- //echo var_dump($finalData);
- /*
- wp_mail('jascha@socialbrothers.nl', 'test', 'tteessttt');
- $xmlDoc->preserveWhiteSpace = false;
- $xmlDoc->formatOutput = true;
- $xmlSave = $xmlDoc->saveXML();
- // return $xmlSave;
- // echo $xmlSave;*/
- function cleanData(&$str)
- {
- $str = preg_replace("/\t/", "\\t", $str);
- $str = preg_replace("/\r?\n/", "\\n", $str);
- if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
- }
- // filename for download
- $filename = "website_data_" . date('Ymd') . ".xls";
- //header("Content-Disposition: attachment; filename=\"$filename\"");
- //header("Content-Type: application/vnd.ms-excel");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement