Hi @psorn,
with REST the plugin sets the reference like this by default: order_12345
If you want it back to just the WooCommerce order number, you can override it with a small code snippet in your theme’s functions.php:
add_filter( 'pr_shipping_dhl_label_args', 'custom_dhl_reference_number', 10, 2 );
function custom_dhl_reference_number( $args, $order_id ) {
$order = wc_get_order( $order_id );
if ( $order ) {
// Use only the WooCommerce order number
$args['refNo'] = $order->get_order_number();
}
return $args;
}
This will remove the order_ prefix and send only the order number in the reference field.
After adding the snippet, try creating a new label and you’ll see the updated reference.
Thread Starter
psorn
(@psorn)
Hi @sal4sup ,
Thank you for the snippet. However, it still shows the order_prefix. Could you please double check the snippet?
Thank you!
Hello @psorn
The order_ prefix was added intentionally when using the DHL REST API. This is because DHL requires the reference number to have a minimum length of 6 characters. In many cases, the raw WooCommerce order ID can be shorter than this requirement, so the prefix ensures the label request is always valid.
That said, you can easily customize or even remove the prefix using the filter below:
/**
* Modify or remove the DHL reference number prefix.
*/
add_filter( 'pr_shipping_dhl_paket_label_ref_no_prefix', function( $prefix ) {
// Remove the prefix entirely
return '';
// Or change it to something else, for example:
// return 'wc-';
});
If you remove the prefix, please just make sure that your order IDs are always at least 6 characters long, otherwise the DHL API may reject the request.
Thank you
Hi @psorn,
you can control the prefix with this filter:
add_filter( 'pr_shipping_dhl_paket_label_ref_no_prefix', function () {
return '';
}, 10 );
Please note: DHL requires the reference number (refNo) to be at least 8 characters long.
So if your WooCommerce order numbers are shorter than 8 digits, you’ll need to keep a short prefix (e.g. order-,or 0000) to meet the requirement.
example of code
add_filter( 'pr_shipping_dhl_paket_label_ref_no_prefix', function () {
return 'order-';
}, 10 );