hello everyone please,
as follows in the Script, i need to insert PHP Script inside the html code and i didn’t find any example in the documentationt that shows how to do that.
Is that possible right?
1° I use Wordpres
2° I use Woocommerce
3° I must print the thankyou Page. On the thankyou page i have a button that i click and download the file.
4° The PHP file that generate the PDF file must receive dynamic data.
5° The PHP Script must be included inside the html code as follows.
6° When i click on the button to download the PDF file, i got the following error message.
Notice: Undefined variable: order in C:xampppserver2htdocsmrdigitalwp-contentthemesastra-childtestmpdf.php on line 22
Fatal error: Uncaught Error: Call to a member function get_order_number() on null in C:xampppserver2htdocsmrdigitalwp-contentthemesastra-childtestmpdf.php:22 Stack trace: #0 {main} thrown in C:xampppserver2htdocsmrdigitalwp-contentthemesastra-childtestmpdf.php on line 22
This is the line 22
$order = $_GET[$order->get_order_number()];
This is the whole testmpdf.php file:
<?php
/**
* @Author: exame
* @Last Modified time: 2020-11-05 15:47:01
*/
use MpdfMpdf;
require_once __DIR__ . '/vendor/autoload.php';
$mpdf = new Mpdf();
$mpdf = new MpdfMpdf(['tempDir' => __DIR__ . '/custom/temp/dir/path']);
$mpdf = new MpdfMpdf([
'mode' => 'utf-8',
'orientation' => 'P',
'format' => 'A4'
]);
$order = $_GET[$order->get_order_number()];
$order = $_GET[$order->get_date_created()];
$html = '
<div id="pdfprintcontentarea">
<p class="woocommerce-notice woocommerce-notice--success woocommerce-thankyou-order-received">Obrigado. Seu pedido foi recebido. Enviamos o comprovante de compra por e-mail para você.</p>
<p>Tempo de Reserva do Pedido: <b>24 horas</b> - Por favor efetue o pagamento agora antes que você perca a reserva!</p>
<ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details">
<li class="woocommerce-order-overview__order order">
<strong>$order->get_order_number();</strong>
</li>
<li class="woocommerce-order-overview__date date">
Hora: <strong>10:56:01.507644</strong>
</li>
<li class="woocommerce-order-overview__date date">
<strong>wc_format_datetime( $order->get_date_created() );</strong>
</li>
<li class="woocommerce-order-overview__total total">
Total: <strong><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">R$</span>5,00</bdi></span></strong>
</li>
<li class="woocommerce-order-overview__total total">
Status Pedido: <strong>Aguardando</strong>
</li>
<li class="woocommerce-order-overview__payment-method method">
Método de pagamento: <strong>Transferência Bancária Rápida e Gratuita pelo Aplicativo do Banco</strong>
</li>
</div> <!-- <div id="pdfprintcontentarea"> -->
';
//$html = file_get_contents(__DIR__. '/woocommerce/checkout/thankyou.php');
$mpdf->SetProtection(array(),'','MyPassword');
$mpdf->WriteHTML($html,MpdfHTMLParserMode::HTML_BODY);// Load the html
$mpdf->Output('invoice.pdf',"D");
$mpdf->cleanup();
How can i turn around this situation please?
Thank you in Advance!
2
Answers
Thank you so much for the help. This is how i have turned around the situation.
1° You need to know that i customised my mPDF Composer installation inside my Template-Child and NOT inside the Default Root Folder.
2° I must definitivily to make reference to the Wordpress wp-config.php file, other wise this never would worked because of my customised installation.
3° I must definitivily to make reference to the Woocommerce Class class-wc-order.php file.
4° Now as follows in the code, i can receive the order object and manipulate what i need.
Code:
You need to run it after
wc_get_order
has been created, and also, find an easy way to get the order id. this is my proposed solution below.