Skip to content

Instantly share code, notes, and snippets.

@simkoG
Created February 14, 2023 13:49
Show Gist options
  • Save simkoG/2ab8f456c3ca3cd83d47c761e7225c8f to your computer and use it in GitHub Desktop.
Save simkoG/2ab8f456c3ca3cd83d47c761e7225c8f to your computer and use it in GitHub Desktop.
<?php
defined( 'ABSPATH' ) || exit;
if( is_plugin_active( "woocommerce-pdf-invoice/woocommerce-pdf-invoice.php" ) ) :
/**
* Create a custom PDF preview page for the plugin.
*
* @since 1.0.0
* @return void
*/
function acme_woocommerce_pdf_preview_render() {
if( !is_admin() || !isset( $_GET['woocommerce_pdf_preview'] ) ) {
return;
}
if( !class_exists( 'WC_send_pdf' ) ){
include_once WP_PLUGIN_DIR . '/woocommerce-pdf-invoice/classes/class-pdf-send-pdf-class.php';
}
global $WC_send_pdf;
$test_order_id = 9522;
$pdf_content = $WC_send_pdf->get_woocommerce_invoice_content( wc_get_order( $test_order_id ) );
$pdf_content_base64 = base64_encode( $pdf_content );
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="<?php echo get_bloginfo( 'charset' ); ?>">
<title><?php esc_html_e( 'PDF Invoice', 'woocommerce-pdf-invoice' ); ?></title>
<style>
body {
background-color: #f7f7f7;
overflow: auto;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
#invoice-preview {
background: #fff;
display: block;
width: 210mm;
height: 297mm;
margin: 3rem auto;
border: 1px solid #ddd;
box-shadow: 0 10px 20px rgb( 0 0 0 / 10% );
}
</style>
</head>
<body>
<iframe id="invoice-preview" src="data:text/html;base64,<?php echo $pdf_content_base64; ?>">
Iframe is not supported.
</iframe>
</body>
</html>
<?php
die;
}
add_action( 'admin_init', 'acme_woocommerce_pdf_preview_render' );
endif; // is_plugin_active()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment