Version Description
April, 15, 2017 =
Added: Filter 'bewpi_my_account_pdf_name' to change the name of the PDF button on My Account page.
Fixed: 'Fatal error: Call to a member function get_id() on null' by checking object type in method
add_emailitin_as_recipient()
.
Download this release
Release Info
Developer | baaaaas |
Plugin | WooCommerce PDF Invoices |
Version | 2.7.2 |
Comparing to | |
See all releases |
Code changes from version 2.7.1 to 2.7.2
- bootstrap.php +3 -3
- includes/abstracts/abstract-bewpi-document.php +9 -8
- includes/abstracts/abstract-bewpi-invoice.php +7 -8
- includes/be-woocommerce-pdf-invoices.php +20 -7
- includes/class-bewpi-debug-log.php +174 -0
- includes/class-bewpi-template.php +3 -3
- includes/functions.php +22 -0
- readme.txt +10 -4
bootstrap.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: WooCommerce PDF Invoices
|
4 |
* Plugin URI: https://wordpress.org/plugins/woocommerce-pdf-invoices
|
5 |
* Description: Automatically generate and attach customizable PDF Invoices to WooCommerce emails and connect with Dropbox, Google Drive, OneDrive or Egnyte.
|
6 |
-
* Version: 2.7.
|
7 |
* Author: Bas Elbers
|
8 |
* Author URI: http://wcpdfinvoices.com
|
9 |
* License: GPL-2.0+
|
@@ -19,9 +19,9 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
19 |
/**
|
20 |
* @deprecated instead use WPI_VERSION.
|
21 |
*/
|
22 |
-
define( 'BEWPI_VERSION', '2.7.
|
23 |
|
24 |
-
define( 'WPI_VERSION', '2.7.
|
25 |
|
26 |
/**
|
27 |
* Load WooCommerce PDF Invoices plugin.
|
3 |
* Plugin Name: WooCommerce PDF Invoices
|
4 |
* Plugin URI: https://wordpress.org/plugins/woocommerce-pdf-invoices
|
5 |
* Description: Automatically generate and attach customizable PDF Invoices to WooCommerce emails and connect with Dropbox, Google Drive, OneDrive or Egnyte.
|
6 |
+
* Version: 2.7.2
|
7 |
* Author: Bas Elbers
|
8 |
* Author URI: http://wcpdfinvoices.com
|
9 |
* License: GPL-2.0+
|
19 |
/**
|
20 |
* @deprecated instead use WPI_VERSION.
|
21 |
*/
|
22 |
+
define( 'BEWPI_VERSION', '2.7.2' );
|
23 |
|
24 |
+
define( 'WPI_VERSION', '2.7.2' );
|
25 |
|
26 |
/**
|
27 |
* Load WooCommerce PDF Invoices plugin.
|
includes/abstracts/abstract-bewpi-document.php
CHANGED
@@ -17,6 +17,7 @@ if ( ! class_exists( 'BEWPI_Abstract_Document' ) ) {
|
|
17 |
* Class BEWPI_Abstract_Document.
|
18 |
*/
|
19 |
abstract class BEWPI_Abstract_Document {
|
|
|
20 |
/**
|
21 |
* Type of document like invoice, packing slip or credit note.
|
22 |
*
|
@@ -77,10 +78,10 @@ if ( ! class_exists( 'BEWPI_Abstract_Document' ) ) {
|
|
77 |
* BEWPI_Abstract_Document constructor.
|
78 |
*/
|
79 |
public function __construct() {
|
80 |
-
$templater
|
81 |
$templater->set_order( $this->order );
|
82 |
-
$this->template
|
83 |
-
$this->general_options
|
84 |
$this->template_options = get_option( 'bewpi_template_settings' ); // @todo remove and use 'templater()'.
|
85 |
}
|
86 |
|
@@ -91,13 +92,12 @@ if ( ! class_exists( 'BEWPI_Abstract_Document' ) ) {
|
|
91 |
* @param bool $is_paid WooCommerce order paid status.
|
92 |
*/
|
93 |
protected function generate( $destination, $is_paid ) {
|
94 |
-
|
95 |
-
$order_id = method_exists( 'WC_Order', 'get_id' ) ? $this->order->get_id() : $this->order->id;
|
96 |
|
97 |
do_action( 'bewpi_before_invoice_content', $order_id );
|
98 |
|
99 |
// Only use default font with version 2.6.2- because we defining font in template.
|
100 |
-
$default_font
|
101 |
$is_new_template = 'minimal' === $this->template_options['bewpi_template_name'];
|
102 |
|
103 |
$mpdf_params = apply_filters( 'bewpi_mpdf_options', array(
|
@@ -113,7 +113,7 @@ if ( ! class_exists( 'BEWPI_Abstract_Document' ) ) {
|
|
113 |
'margin_footer' => ( $is_new_template ) ? 0 : 6,
|
114 |
'orientation' => 'P',
|
115 |
) );
|
116 |
-
$mpdf
|
117 |
$mpdf_params['mode'],
|
118 |
$mpdf_params['format'],
|
119 |
$mpdf_params['default_font_size'],
|
@@ -164,6 +164,7 @@ if ( ! class_exists( 'BEWPI_Abstract_Document' ) ) {
|
|
164 |
|
165 |
$html = $this->get_html();
|
166 |
if ( count( $html ) === 0 ) {
|
|
|
167 |
return;
|
168 |
}
|
169 |
|
@@ -230,7 +231,7 @@ if ( ! class_exists( 'BEWPI_Abstract_Document' ) ) {
|
|
230 |
*/
|
231 |
public static function view( $full_path ) {
|
232 |
$general_options = get_option( 'bewpi_general_settings' );
|
233 |
-
$type
|
234 |
|
235 |
header( 'Content-type: application/pdf' );
|
236 |
header( 'Content-Disposition: ' . $type . '; filename="' . basename( $full_path ) . '"' );
|
17 |
* Class BEWPI_Abstract_Document.
|
18 |
*/
|
19 |
abstract class BEWPI_Abstract_Document {
|
20 |
+
|
21 |
/**
|
22 |
* Type of document like invoice, packing slip or credit note.
|
23 |
*
|
78 |
* BEWPI_Abstract_Document constructor.
|
79 |
*/
|
80 |
public function __construct() {
|
81 |
+
$templater = BEWPI()->templater();
|
82 |
$templater->set_order( $this->order );
|
83 |
+
$this->template = $templater->get_template( $this->type );
|
84 |
+
$this->general_options = get_option( 'bewpi_general_settings' ); // @todo remove.
|
85 |
$this->template_options = get_option( 'bewpi_template_settings' ); // @todo remove and use 'templater()'.
|
86 |
}
|
87 |
|
92 |
* @param bool $is_paid WooCommerce order paid status.
|
93 |
*/
|
94 |
protected function generate( $destination, $is_paid ) {
|
95 |
+
$order_id = bewpi_get_id( $this->order );
|
|
|
96 |
|
97 |
do_action( 'bewpi_before_invoice_content', $order_id );
|
98 |
|
99 |
// Only use default font with version 2.6.2- because we defining font in template.
|
100 |
+
$default_font = ( version_compare( WPI_VERSION, '2.6.2' ) <= 0 ) ? 'opensans' : '';
|
101 |
$is_new_template = 'minimal' === $this->template_options['bewpi_template_name'];
|
102 |
|
103 |
$mpdf_params = apply_filters( 'bewpi_mpdf_options', array(
|
113 |
'margin_footer' => ( $is_new_template ) ? 0 : 6,
|
114 |
'orientation' => 'P',
|
115 |
) );
|
116 |
+
$mpdf = new mPDF(
|
117 |
$mpdf_params['mode'],
|
118 |
$mpdf_params['format'],
|
119 |
$mpdf_params['default_font_size'],
|
164 |
|
165 |
$html = $this->get_html();
|
166 |
if ( count( $html ) === 0 ) {
|
167 |
+
BEWPI()->logger()->error( sprintf( 'PDF generation aborted. No HTML for PDF in %1$s:%2$s', __FILE__, __LINE__ ) );
|
168 |
return;
|
169 |
}
|
170 |
|
231 |
*/
|
232 |
public static function view( $full_path ) {
|
233 |
$general_options = get_option( 'bewpi_general_settings' );
|
234 |
+
$type = ( 'browser' === $general_options['bewpi_view_pdf'] ) ? 'inline' : 'attachment';
|
235 |
|
236 |
header( 'Content-type: application/pdf' );
|
237 |
header( 'Content-Disposition: ' . $type . '; filename="' . basename( $full_path ) . '"' );
|
includes/abstracts/abstract-bewpi-invoice.php
CHANGED
@@ -72,8 +72,7 @@ if ( ! class_exists( 'BEWPI_Abstract_Invoice' ) ) {
|
|
72 |
|
73 |
$this->full_path = self::exists( $order_id );
|
74 |
if ( $this->full_path ) {
|
75 |
-
|
76 |
-
$order_id = method_exists( 'WC_Order', 'get_id' ) ? $this->order->get_id() : $this->order->id;
|
77 |
|
78 |
$this->number = get_post_meta( $order_id, '_bewpi_invoice_number', true );
|
79 |
$this->date = get_post_meta( $order_id, '_bewpi_invoice_date', true );
|
@@ -240,7 +239,7 @@ if ( ! class_exists( 'BEWPI_Abstract_Invoice' ) ) {
|
|
240 |
// uses WooCommerce order numbers as invoice numbers?
|
241 |
if ( 'woocommerce_order_number' === $this->template_options['bewpi_invoice_number_type'] ) {
|
242 |
// WC backwards compatibility.
|
243 |
-
$order_id =
|
244 |
|
245 |
return $order_id;
|
246 |
}
|
@@ -305,7 +304,7 @@ if ( ! class_exists( 'BEWPI_Abstract_Invoice' ) ) {
|
|
305 |
*/
|
306 |
public function save( $destination = 'F' ) {
|
307 |
// WC backwards compatibility.
|
308 |
-
$order_id =
|
309 |
|
310 |
if ( BEWPI_Invoice::exists( $order_id ) ) {
|
311 |
// delete postmeta and PDF.
|
@@ -398,7 +397,7 @@ if ( ! class_exists( 'BEWPI_Abstract_Invoice' ) ) {
|
|
398 |
*/
|
399 |
public function display_vat_number() {
|
400 |
// WC backwards compatibility.
|
401 |
-
$order_id =
|
402 |
|
403 |
$vat_number = get_post_meta( $order_id, '_vat_number', true );
|
404 |
if ( ! empty( $vat_number ) ) {
|
@@ -417,7 +416,7 @@ if ( ! class_exists( 'BEWPI_Abstract_Invoice' ) ) {
|
|
417 |
|
418 |
if ( isset( $payment_method ) && 'woocommerce_gateway_purchase_order' === $payment_method ) {
|
419 |
// WC backwards compatibility.
|
420 |
-
$order_id =
|
421 |
|
422 |
$po_number = get_post_meta( $order_id, '_po_number', true );
|
423 |
if ( ! empty( $po_number ) ) {
|
@@ -554,7 +553,7 @@ if ( ! class_exists( 'BEWPI_Abstract_Invoice' ) ) {
|
|
554 |
*/
|
555 |
public function display_zero_rated_vat() {
|
556 |
// WC backwards compatibility.
|
557 |
-
$order_id =
|
558 |
|
559 |
$is_vat_valid = get_post_meta( $order_id, '_vat_number_is_valid', true );
|
560 |
if ( ! $is_vat_valid ) {
|
@@ -578,7 +577,7 @@ if ( ! class_exists( 'BEWPI_Abstract_Invoice' ) ) {
|
|
578 |
*/
|
579 |
private function replace_placeholders( $str ) {
|
580 |
// WC backwards compatibility.
|
581 |
-
$order_id =
|
582 |
|
583 |
$placeholders = apply_filters( 'bewpi_placeholders', array(
|
584 |
'[payment_method]' => method_exists( 'WC_Order', 'get_payment_method_title' ) ? $this->order->get_payment_method_title() : $this->order->payment_method_title,
|
72 |
|
73 |
$this->full_path = self::exists( $order_id );
|
74 |
if ( $this->full_path ) {
|
75 |
+
$order_id = bewpi_get_id( $this->order );
|
|
|
76 |
|
77 |
$this->number = get_post_meta( $order_id, '_bewpi_invoice_number', true );
|
78 |
$this->date = get_post_meta( $order_id, '_bewpi_invoice_date', true );
|
239 |
// uses WooCommerce order numbers as invoice numbers?
|
240 |
if ( 'woocommerce_order_number' === $this->template_options['bewpi_invoice_number_type'] ) {
|
241 |
// WC backwards compatibility.
|
242 |
+
$order_id = bewpi_get_id( $this->order );
|
243 |
|
244 |
return $order_id;
|
245 |
}
|
304 |
*/
|
305 |
public function save( $destination = 'F' ) {
|
306 |
// WC backwards compatibility.
|
307 |
+
$order_id = bewpi_get_id( $this->order );
|
308 |
|
309 |
if ( BEWPI_Invoice::exists( $order_id ) ) {
|
310 |
// delete postmeta and PDF.
|
397 |
*/
|
398 |
public function display_vat_number() {
|
399 |
// WC backwards compatibility.
|
400 |
+
$order_id = bewpi_get_id( $this->order );
|
401 |
|
402 |
$vat_number = get_post_meta( $order_id, '_vat_number', true );
|
403 |
if ( ! empty( $vat_number ) ) {
|
416 |
|
417 |
if ( isset( $payment_method ) && 'woocommerce_gateway_purchase_order' === $payment_method ) {
|
418 |
// WC backwards compatibility.
|
419 |
+
$order_id = bewpi_get_id( $this->order );
|
420 |
|
421 |
$po_number = get_post_meta( $order_id, '_po_number', true );
|
422 |
if ( ! empty( $po_number ) ) {
|
553 |
*/
|
554 |
public function display_zero_rated_vat() {
|
555 |
// WC backwards compatibility.
|
556 |
+
$order_id = bewpi_get_id( $this->order );
|
557 |
|
558 |
$is_vat_valid = get_post_meta( $order_id, '_vat_number_is_valid', true );
|
559 |
if ( ! $is_vat_valid ) {
|
577 |
*/
|
578 |
private function replace_placeholders( $str ) {
|
579 |
// WC backwards compatibility.
|
580 |
+
$order_id = bewpi_get_id( $this->order );
|
581 |
|
582 |
$placeholders = apply_filters( 'bewpi_placeholders', array(
|
583 |
'[payment_method]' => method_exists( 'WC_Order', 'get_payment_method_title' ) ? $this->order->get_payment_method_title() : $this->order->payment_method_title,
|
includes/be-woocommerce-pdf-invoices.php
CHANGED
@@ -276,7 +276,7 @@ if ( ! class_exists( 'BE_WooCommerce_PDF_Invoices' ) ) {
|
|
276 |
|
277 |
// check if user has ordered order.
|
278 |
$user = wp_get_current_user();
|
279 |
-
$order_id =
|
280 |
$customer_user_id = (int) get_post_meta( $order_id, '_customer_user', true );
|
281 |
if ( $user->ID !== $customer_user_id ) {
|
282 |
wp_die( 'Access denied' );
|
@@ -438,9 +438,13 @@ if ( ! class_exists( 'BE_WooCommerce_PDF_Invoices' ) ) {
|
|
438 |
* @return string
|
439 |
*/
|
440 |
function add_emailitin_as_recipient( $headers, $status, $order ) {
|
441 |
-
|
|
|
|
|
|
|
442 |
|
443 |
// make sure invoice got only send once for each order.
|
|
|
444 |
$transient_name = sprintf( 'bewpi_emailitin_processed-%1$s', $order_id );
|
445 |
if ( get_transient( $transient_name ) ) {
|
446 |
return $headers;
|
@@ -502,7 +506,7 @@ if ( ! class_exists( 'BE_WooCommerce_PDF_Invoices' ) ) {
|
|
502 |
return $attachments;
|
503 |
}
|
504 |
|
505 |
-
$order_id =
|
506 |
$invoice = new BEWPI_Invoice( $order_id );
|
507 |
if ( ! $invoice->exists( $order_id ) ) {
|
508 |
$full_path = $invoice->save();
|
@@ -565,7 +569,7 @@ if ( ! class_exists( 'BE_WooCommerce_PDF_Invoices' ) ) {
|
|
565 |
* @param WC_ORDER $order WooCommerce Order.
|
566 |
*/
|
567 |
public function add_admin_order_pdf( $order ) {
|
568 |
-
$order_id =
|
569 |
|
570 |
if ( BEWPI_Invoice::exists( $order_id ) ) {
|
571 |
$this->show_invoice_button(
|
@@ -676,7 +680,7 @@ if ( ! class_exists( 'BE_WooCommerce_PDF_Invoices' ) ) {
|
|
676 |
return;
|
677 |
}
|
678 |
|
679 |
-
$order_id =
|
680 |
if ( ! BEWPI_Invoice::exists( $order_id ) ) {
|
681 |
return;
|
682 |
}
|
@@ -714,7 +718,7 @@ if ( ! class_exists( 'BE_WooCommerce_PDF_Invoices' ) ) {
|
|
714 |
return $actions;
|
715 |
}
|
716 |
|
717 |
-
$order_id =
|
718 |
if ( ! BEWPI_Invoice::exists( $order_id ) ) {
|
719 |
return $actions;
|
720 |
}
|
@@ -728,7 +732,7 @@ if ( ! class_exists( 'BE_WooCommerce_PDF_Invoices' ) ) {
|
|
728 |
$invoice = new BEWPI_Invoice( $order_id );
|
729 |
$actions['invoice'] = array(
|
730 |
'url' => $url,
|
731 |
-
'name' => sprintf( __( 'Invoice %s
|
732 |
);
|
733 |
|
734 |
return $actions;
|
@@ -742,5 +746,14 @@ if ( ! class_exists( 'BE_WooCommerce_PDF_Invoices' ) ) {
|
|
742 |
public function templater() {
|
743 |
return BEWPI_Template::instance();
|
744 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
745 |
}
|
746 |
}
|
276 |
|
277 |
// check if user has ordered order.
|
278 |
$user = wp_get_current_user();
|
279 |
+
$order_id = bewpi_get_id( $order );
|
280 |
$customer_user_id = (int) get_post_meta( $order_id, '_customer_user', true );
|
281 |
if ( $user->ID !== $customer_user_id ) {
|
282 |
wp_die( 'Access denied' );
|
438 |
* @return string
|
439 |
*/
|
440 |
function add_emailitin_as_recipient( $headers, $status, $order ) {
|
441 |
+
// Only attach to emails with WC_Order object.
|
442 |
+
if ( ! $order instanceof WC_Order ) {
|
443 |
+
return $headers;
|
444 |
+
}
|
445 |
|
446 |
// make sure invoice got only send once for each order.
|
447 |
+
$order_id = bewpi_get_id( $order );
|
448 |
$transient_name = sprintf( 'bewpi_emailitin_processed-%1$s', $order_id );
|
449 |
if ( get_transient( $transient_name ) ) {
|
450 |
return $headers;
|
506 |
return $attachments;
|
507 |
}
|
508 |
|
509 |
+
$order_id = bewpi_get_id( $order );
|
510 |
$invoice = new BEWPI_Invoice( $order_id );
|
511 |
if ( ! $invoice->exists( $order_id ) ) {
|
512 |
$full_path = $invoice->save();
|
569 |
* @param WC_ORDER $order WooCommerce Order.
|
570 |
*/
|
571 |
public function add_admin_order_pdf( $order ) {
|
572 |
+
$order_id = bewpi_get_id( $order );
|
573 |
|
574 |
if ( BEWPI_Invoice::exists( $order_id ) ) {
|
575 |
$this->show_invoice_button(
|
680 |
return;
|
681 |
}
|
682 |
|
683 |
+
$order_id = bewpi_get_id( $order );
|
684 |
if ( ! BEWPI_Invoice::exists( $order_id ) ) {
|
685 |
return;
|
686 |
}
|
718 |
return $actions;
|
719 |
}
|
720 |
|
721 |
+
$order_id = bewpi_get_id( $order );
|
722 |
if ( ! BEWPI_Invoice::exists( $order_id ) ) {
|
723 |
return $actions;
|
724 |
}
|
732 |
$invoice = new BEWPI_Invoice( $order_id );
|
733 |
$actions['invoice'] = array(
|
734 |
'url' => $url,
|
735 |
+
'name' => apply_filters( 'bewpi_my_account_pdf_name', sprintf( __( 'Invoice %s', 'woocommerce-pdf-invoices' ), $invoice->get_formatted_number() ) ),
|
736 |
);
|
737 |
|
738 |
return $actions;
|
746 |
public function templater() {
|
747 |
return BEWPI_Template::instance();
|
748 |
}
|
749 |
+
|
750 |
+
/**
|
751 |
+
* Logger instance;
|
752 |
+
*
|
753 |
+
* @return BEWPI_Debug_Log.
|
754 |
+
*/
|
755 |
+
public function logger() {
|
756 |
+
return BEWPI_Debug_Log::instance();
|
757 |
+
}
|
758 |
}
|
759 |
}
|
includes/class-bewpi-debug-log.php
ADDED
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Simple logging class that writes to wp-content/debug.log file.
|
4 |
+
*
|
5 |
+
* @author Bas Elbers
|
6 |
+
* @category Class
|
7 |
+
* @package BE_WooCommerce_PDF_Invoices/Class
|
8 |
+
* @version 0.0.1
|
9 |
+
*/
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Class BEWPI_Debug_Log.
|
13 |
+
*/
|
14 |
+
class BEWPI_Debug_Log {
|
15 |
+
|
16 |
+
/** Main instance.
|
17 |
+
*
|
18 |
+
* @var BEWPI_Debug_Log The single instance of the class.
|
19 |
+
*/
|
20 |
+
protected static $_instance = null;
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Detailed debug information
|
24 |
+
*/
|
25 |
+
const DEBUG = 100;
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Interesting events
|
29 |
+
*
|
30 |
+
* Examples: Visitor subscribed
|
31 |
+
*/
|
32 |
+
const INFO = 200;
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Exceptional occurrences that are not errors
|
36 |
+
*
|
37 |
+
* Examples: User already subscribed
|
38 |
+
*/
|
39 |
+
const WARNING = 300;
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Runtime errors
|
43 |
+
*/
|
44 |
+
const ERROR = 400;
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Logging levels from syslog protocol defined in RFC 5424
|
48 |
+
*
|
49 |
+
* @var array $levels Logging levels
|
50 |
+
*/
|
51 |
+
protected static $levels = array(
|
52 |
+
self::DEBUG => 'DEBUG',
|
53 |
+
self::INFO => 'INFO',
|
54 |
+
self::WARNING => 'WARNING',
|
55 |
+
self::ERROR => 'ERROR',
|
56 |
+
);
|
57 |
+
|
58 |
+
/**
|
59 |
+
* Main BEWPI_Debug_Log Instance.
|
60 |
+
*
|
61 |
+
* Ensures only one instance of BEWPI_Debug_Log is loaded or can be loaded.
|
62 |
+
*
|
63 |
+
* @since 2.7.2
|
64 |
+
* @static
|
65 |
+
* @return BEWPI_Debug_Log Main instance
|
66 |
+
*/
|
67 |
+
public static function instance() {
|
68 |
+
if ( is_null( self::$_instance ) ) {
|
69 |
+
self::$_instance = new self();
|
70 |
+
}
|
71 |
+
|
72 |
+
return self::$_instance;
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Log to wp-content/debug.log file.
|
77 |
+
*
|
78 |
+
* @param string $level Log level.
|
79 |
+
* @param string $message Log message.
|
80 |
+
*
|
81 |
+
* @return bool true on success and false on failure.
|
82 |
+
*/
|
83 |
+
private function log( $level, $message ) {
|
84 |
+
$level = self::to_level( $level );
|
85 |
+
|
86 |
+
// Generate line.
|
87 |
+
$level_name = self::get_level_name( $level );
|
88 |
+
$message = sprintf( 'WooCommerce PDF Invoices %s: %s', $level_name, $message );
|
89 |
+
|
90 |
+
return error_log( $message );
|
91 |
+
}
|
92 |
+
|
93 |
+
/**
|
94 |
+
* Log warning.
|
95 |
+
*
|
96 |
+
* @param string $message Log message.
|
97 |
+
*
|
98 |
+
* @return bool true on success and false on failure.
|
99 |
+
*/
|
100 |
+
public function warning( $message ) {
|
101 |
+
return $this->log( self::WARNING, $message );
|
102 |
+
}
|
103 |
+
|
104 |
+
/**
|
105 |
+
* Log information.
|
106 |
+
*
|
107 |
+
* @param string $message Log message.
|
108 |
+
*
|
109 |
+
* @return bool true on success and false on failure.
|
110 |
+
*/
|
111 |
+
public function info( $message ) {
|
112 |
+
return $this->log( self::INFO, $message );
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
116 |
+
* Log error.
|
117 |
+
*
|
118 |
+
* @param string $message Log message.
|
119 |
+
*
|
120 |
+
* @return bool true on success and false on failure.
|
121 |
+
*/
|
122 |
+
public function error( $message ) {
|
123 |
+
return $this->log( self::ERROR, $message );
|
124 |
+
}
|
125 |
+
|
126 |
+
/**
|
127 |
+
* Log debug information.
|
128 |
+
*
|
129 |
+
* @param string $message Log message.
|
130 |
+
*
|
131 |
+
* @return bool true on success and false on failure.
|
132 |
+
*/
|
133 |
+
public function debug( $message ) {
|
134 |
+
return $this->log( self::DEBUG, $message );
|
135 |
+
}
|
136 |
+
|
137 |
+
/**
|
138 |
+
* Converts PSR-3 levels to local ones if necessary.
|
139 |
+
*
|
140 |
+
* @param string|int $level Level number or name (PSR-3).
|
141 |
+
*
|
142 |
+
* @return int
|
143 |
+
*/
|
144 |
+
public static function to_level( $level ) {
|
145 |
+
|
146 |
+
if ( is_string( $level ) ) {
|
147 |
+
|
148 |
+
$level = strtoupper( $level );
|
149 |
+
if ( defined( __CLASS__ . '::' . $level ) ) {
|
150 |
+
return constant( __CLASS__ . '::' . $level );
|
151 |
+
}
|
152 |
+
|
153 |
+
throw new InvalidArgumentException( 'Level "' . $level . '" is not defined, use one of: ' . implode( ', ', array_keys( self::$levels ) ) );
|
154 |
+
}
|
155 |
+
|
156 |
+
return $level;
|
157 |
+
}
|
158 |
+
|
159 |
+
/**
|
160 |
+
* Gets the name of the logging level.
|
161 |
+
*
|
162 |
+
* @param int $level Log level.
|
163 |
+
*
|
164 |
+
* @return string
|
165 |
+
*/
|
166 |
+
public static function get_level_name( $level ) {
|
167 |
+
|
168 |
+
if ( ! isset( self::$levels[ $level ] ) ) {
|
169 |
+
throw new InvalidArgumentException( 'Level "' . $level . '" is not defined, use one of: ' . implode( ', ', array_keys( self::$levels ) ) );
|
170 |
+
}
|
171 |
+
|
172 |
+
return self::$levels[ $level ];
|
173 |
+
}
|
174 |
+
}
|
includes/class-bewpi-template.php
CHANGED
@@ -95,7 +95,7 @@ class BEWPI_Template {
|
|
95 |
}
|
96 |
|
97 |
if ( count( $template ) === 0 ) {
|
98 |
-
|
99 |
}
|
100 |
|
101 |
return $template;
|
@@ -126,7 +126,7 @@ class BEWPI_Template {
|
|
126 |
public function get_option( $name ) {
|
127 |
$template_options = get_option( 'bewpi_template_settings' );
|
128 |
|
129 |
-
$order_id =
|
130 |
$value = apply_filters( $name, $template_options[ $name ], $name, $order_id );
|
131 |
$value = $this->replace_placeholders( $value );
|
132 |
|
@@ -189,7 +189,7 @@ class BEWPI_Template {
|
|
189 |
* @return string
|
190 |
*/
|
191 |
public function get_meta( $meta_key ) {
|
192 |
-
$order_id =
|
193 |
|
194 |
return (string) get_post_meta( $order_id, $meta_key, true );
|
195 |
}
|
95 |
}
|
96 |
|
97 |
if ( count( $template ) === 0 ) {
|
98 |
+
BEWPI()->logger()->warning( sprintf( 'PDF generation aborted. Template not found in %1$s:%2$s', __FILE__, __LINE__ ) );
|
99 |
}
|
100 |
|
101 |
return $template;
|
126 |
public function get_option( $name ) {
|
127 |
$template_options = get_option( 'bewpi_template_settings' );
|
128 |
|
129 |
+
$order_id = bewpi_get_id( $this->order );
|
130 |
$value = apply_filters( $name, $template_options[ $name ], $name, $order_id );
|
131 |
$value = $this->replace_placeholders( $value );
|
132 |
|
189 |
* @return string
|
190 |
*/
|
191 |
public function get_meta( $meta_key ) {
|
192 |
+
$order_id = bewpi_get_id( $this->order );
|
193 |
|
194 |
return (string) get_post_meta( $order_id, $meta_key, true );
|
195 |
}
|
includes/functions.php
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Backwards compatibility to get the WC_Order ID.
|
5 |
+
*
|
6 |
+
* @param WC_Order $order WooCommerce Order object.
|
7 |
+
*
|
8 |
+
* @return int/bool WC_Order ID or false on failure.
|
9 |
+
*/
|
10 |
+
function bewpi_get_id( $order ) {
|
11 |
+
$reflection = new ReflectionObject( $order );
|
12 |
+
|
13 |
+
if ( $reflection->hasMethod( 'get_id' ) ) {
|
14 |
+
return $reflection->getMethod( 'get_id' )->invoke( $order );
|
15 |
+
}
|
16 |
+
|
17 |
+
if ( $reflection->hasProperty( 'id' ) ) {
|
18 |
+
return $reflection->getProperty( 'id' )->getValue();
|
19 |
+
}
|
20 |
+
|
21 |
+
return false;
|
22 |
+
}
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link:
|
|
4 |
Tags: woocommerce pdf invoices, invoice, generate, pdf, woocommerce, attachment, email, completed order, customer invoice, processing order, attach, automatic, vat, rate, sequential, number
|
5 |
Requires at least: 4.0
|
6 |
Tested up to: 4.7
|
7 |
-
Stable tag: 2.7.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -29,8 +29,8 @@ This WooCommerce plugin generates PDF invoices, attaches it to WooCommerce email
|
|
29 |
|
30 |
> **WooCommerce PDF Invoices Premium**<br /><br />
|
31 |
> This plugin offers a premium version which comes with the following features:<br /><br />
|
32 |
-
> -
|
33 |
-
> -
|
34 |
> - Bulk generate PDF invoices<br />
|
35 |
> - Bulk export and/or download PDF invoices<br />
|
36 |
> - Periodically bill by generating and sending global invoices<br />
|
@@ -59,7 +59,8 @@ Contribute a translation on [GitHub](https://github.com/baselbers/woocommerce-pd
|
|
59 |
4. Create new invoice from the order page.
|
60 |
5. View invoice from the shop order page.
|
61 |
6. Download invoice from account.
|
62 |
-
|
|
|
63 |
|
64 |
== Installation ==
|
65 |
|
@@ -232,6 +233,11 @@ Important: A custom template is required to add a custom field to the PDF invoic
|
|
232 |
|
233 |
== Changelog ==
|
234 |
|
|
|
|
|
|
|
|
|
|
|
235 |
= 2.7.1 - April, 14, 2017 =
|
236 |
|
237 |
- Fixed: 'PHP Fatal error: Call to undefined method WC_Order::get_id()'.
|
4 |
Tags: woocommerce pdf invoices, invoice, generate, pdf, woocommerce, attachment, email, completed order, customer invoice, processing order, attach, automatic, vat, rate, sequential, number
|
5 |
Requires at least: 4.0
|
6 |
Tested up to: 4.7
|
7 |
+
Stable tag: 2.7.2
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
29 |
|
30 |
> **WooCommerce PDF Invoices Premium**<br /><br />
|
31 |
> This plugin offers a premium version which comes with the following features:<br /><br />
|
32 |
+
> - Design PDF invoices with custom fonts.<br />
|
33 |
+
> - Multilingual PDF invoices with WPML and Polylang<br />
|
34 |
> - Bulk generate PDF invoices<br />
|
35 |
> - Bulk export and/or download PDF invoices<br />
|
36 |
> - Periodically bill by generating and sending global invoices<br />
|
59 |
4. Create new invoice from the order page.
|
60 |
5. View invoice from the shop order page.
|
61 |
6. Download invoice from account.
|
62 |
+
7. Nice and clean template called 'Micro'.
|
63 |
+
8. Nice and clean template called 'Minimal'.
|
64 |
|
65 |
== Installation ==
|
66 |
|
233 |
|
234 |
== Changelog ==
|
235 |
|
236 |
+
= 2.7.2 - April, 15, 2017 =
|
237 |
+
|
238 |
+
- Added: Filter 'bewpi_my_account_pdf_name' to change the name of the PDF button on My Account page.
|
239 |
+
- Fixed: 'Fatal error: Call to a member function get_id() on null' by checking object type in method `add_emailitin_as_recipient()`.
|
240 |
+
|
241 |
= 2.7.1 - April, 14, 2017 =
|
242 |
|
243 |
- Fixed: 'PHP Fatal error: Call to undefined method WC_Order::get_id()'.
|