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;
?>