Skip to content

Instantly share code, notes, and snippets.

@WooForce
Last active April 22, 2016 07:45
Show Gist options
  • Save WooForce/47d58092c89f51154c455050009a3edc to your computer and use it in GitHub Desktop.
Save WooForce/47d58092c89f51154c455050009a3edc to your computer and use it in GitHub Desktop.
Canada Post - Add a custom description while printing label.
add_filter('wf_canadapost_request','wf_canadapost_label_request_callback', 10, 2 );
function wf_canadapost_label_request_callback($request,$order){
$custom_product_description = 'My product description'; // This text might not exceed 35 characters
$xml = new SimpleXMLElement($request);
if($xml->{'delivery-spec'}->{'destination'}->{'address-details'}->{'country-code'} != 'CA'){ //if international
$ref_no = $xml->{'delivery-spec'}->{'references'}->{'customer-ref-1'};
$custom_text = $ref_no.", ".$custom_product_description;
$xml->{'delivery-spec'}->{'references'}->{'customer-ref-1'} = substr($custom_text,0,35);
}
else
$xml->{'delivery-spec'}->{'references'}->{'customer-ref-2'} = $custom_product_description;
return $xml->asXML();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment