Skip to content

Instantly share code, notes, and snippets.

View faridfox's full-sized avatar
🏠
Working from home

Farid Fox faridfox

🏠
Working from home
View GitHub Profile
@faridfox
faridfox / functions.php
Last active June 17, 2021 23:36
Show Download invoice PDF Link for WooCommerce PDF Invoices & Packing Slips in Thank you page with if condition.
<?php
// Show Download invoice PDF Link for WooCommerce PDF Invoices & Packing Slips in Thank you page with if condition.
// Original gist: https://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/download-link-on-the-thank-you-page/
// credits to David Anderson (@davidanderson) and Ewout (@pomegranate)
// add it to fuctions.php in your child theme (WordPress)
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>';