How to remove Signature options from DHL shipping label, if the country is Switzerland?

With the following code snippet, you can remove signature options from the request (sent to DHL), if destination country is Switzerland.
Add the following code to Appearance > Editor > functions.php file.

add_filter( 'wf_dhl_label_request', 'wf_alter_dhl_request', 10, 2 );
function wf_alter_dhl_request($xmlRequest, $order_id){
global $woocommerce;
$order = new WC_Order($order_id);
if( $order->get_shipping_country() != 'US') {
return $xmlRequest;
}

$signature_options = array(‘SX’,’SA’,’SB’,’SC’,’SD’,’SE’,’SW’);
$xml_obj = new SimpleXMLElement($xmlRequest);
$i=0;
foreach ($xml_obj->SpecialService as $SpecialService) {
if( in_array($SpecialService->SpecialServiceType, $signature_options)){
unset($xml_obj->SpecialService[$i]);
}
$i++;
}

$doc = new DOMDocument();
$doc->formatOutput = TRUE;
$doc->loadXML($xml_obj->asXML());
return $doc->saveXML();
}

Using this, shipments to Switzerland will not throw an error if you have enabled the signature option for other countries.

 


To explore more details about the plugins, go check out ELEX WooCommerce DHL Express / eCommerce / Paket Shipping Plugin with Print Label.

Read the article for setting up DHL Express understand the plugin, in detail. Or check out the product documentation section for more related articles.

You can also check out other WooCommerce and WordPress plugins in ELEX.

    Leave a Reply