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;
}
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?
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.