Title: Mult levels XML structure
Last modified: February 10, 2017

---

# Mult levels XML structure

 *  Resolved [baima](https://wordpress.org/support/users/baima/)
 * (@baima)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/mult-levels-xml-structure/)
 * Hi,
 * Is there a way to create XML with this structure? Could anyone give me a hint
   how?
 * TIA
 *     ```
       <?xml version='1.0' encoding='utf-8'?>
       <Orders>
         <Shop>
           <GUID>xxxxxx</GUID>
         </Shop>
         <Order>
           <OrderNumber>xxx</OrderNumber>
           <CustomerNumber>xxxx</CustomerNumber>
           <Addresses>
             <BillingAddress>
               <FirstName>xxxxxx</FirstName>
               <LastName>yyyyyy</LastName>
               <Street>xxxxxxxx</Street>
               <Zipcode>zzz</Zipcode>
               <City>xxx</City>
             </BillingAddress>
             <ShippingAddress>
               <FirstName>xxxxx</FirstName>
               <LastName>yyyy</LastName>
               <Street>zzzz</Street>
               <Zipcode>xxxx</Zipcode>
             </ShippingAddress>
           </Addresses>
           <LineItems>
             <LineItem>
               <Id>c022-0002</Id>
               <Name>xxxx</Name>
               <Quantity>xxx</Quantity>
             </LineItem>
             <LineItem>
               <Id>c025-0002</Id>
               <Name>yyyyy</Name>
               <Quantity>1</Quantity>
             </LineItem>
             <LineItemShipping>
               <Id>delivery</Id>
               <TotalPrice>0.00</TotalPrice>
               <Name>delivery</Name>
             </LineItemShipping>
             <LineItemPayment>
               <Id>CashInAdvance</Id>
               <TotalPrice>0.00</TotalPrice>
               <Name>Pre pay</Name>
             </LineItemPayment>
           </LineItems>
           <CreationDate>2011-01-20T01:41:33</CreationDate>
           <ShippedOn>2011-01-20T18:45:06</ShippedOn>
         </Order>
       </Orders>
       ```
   

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [algol.plus](https://wordpress.org/support/users/algolplus/)
 * (@algolplus)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/mult-levels-xml-structure/#post-8792812)
 * hello [@baima](https://wordpress.org/support/users/baima/)
 * try this code
    thanks, alex
 *     ```
       add_filter("woe_xml_output_after_root_tag","woe_xml_add_shopnfo");
       function woe_xml_add_shopnfo($text) {
        $text.="<Shop><GUID>xxxxxx</GUID></Shop>\n";
        return $text;
       }
   
       add_filter("woe_xml_output_filter","woe_xml_make_order");
       function woe_xml_make_order($xml) {
        // get order 
        $order = new WC_Order(WC_Order_Export_Data_Extractor::$current_order);
   
        //make xml
        $xml = new SimpleXMLElement( "<Order/>" );
   
        // top
        $xml->addChild("OrderNumber", $order->get_order_number() );
        $xml->addChild("CustomerNumber", $order->user_id );
   
        // addresses
        $addr = $xml->addChild("Addresses");
        $b_addr = $addr->addChild("BillingAddress");
        $b_addr->addChild("FirstName",$order->billing_first_name);
        $b_addr->addChild("LastName",$order->billing_last_name);
        $b_addr->addChild("Street", trim( $order->billing_address_1. " " . $order->billing_address_2) );
        $b_addr->addChild("Zipcode",$order->billing_postcode);
        $b_addr->addChild("City",$order->billing_city);
        $s_addr = $addr->addChild("ShippingAddress");
        $s_addr->addChild("FirstName",$order->shipping_first_name);
        $s_addr->addChild("LastName",$order->shipping_last_name);
        $s_addr->addChild("Street", trim( $order->shipping_address_1. " " . $order->shipping_address_2) );
        $s_addr->addChild("Zipcode",$order->shipping_postcode);
        $s_addr->addChild("City",$order->shipping_city);
   
        // items
        $items = $xml->addChild("LineItems");
        foreach ( $order->get_items('line_item') as $item_id=>$item ) {
          $product   = $order->get_product_from_item( $item );
          $item_meta = $order->get_item_meta( $item_id );
   
          $itemXML = $items->addChild("LineItem");
          $itemXML->addChild("Id",$product->sku);
          $itemXML->addChild("Name",$item['name']);
          $itemXML->addChild("Quantity",$item['qty']);
        }
   
   
        // shipment 
        $ship = $xml->addChild("LineItemShipping");
        $shipping_methods = $order->get_items( 'shipping' );
        $shipping_method = reset($shipping_methods); // take first entry
        $shipping_method_id =  !empty($shipping_method) ?  $shipping_method['method_id'] : '' ;
        $ship->addChild("Id",$shipping_method_id);
        $ship->addChild("TotalPrice",$order->get_total_shipping() );
        $ship->addChild("Name",$order->get_shipping_method() );
   
        // payment 
        $pay = $xml->addChild("LineItemPayment");
        $pay->addChild("Id",$order->payment_method);
        $pay->addChild("TotalPrice",$order->get_total() );
        $pay->addChild("Name",$order->payment_method_title );
   
        //bottom
        $xml->addChild("CreationDate", $order->order_date );
        $xml->addChild("ShippedOn", $order->completed_date );
   
        //format it!
        $dom = dom_import_simplexml( $xml );
        $dom->ownerDocument->formatOutput = true;
        return  $dom->ownerDocument->saveXML( $dom->ownerDocument->documentElement );
       }
       ```
   
 *  Plugin Author [algol.plus](https://wordpress.org/support/users/algolplus/)
 * (@algolplus)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/mult-levels-xml-structure/#post-8792871)
 * I’ve added this code to [code samples](http://algolplus.com/plugins/code-samples/)
 *  Thread Starter [baima](https://wordpress.org/support/users/baima/)
 * (@baima)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/mult-levels-xml-structure/#post-8794015)
 * Hi,
 * Thanks for your response. Here is the final release of code with few modifications,
   feel free to post it where you want)
 * If you have any kind of interest on a portuguese translation for your plugin,
   I already started it. Maybe we can have a deal about a pro version here 😉
 * Your plugin is a good job, one of a kind.. I already tested some others and “
   Export Suite” available at woocommerce is the one that come most close from yours.
   Although their exportations tasks hangs a lot.
 * Thanks
 * Claudio Baima
 *     ```
       <?php
       if ( !class_exists( 'woecutomized' ) ) {
       	class woecutomized {
       		function __construct() {
       			add_filter("woe_xml_output_after_root_tag", array($this,"woe_xml_add_shopnfo"));
       			add_filter("woe_xml_output_filter",         array($this,"woe_xml_make_order"));
       		}
       		function woe_xml_add_shopnfo($text) {
       			 $text.='<Shop>'.chr(13).'<GUID>' . $this->woe_guidv4() . '</GUID>'.chr(13).'</Shop>'.chr(13);
       			 return $text;
       		}
       		function woe_guidv4() {
       			if (function_exists('com_create_guid') === true)
       				return trim(com_create_guid(), '{}');
   
       			$data = openssl_random_pseudo_bytes(16);
       			$data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0100
       			$data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10
       			return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
       		}
       		function woe_xml_make_order($xml) {
       			// get order 
       			$order = new WC_Order(WC_Order_Export_Data_Extractor::$current_order);
       			$xml->preserveWhiteSpace = false;
       			$xml->formatOutput       = true;		
       			//make xml
       			$xml = new SimpleXMLElement( "<Order/>" );
   
       			// top
       			$fee_tax_total = self::woe_get_fee_items( $order );
   
       			$xml->addChild("OrderNumber",    $order->get_order_number() );
       			$xml->addChild("CustomerNumber", $order->user_id );
       			$xml->addChild("Currency", "EUR");
       			$xml->addChild("Language", "pt");
       			$xml->addChild("Locale",   "pt_PT");
       			$xml->addChild("TaxArea",  "EU");
       			$xml->addChild("TaxModel", "net");
       			$xml->addChild("GrandTotal",     number_format( $order->get_total(), 2, '.', '') );
       			$xml->addChild("TotalBeforeTax", number_format( $order->get_total()-$fee_tax_total, 2, '.', '') );
       			$xml->addChild("TotalTax",       number_format( $fee_tax_total, 2, '.', '') );			
       			// addresses
       			$addr = $xml->addChild("Addresses");
       			$b_addr = $addr->addChild("BillingAddress");
       			$b_addr->addChild("FirstName",$order->billing_first_name);
       			$b_addr->addChild("LastName",$order->billing_last_name);
       			$b_addr->addChild("Street", trim( $order->billing_address_1. " " . $order->billing_address_2) );
       			$b_addr->addChild("Zipcode",$order->billing_postcode);
       			$b_addr->addChild("City",$order->billing_city);
       			$s_addr = $addr->addChild("ShippingAddress");
       			$s_addr->addChild("FirstName",$order->shipping_first_name);
       			$s_addr->addChild("LastName",$order->shipping_last_name);
       			$s_addr->addChild("Street", trim( $order->shipping_address_1. " " . $order->shipping_address_2) );
       			$s_addr->addChild("Zipcode",$order->shipping_postcode);
       			$s_addr->addChild("City",$order->shipping_city);
   
       			// items
       			$items = $xml->addChild("LineItems");
       			foreach ( $order->get_items('line_item') as $item_id=>$item ) {
       				$product   = $order->get_product_from_item( $item );
       				$item_meta = $order->get_item_meta( $item_id );
   
       				$itemXML = $items->addChild("LineItem");
       				$itemXML->addChild("Id",$product->id);
       				$itemXML->addChild("Name",$item['name']);
       				$itemXML->addChild("Quantity",$item['qty']);
       			}
       			// shipment 
       			$ship = $xml->addChild("LineItemShipping");
       			$shipping_methods = $order->get_items( 'shipping' );
       			$shipping_method = reset($shipping_methods); // take first entry
       			$shipping_method_id =  !empty($shipping_method) ?  $shipping_method['method_id'] : '' ;
       			$ship->addChild("Id",$shipping_method_id);
       			$ship->addChild("TotalPrice",$order->get_total_shipping() );
       			$ship->addChild("Name",$order->get_shipping_method() );
   
       			// payment 
       			$pay = $xml->addChild("LineItemPayment");
       			$pay->addChild("Id",$order->payment_method);
       			$pay->addChild("TotalPrice",$order->get_total() );
       			$pay->addChild("Name",$order->payment_method_title );
   
       			//bottom
       			$xml->addChild("CreationDate", $order->order_date );
       			$xml->addChild("ShippedOn", $order->completed_date );
   
       			//format it!
       			$dom = dom_import_simplexml( $xml );
       			$dom->ownerDocument->formatOutput = true;
       			return  $dom->ownerDocument->saveXML( $dom->ownerDocument->documentElement );
       		}
       		private function woe_get_fee_items( $order ) {
       			$fee_tax_total = 0;
       			foreach ( $order->get_fees() as $fee_item_id => $fee ) {
       				$fee_tax_total += wc_format_decimal( $order->get_line_tax( $fee ), 2 );
       			}
       			return $fee_tax_total ;
       		}		
       	}
       }
       $woecutomized = new woecutomized;
       ?>
       ```
   
 *  Plugin Author [algol.plus](https://wordpress.org/support/users/algolplus/)
 * (@algolplus)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/mult-levels-xml-structure/#post-8794284)
 * hi Claudio
 * Yes, I’m interested in new translations. You can contact me to get pro version.
 * I studied all competitors before starting. Later some of them copied the features
   from my plugin 😉
 * thanks, alex
    -  This reply was modified 9 years, 3 months ago by [algol.plus](https://wordpress.org/support/users/algolplus/).
 *  Thread Starter [baima](https://wordpress.org/support/users/baima/)
 * (@baima)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/mult-levels-xml-structure/#post-8794533)
 * Ok… Please excuse me for start to cooperating here with some expressionson at
   the user interface that is not compatible with “__()” standards (not being translated),
   here they are:
 * – “Filter by coupons”
    – “Sort orders by “Order Id” in order” – “× Shipping methods”(
   on shipment filter) – “Set up fields to export” (button on firlfd to export area)–“
   Buy pro version to get access to profiles” (profile tab) – “Buy pro version to
   get access to scheduled reports” (schedule tab) – all expressions on tools tab
 * When I finished the portuguese translation, how can I send and contact you?
 *  Plugin Author [algol.plus](https://wordpress.org/support/users/algolplus/)
 * (@algolplus)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/mult-levels-xml-structure/#post-8795239)
 * hi
 * it’s a good news. I welcome bug reports 🙂
    it seems I didn’t rebuild pot file
   for free version.
 * please, use this form [http://algolplus.com/plugins/contact-us/](http://algolplus.com/plugins/contact-us/)
   
   thanks, alex

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Mult levels XML structure’ is closed to new replies.

 * ![](https://ps.w.org/woo-order-export-lite/assets/icon-256x256.png?rev=1365554)
 * [Advanced Order Export For WooCommerce](https://wordpress.org/plugins/woo-order-export-lite/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woo-order-export-lite/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woo-order-export-lite/)
 * [Active Topics](https://wordpress.org/support/plugin/woo-order-export-lite/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woo-order-export-lite/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woo-order-export-lite/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [algol.plus](https://wordpress.org/support/users/algolplus/)
 * Last activity: [9 years, 3 months ago](https://wordpress.org/support/topic/mult-levels-xml-structure/#post-8795239)
 * Status: resolved