Download Invoice link with shortcode

WooCommerce PDF Invoices & Packing Slips comes with a useful shortcode to place a Download Invoice link in other pages, where you have access to the order ID. Alternatively you define the ID inside the order_id attribute.

Setting up the shortcode #

  • link_text=”” accepts any text. Ex: Download Invoice
  • order_id=”” accepts a number. Ex: 23

Simple shortcode with default attributes:

[wcpdf_download_invoice]

Shortcode with all atts customized:

[wcpdf_download_invoice link_text="Download your invoice" order_id="23"]

Inserting the shortcode a php file #

If you’re working directly in template files, you can also use this PHP code:

<?php echo do_shortcode('[wcpdf_download_invoice]'); ?>

Printing the download button on the Thank You page #

In theory, the shortcode can be used on any page you can edit in WordPress, but the “Thank You” page (also called the “Order received” page sometimes) is not editable by default (though there are various plugins out there that can enable this).

An alternative method to add the button to download the invoice PDF to the “Thank You” page without being editable is to use a small code snippet:

add_action( 'woocommerce_thankyou', function() {
    echo do_shortcode('[wcpdf_download_invoice]');
});

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