Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Shadi Manna

    (@shadim)

    Yes, the order id is contained within the label as the reference number.

    Thread Starter muhammadasad

    (@muhammadasad)

    We are using another custom order plugin which modifies the order numbers. I see that the reference number prints the default woocommerce id/post id. Is it possible to display/change the value printed in reference number of the generated label?

    Plugin Author Shadi Manna

    (@shadim)

    You can use the plugin filter “pr_shipping_dhl_label_args” to modify the arguments sent to the DHL API to add your custom order number:

    args[‘order_details’][‘order_id’] = custom order number

    You will need a developer to do this.

    Dear Shadi, I’m interested in the same solution. Could you possibly define the exact code of the filter so that I’d only have to set my own variable for the custom order number? This would be highly appreciated.
    Thanks

    Plugin Author Shadi Manna

    (@shadim)

    Take a look at this code:

    https://gist.github.com/shadimanna/b4a6ab1d4f8efcf6061cb5da3bbdb7e4

    It should be similar, you can change the “$args[‘dhl_settings’][‘dhl_label_ref’]” to any number you like and it should show up on the label.

    Dear Shadi, you very much for the code snippet. I tried it by adding a fixed value ‘123’ to the variable. But the label keeps on showing the order id. See below how I added the ‘123’. Do you see a mistake? I added the snippet at the very end of my functions.php.

    add_filter('pr_shipping_dhl_label_args', 'modify_order_id_to_number', 10, 2);
    function modify_order_id_to_number($args, $order_id) {
     	$order = wc_get_order( $order_id );
    	$args['dhl_settings']['dhl_label_ref'] = '123';
    	return $args;
    }
    Plugin Author Shadi Manna

    (@shadim)

    Apologies, you should replace:

    args[‘dhl_settings’][‘dhl_label_ref’]

    with

    args[‘order_details’][‘order_id’]

    And that should work.

    Dear Shadi, thank you very much! It works like a charm now! Also the function you suggested for getting the order number was just the right one.

    For everybody else: I used the snippet to get the order number that was given by the plugin German Market. Here is the final code that I used:

    add_filter('pr_shipping_dhl_label_args', 'modify_order_id_to_number', 10, 2);
    function modify_order_id_to_number($args, $order_id) {
     	$order = wc_get_order( $order_id );
    	$args['order_details']['order_id'] = $order->get_order_number();
    	return $args;
    }
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Can you add woocommerce order ID to printed label?’ is closed to new replies.