Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save helgatheviking/dfa4bf99f940d89a54d374589a1539ce to your computer and use it in GitHub Desktop.
Save helgatheviking/dfa4bf99f940d89a54d374589a1539ce to your computer and use it in GitHub Desktop.
Woocommerce Shipstation Integration tiny patch--xml output filter
/* Apologies for formatting, this was originally intended to be a ticket, but it errored. */
// Line 295 of Woocommerce Shipstation Integration 4.1.27 includes/api-requests/class-wc-shipstation-api-export.php is currently:
$orders_xml->appendChild( $order_xml );
// Proposed Change:
$orders_xml->appendChild( apply_filters( 'woocommerce_shipstation_export_order_xml', $order_xml) );
/*
Lots of ways this can be used, for example, pulling from a staging site and using an internal email so as not to notify customers when testing.
Or customizing "free shipping" output to be mapped, or any other fields, including the order items.
I've whipped up some code examples that could go in the documentation and show the utility of this:
*/
// changing customer email conditionally with simpleXML
public function export_order_xml( DOMElement $order_xml, DOMDocument $dom) {
if ( is_dev_site() ) {
$xml = simplexml_import_dom($order_xml);
$xml->Customer->BillTo->Email = 'shiptest@mydomain.com;
$order_xml = dom_import_simplexml($xml);
}
return $order_xml;
}
/*
Note that the $xml (DOMDocument) isn't used in this example, but is included in case devs aren't using simpleXML.
This lets them creating a new DOMDocument and receiving the "Wrong Document" Error" when appending. Example code for this (I'm inexpert with DOMDocument, bear with me):
*/
// Changing customer email conditionally with DOMDocument
public function export_order_xml( DOMElement $order_xml) {
if ( is_dev_site() ) {
$dom = $order_xml->ownerDocument;
$order_node = $dom->appendChild($order_xml);
$xp = new DOMXPath($dom);
$email = $xp->query('/Order/Customer/BillTo/Email')->item(0);
$new_email = $email->cloneNode();
$new_email->nodeValue = 'shiptest@mydomain.com';
$email->parentNode->replaceChild($new_email, $email);
}
return $order_node;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment