Created
July 17, 2018 11:39
-
-
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/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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