Skip to content

Instantly share code, notes, and snippets.

@Nishadup
Created July 17, 2018 11:39
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 Nishadup/fa19ba672cb0e9fe4574ea2c0442c805 to your computer and use it in GitHub Desktop.
Save Nishadup/fa19ba672cb0e9fe4574ea2c0442c805 to your computer and use it in GitHub Desktop.
Remove '-' from Canadian zip code from WooCommerce CanadaPost plugin https://www.xadapter.com/product/woocommerce-canada-post-shipping-plugin-with-print-label/
add_filter('xa_canadapost_rate_request', 'sanitize_postal_code_for_rate_req', 10, 2);
function sanitize_postal_code_for_rate_req($xmlRequest, $package){
$xml_obj = new SimpleXMLElement($xmlRequest);
if( isset($xml_obj->{'destination'}->{'domestic'}->{'postal-code'}) ){
$xml_obj->{'destination'}->{'domestic'}->{'postal-code'} = str_replace("-","",$xml_obj->{'destination'}->{'domestic'}->{'postal-code'} );
}
$doc = new DOMDocument();
$doc->formatOutput = TRUE;
$doc->loadXML($xml_obj->asXML());
return $doc->saveXML();
}
add_filter('wf_canadapost_request', 'sanitize_postal_code_for_label_req', 10, 2);
function sanitize_postal_code_for_label_req($xmlRequest, $order_id){
$xml_obj = new SimpleXMLElement($xmlRequest);
if($xml_obj->{'delivery-spec'}->{'destination'}->{'address-details'}->{'country-code'} == 'CA'){
$xml_obj->{'delivery-spec'}->{'destination'}->{'address-details'}->{'postal-zip-code'} = str_replace('-', "", $xml_obj->{'delivery-spec'}->{'destination'}->{'address-details'}->{'postal-zip-code'});
}
$doc = new DOMDocument();
$doc->formatOutput = TRUE;
$doc->loadXML($xml_obj->asXML());
return $doc->saveXML();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment