Support » Plugin: WooCommerce PDF Invoices & Packing Slips » Suggestion for the FAQ

  • Resolved David Anderson

    (@davidanderson)


    Hi Ewout,

    Great plugin!

    A suggestion for your FAQ, so that other people don’t have to research this….

    Here’s the snippet to add a downloadable link to your “Thank you” page when someone orders:

    add_action('woocommerce_thankyou', 'my_woocommerce_thankyou');
    function my_woocommerce_thankyou($order_id) {
            $pdf_url = wp_nonce_url( admin_url( 'admin-ajax.php?action=generate_wpo_wcpdf&template_type=invoice&order_ids=' . $order_id . '&my-account'), 'generate_wpo_wcpdf' );
            echo '<p><a href="'.esc_attr($pdf_url).'">Download a printable invoice / payment confirmation (PDF format)</a></p>';
    }

    Best wishes,
    David

    https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Ewout

    (@pomegranate)

    Thanks for the compliment, and a great suggestion!
    I haven’t had the time to test this, but I was wondering what happens if someone clicks that link when they placed the order as a guest? People asked for this functionality before, but I didn’t include it because I thought that it wouldn’t work for guest purchases (simply because the user needs to be logged in to pass the security checks).

    Thanks!
    Ewout

    Thread Starter David Anderson

    (@davidanderson)

    Good point. My store doesn’t have guest check-outs. Should probably throw in a is_user_logged_in() check for those that do.

    David

    Plugin Author Ewout

    (@pomegranate)

    Thanks, will add it to the FAQ!

    Plugin Author Ewout

    (@pomegranate)

    I have made a slight alteration to the code, so that it doesn’t end up all the way at the bottom of the page:

    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->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;
    }

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Suggestion for the FAQ’ is closed to new replies.