• Resolved psorn

    (@psorn)


    Hi there,

    after switching to REST API, the prefix “order_” is added to the reference number.

    How can we delete this so the reference number is only the order id without this prefix (as it was before when using the SOAP API)?

    Thank you!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Saleem Summour

    (@sal4sup)

    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!

    Plugin Author Abdalsalaam Halawa

    (@abdalsalaam)

    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

    Plugin Author Saleem Summour

    (@sal4sup)

    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 );
    Thread Starter psorn

    (@psorn)

    Understood, thank you!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘SOAP –> REST: Reference number’ is closed to new replies.