simkoG

acme-woocommerce-pdf-invoice-preview.php

Feb 14th, 2023 (edited)
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.81 KB | None | 0 0
  1. <?php
  2. defined( 'ABSPATH' ) || exit;
  3.  
  4. if( is_plugin_active( "woocommerce-pdf-invoice/woocommerce-pdf-invoice.php" ) ) :
  5.  
  6.  
  7.   /**
  8.    * Create a custom PDF preview page for the plugin.
  9.    *
  10.    * @since 1.0.0
  11.    * @return void
  12.    */
  13.  
  14.   function acme_woocommerce_pdf_preview_render() {
  15.     if( !is_admin() || !isset( $_GET['woocommerce_pdf_preview'] ) ) {
  16.       return;
  17.     }
  18.  
  19.     if( !class_exists( 'WC_send_pdf' ) ){
  20.       include_once WP_PLUGIN_DIR . '/woocommerce-pdf-invoice/classes/class-pdf-send-pdf-class.php';
  21.     }
  22.  
  23.     global $WC_send_pdf;
  24.  
  25.     $test_order_id = 9522;
  26.  
  27.     $pdf_content = $WC_send_pdf->get_woocommerce_invoice_content( wc_get_order( $test_order_id ) );
  28.     $pdf_content_base64 = base64_encode( $pdf_content );
  29.     ?>
  30.  
  31.     <!DOCTYPE html>
  32.     <html>
  33.       <head>
  34.         <meta charset="<?php echo get_bloginfo( 'charset' ); ?>">
  35.  
  36.         <title><?php esc_html_e( 'PDF Invoice', 'woocommerce-pdf-invoice' ); ?></title>
  37.  
  38.         <style>
  39.           body {
  40.             background-color: #f7f7f7;
  41.             overflow: auto;
  42.             -webkit-font-smoothing: antialiased;
  43.             -moz-osx-font-smoothing: grayscale;
  44.           }
  45.  
  46.           #invoice-preview {
  47.             background: #fff;
  48.             display: block;
  49.             width: 210mm;
  50.             height: 297mm;
  51.             margin: 3rem auto;
  52.             border: 1px solid #ddd;
  53.             box-shadow: 0 10px 20px rgb( 0 0 0 / 10% );
  54.           }
  55.         </style>
  56.       </head>
  57.       <body>
  58.  
  59.         <iframe id="invoice-preview" src="data:text/html;base64,<?php echo $pdf_content_base64; ?>">
  60.           Iframe is not supported.
  61.         </iframe>
  62.  
  63.       </body>
  64.     </html>
  65.  
  66.     <?php
  67.     die;
  68.   }
  69.  
  70.   add_action( 'admin_init', 'acme_woocommerce_pdf_preview_render' );
  71.  
  72.  
  73. endif; // is_plugin_active()
  74.  
Add Comment
Please, Sign In to add comment