Variable text on top of Invoice

[ad_1]

Hi @panconpescao,

Try the following code snippet:

/**
* PDF Invoices & Packing Slips:
* Show a custom text after the document label for certaing shipping method IDs
*/
add_action( 'wpo_wcpdf_after_document_label', function( $document_type, $order ) {
if ( $document_type == 'invoice' ) {
// Check shipping methods
if ( ! empty( $shipping_methods = $order->get_shipping_methods() ) ) {
$first_method = array_shift( $shipping_methods );
$shipping_method_id = $first_method->get_method_id();
}

if ( $shipping_method_id == 'first_shipping_id' ) {
$custom_text="bluexpress";
} elseif ( $shipping_method_id == 'second_shipping_id' ) {
$custom_text="starken";
}
if ( $custom_text ) {
echo "<div style="margin: -10pt 0 10pt 0">$custom_text</div>";
}
}
}, 10, 2 );

If you haven’t worked with code snippets (actions/filters) or functions.php before, read this guide: How to use code snippets

Please note that you have to replace first_shipping_id and second_shipping_id with the actual shipping method IDs.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer