Download link on the Thank You page
You can add a download link to the PDF invoice on the WooCommerce Thank You page with a small code snippet (filter).
Read this if you haven’t used wordpress filters / edited functions.php before!
Logged in users only
Due to security restrictions, only registered/logged in users will normally be able to download their invoices on the thank you page, this can be achieved using the code snippet below.
add_filter('woocommerce_thankyou_order_received_text', 'wpo_wcpdf_thank_you_link', 10, 2); function wpo_wcpdf_thank_you_link( $text, $order ) { if ( is_user_logged_in() ) { $pdf_url = wp_nonce_url( admin_url( 'admin-ajax.php?action=generate_wpo_wcpdf&template_type=invoice&order_ids=' . $order->get_id() . '&my-account'), 'generate_wpo_wcpdf' ); $text .= '<p><a href="'.esc_attr($pdf_url).'">Download a printable invoice / payment confirmation (PDF format)</a></p>'; } return $text; }
Enabling guest access
If you want guest users to be able to download their invoices on the thank you page too (without being logged in), you need to enable the ‘Guest access’ option on the Status tab of the WooCommerce PDF Invoices & Packing Slips settings.
You can then use a slightly altered version of the code above, replacing the ‘nonce’ with a unique ‘order_key’ value that acts as a password:
add_filter('woocommerce_thankyou_order_received_text', 'wpo_wcpdf_thank_you_link_guest_access', 10, 2); function wpo_wcpdf_thank_you_link_guest_access( $text, $order ) { $pdf_url = admin_url( 'admin-ajax.php?action=generate_wpo_wcpdf&template_type=invoice&order_ids=' . $order->get_id() . '&order_key=' . $order->get_order_key() ); $text .= '<p><a href="'.esc_attr($pdf_url).'">Download a printable invoice / payment confirmation (PDF format)</a></p>'; return $text; }
alternatively, you can hook this text to the woocommerce_thankyou
action, see this thread on the support forum.