Created
September 11, 2020 20:06
-
-
Save flymke/ad22b7ce99a21a1697a5042ce42a923f to your computer and use it in GitHub Desktop.
WooCommerce Germanized Pro 2.6.1 - clone packing slip page on PDF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* WooCommerce Germanized Pro 2.1.6 | |
* Function to clone packing slip on PDF | |
**/ | |
function my_clone_packing_slip( $attachment, $document ) { | |
if ( $document->type === 'packing_slip' ) { | |
WC_germanized_pro()->set_upload_dir_filter(); | |
$path = get_attached_file( $attachment ); | |
WC_germanized_pro()->unset_upload_dir_filter(); | |
if ( ! class_exists( 'Fpdi' ) ) { | |
require_once( 'fpdi/fpdi.php' ); // include FPDI library in your folder | |
} | |
if ( class_exists('TCPDF') && class_exists('Fpdi') ) { // TCPDF should be included by Germanized Pro | |
// initiate FPDI | |
$pdf = new Fpdi(); | |
$pageCount = $pdf->setSourceFile($path); | |
$tplIdx = $pdf->importPage(1, '/MediaBox'); | |
// remove default header/footer | |
$pdf->setPrintHeader( false ); | |
$pdf->setPrintFooter( false ); | |
$pdf->addPage(); | |
$pdf->useTemplate( $tplIdx, 0, 0 ); | |
$pdf->addPage(); | |
$pdf->useTemplate( $tplIdx, 0, 0 ); | |
$pdf->Output( $path, 'F' ); | |
} | |
} | |
} | |
add_action( 'woocommerce_gzdp_pdf_attachment_updated', 'my_clone_packing_slip', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment