I hope someone can help me.
What I would like to achieve:
I would like to create an automatic PDF invoice, as soon as an order has taken place and download it to a folder. It DOES NOT have to be displayed.
My problem:
I’m only concerned about the PDF creation. Somehow I can not create and download the PDF. I already read through similar questions on the subject here, but was not able to figure out the issue.
What I’ve done so far:
I have a plugin, into which the automatic billing has to be integrated. Within the plugin folder (…/wp-content/plugins/myplugin/) I have created a folder fpdf and installed fpdf.
The fpdf.php is located in … /myplugin/fpdf/fpdf.php
I have created a file with the following code for testing. This is also in the fpdf folder (… /myplugin/fpdf/pdf_creation.php):
<?php
require(plugin_dir_path( __FILE__ ).'fpdf/fpdf.php');
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
//$filename="/wp-content/plugins/myplugin/rechnungen/rechnung.pdf";
//$pdf->Output($filename,'F');
//testing output
$pdf->Output();
?>
What I get:
If I try to open the PDF directly in the browser, I get a http ERROR 500 (Chrome), in Firefox a white page.
Fatal error: Uncaught Error: Call to undefined function plugin_dir_path()….