// PDF format , just like invoice
// output order detailsa bove item list
add_action("woe_pdf_started", function ($pdf, $formatter) {
$reflection = new ReflectionClass($formatter);
$property = $reflection->getProperty('storage');
$property->setAccessible(true);
$storage = $property->getValue($formatter);
$addText = function ($hookRow) use ($pdf, &$addText, $storage) {
$storage->loadFull();
$rowObj = $storage->getRow(0);
if ( ! $rowObj) {
return $hookRow;
}
$offset = 0;
$row = $rowObj->getData();
$order = new WC_Order( $rowObj->getMetaItem( "order_id" ));
$billing = WC()->countries->get_formatted_address($order->get_address('billing'), PHP_EOL);
$shipping = WC()->countries->get_formatted_address($order->get_address('shipping'), PHP_EOL);
$x = $pdf->GetX();
$y = $pdf->GetY();
$rowHeight = 5;
$xOffset = 120;
$pdf->SetFont('', 'B');
$pdf->Cell(20, $rowHeight, "Billing address:");
$pdf->SetFont('');
$pdf->SetXY($x, $pdf->GetY() + $rowHeight);
$pdf->MultiCell(120, 120, $billing);
if($order->get_billing_phone()) {
$pdf->SetFont('', 'B');
$pdf->Cell(7, $rowHeight, "Tel:");
$pdf->SetFont('');
$pdf->Cell(10, $rowHeight, $order->get_billing_phone());
$pdf->SetXY($x, $pdf->GetY() + $rowHeight);
$offset += 20;
}
if($order->get_billing_email()) {
$pdf->SetFont('', 'B');
$pdf->Cell(10, $rowHeight, "Email: ");
$pdf->SetFont('');
$pdf->Cell(10, $rowHeight, $order->get_billing_email());
$pdf->SetXY($x, $pdf->GetY() + $rowHeight);
$offset += 20;
}
$pdf->SetXY($x + $xOffset, $y);
$pdf->SetFont('', 'B');
$pdf->Cell(20, $rowHeight, "Shipping address:");
$pdf->SetFont('');
$pdf->SetXY($x + $xOffset, $pdf->GetY() + $rowHeight);
$pdf->MultiCell(120, 120, $shipping);
$pdf->SetXY($x, $y + $offset);
remove_filter('woe_row_before_format_pdf', $addText);
return $hookRow;
};
add_filter('woe_row_before_format_pdf', $addText, 10, 1);
}, 10, 2);