Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Hello,
    Unfortunately, this is not possible with the current security settings: I limited PDF generation to administrators and logged in users. WordPress also uses nonces for security, but they are not safe enough for this purpose.

    That said, you can break this security by directly hooking into the plugin with your own script. You could do this by generating the PDF file from the woocommerce_thankyou action, something like:

    add_action( 'woocommerce_thankyou', 'generate_thank_you_pdf_invoice', 10, 1 );
    function generate_thank_you_pdf_invoice( $order_id ) {
    	global $wpo_wcpdf;
    	$invoice = $wpo_wcpdf->export->get_pdf( 'invoice', (array) $order_id );
    	$pdf_path = 'some/path/on/your/site/'.$order_id.'.pdf';
    	file_put_contents ( $pdf_path, $invoice );
    	unset($invoice);
    	echo '<a href="the/url/to/your/path/<?php echo $order_id; ?>.pdf">Download PDF Invoice</a>';
    }

    But you have to figure out yourself how to get those paths and urls and how to make this safe (you could make a random filename for example instead of the $order_id, or use some other kind of checks). Right now, this is beyond the scope of this plugin.

    Hope this helps you in the right direction!

    Ewout

    Thread Starter alpeshkumar.mca

    (@alpeshkumarmca)

    Hi,

    Thank’s Ewout,

    This is very useful for me.

    There are one change in your code that is

    add_action( 'woocommerce_thankyou', 'generate_thank_you_pdf_invoice', 10, 1 );
    function generate_thank_you_pdf_invoice( $order_id ) {
    	global $wpo_wcpdf;
    	$invoice = $wpo_wcpdf->export->get_pdf( 'invoice', (array) $order_id );
    	$pdf_path = 'some/path/on/your/site/'.$order_id.'.pdf';
    	file_put_contents ( $pdf_path, $invoice );
    	unset($invoice);
    	echo '<a href="the/url/to/your/path/<?php echo $order_id; ?>.pdf">Download PDF Invoice</a>';
    }

    to

    add_action( 'woocommerce_thankyou', 'generate_thank_you_pdf_invoice', 10, 1 );
    function generate_thank_you_pdf_invoice( $order_id ) {
    	global $wpo_wcpdf;
    	$invoice = $wpo_wcpdf->export->get_pdf( 'invoice', (array) $order_id );
    	$pdf_path = 'some/path/on/your/site/'.$order_id.'.pdf';
    	file_put_contents ( $pdf_path, $invoice );
    	unset($invoice);
    	echo '<a href="the/url/to/your/path/'.$order_id.'.pdf">Download PDF Invoice</a>';
    }

    But, Very Very thanks for valuable help.

    Hello People,

    I have used the same code but still not able to generate pdf.
    Its says “File Not Found”

    <?php
    add_action( ‘woocommerce_thankyou’, ‘generate_thank_you_pdf_invoice’, 10, 1 );
    function generate_thank_you_pdf_invoice( $order_id ) {
    global $wpo_wcpdf;
    $invoice = $wpo_wcpdf->export->get_pdf( ‘invoice’, (array) $order_id );
    $pdf_path = ‘/var/www/html/wpdemo/’.$order_id.’.pdf’;
    file_put_contents ( $pdf_path, $invoice );
    unset($invoice);
    echo ‘Download PDF Invoice‘;
    }
    ?>

    Website url

    Plugin Contributor Ewout

    (@pomegranate)

    Hello Cart Geek,
    I think the error in your code lies in the fact that you have the wrong url. You use the server path /var/www/html/wpdemo/ and then append that directly to the url, resulting in https://adevole.com/var/www/html/wpdemo/. It probably works when you remove the first part from the url path.

    Hope that helps!

    Ewout

    Thanx alott Ewout.. it worked ??

    Plugin Contributor Ewout

    (@pomegranate)

    Awesome!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to Display PDF on Thank you page’ is closed to new replies.