• Hello,

    I need to change Referenznr.: order_12345 to an invoice number from another plugin. Here is the code to get it:

    // Getting invoice number
    $invoice = wcpdf_get_invoice( (array) $order->get_id(), true );
    $invoice_number = $invoice->get_number();
    $plain_invoice_number = $invoice_number->get_plain();

    How can I edit the label template to change it and still keep the plugin updates?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Abdalsalaam Halawa

    (@abdalsalaam)

    Hello @donatory
    You can do it by this snippet :

    	add_filter('pr_shipping_dhl_label_args', 'modify_order_id_to_number', 10, 2);

    function modify_order_id_to_number( $args, $order_id ) {
    if ( function_exists( 'wcpdf_get_invoice' ) ) {
    $invoice = wcpdf_get_invoice( $order_id, true );
    $invoice_number = $invoice->get_number();
    $plain_invoice_number = $invoice_number->get_plain();

    $args['dhl_settings']['dhl_label_ref'] = $plain_invoice_number;
    }

    return $args;
    }
    Thread Starter Alexander

    (@donatory)

    Hello @abdalsalaam,
    Thank you for your reply!

    I asked the developer of the invoice plugin how to take data for use with other plugins and here is what he replied:

    You can use $invoice->get_number()->number or get the invoice number from the order data with the _wcpdf_invoice_number meta key.

    I wrote this code, but it doesn’t work:

    add_filter('pr_shipping_dhl_label_args', 'modify_order_id_to_number', 10, 2);

    function modify_order_id_to_number( $args, $order_id ) {
    // Get the invoice number using the meta key
    $invoice_number = get_post_meta( $order_id, '_wcpdf_invoice_number', true );

    // If the invoice number exists, add it to the label settings
    if ( ! empty( $invoice_number ) ) {
    $args['dhl_settings']['dhl_label_ref'] = $invoice_number;
    }

    return $args;
    }

    Then I created a new order, assigned it an invoice number and then created a DHL label.

    What am I doing wrong?

    Plugin Author Saleem Summour

    (@sal4sup)

    Hi @donatory ,

    Unfortunately, we don’t have experience with the plugin you mentioned. It looks like your current code alters the reference. I would recommend reaching out to the plugin author for guidance on how to retrieve the correct invoice number.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.