Last active
June 17, 2021 23:36
-
-
Save faridfox/de08edaf4c5e7acb4933ed7bc4c7973f to your computer and use it in GitHub Desktop.
Show Download invoice PDF Link for WooCommerce PDF Invoices & Packing Slips in Thank you page with if condition.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>'; | |
return $text; | |
} else { | |
$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; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment