Version Description
- Fix: Errors for filtered formatted invoice numbers
Download this release
Release Info
Developer | pomegranate |
Plugin | WooCommerce PDF Invoices & Packing Slips |
Version | 2.3.1 |
Comparing to | |
See all releases |
Code changes from version 2.3.0 to 2.3.1
includes/documents/class-wcpdf-document-number.php
CHANGED
@@ -1,188 +1,188 @@
|
|
1 |
-
<?php
|
2 |
-
namespace WPO\WC\PDF_Invoices\Documents;
|
3 |
-
|
4 |
-
use WPO\WC\PDF_Invoices\Compatibility\WC_Core as WCX;
|
5 |
-
use WPO\WC\PDF_Invoices\Compatibility\Order as WCX_Order;
|
6 |
-
use WPO\WC\PDF_Invoices\Compatibility\Product as WCX_Product;
|
7 |
-
|
8 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
9 |
-
exit; // Exit if accessed directly
|
10 |
-
}
|
11 |
-
|
12 |
-
if ( !class_exists( '\\WPO\\WC\\PDF_Invoices\\Documents\\Document_Number' ) ) :
|
13 |
-
|
14 |
-
/**
|
15 |
-
* Document Number class
|
16 |
-
*
|
17 |
-
* @class \WPO\WC\PDF_Invoices\Documents\Document_Number
|
18 |
-
* @version 2.0
|
19 |
-
* @category Class
|
20 |
-
* @author Ewout Fernhout
|
21 |
-
*/
|
22 |
-
|
23 |
-
class Document_Number {
|
24 |
-
/**
|
25 |
-
* The raw, unformatted number
|
26 |
-
* @var int
|
27 |
-
*/
|
28 |
-
public $number;
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Document number formatted for display
|
32 |
-
* @var String
|
33 |
-
*/
|
34 |
-
public $formatted_number;
|
35 |
-
|
36 |
-
/**
|
37 |
-
* Number prefix
|
38 |
-
* @var string
|
39 |
-
*/
|
40 |
-
public $prefix;
|
41 |
-
|
42 |
-
/**
|
43 |
-
* Number suffix
|
44 |
-
* @var string
|
45 |
-
*/
|
46 |
-
public $suffix;
|
47 |
-
|
48 |
-
/**
|
49 |
-
* Document Type
|
50 |
-
* @var string
|
51 |
-
*/
|
52 |
-
public $document_type;
|
53 |
-
|
54 |
-
/**
|
55 |
-
* Order ID
|
56 |
-
* @var int
|
57 |
-
*/
|
58 |
-
public $order_id;
|
59 |
-
|
60 |
-
/**
|
61 |
-
* Zeros padding (total number of digits including leading zeros)
|
62 |
-
* @var int
|
63 |
-
*/
|
64 |
-
public $padding;
|
65 |
-
|
66 |
-
public function __construct( $number, $settings = array(), $document = null, $order = null ) {
|
67 |
-
$number = apply_filters( 'wpo_wcpdf_raw_document_number', $number, $settings, $document, $order );
|
68 |
-
if ( !is_array( $number ) && !empty( $number ) ) {
|
69 |
-
// we're creating a new number with settings as passed
|
70 |
-
$this->number = $number;
|
71 |
-
|
72 |
-
foreach ($settings as $key => $value) {
|
73 |
-
$this->{$key} = $value;
|
74 |
-
}
|
75 |
-
|
76 |
-
if ( !isset( $this->formatted_number ) ) {
|
77 |
-
$this->apply_formatting( $document, ( !empty( $document->order ) ? $document->order : $order ) );
|
78 |
-
}
|
79 |
-
|
80 |
-
} elseif ( is_array( $number ) ) {
|
81 |
-
// loaded with full number data
|
82 |
-
foreach ($number as $key => $value) {
|
83 |
-
$this->{$key} = $value;
|
84 |
-
}
|
85 |
-
}
|
86 |
-
|
87 |
-
if (!empty($document)) {
|
88 |
-
$this->document_type = $document->get_type();
|
89 |
-
}
|
90 |
-
if (!empty($order)) {
|
91 |
-
$this->order_id = WCX_Order::get_id( $order );
|
92 |
-
}
|
93 |
-
}
|
94 |
-
|
95 |
-
public function __toString() {
|
96 |
-
return $this->get_formatted();
|
97 |
-
}
|
98 |
-
|
99 |
-
public function get_formatted() {
|
100 |
-
$formatted_number = isset( $this->formatted_number ) ? $this->formatted_number : '';
|
101 |
-
$formatted_number = apply_filters( 'wpo_wcpdf_formatted_document_number', $formatted_number, $this, $this->document_type, $this->order_id );
|
102 |
-
return $formatted_number;
|
103 |
-
}
|
104 |
-
|
105 |
-
public function get_plain() {
|
106 |
-
return $this->number;
|
107 |
-
}
|
108 |
-
|
109 |
-
public function apply_formatting( $document, $order ) {
|
110 |
-
if ( empty( $document ) || empty( $order ) ) {
|
111 |
-
$this->formatted_number = $this->number;
|
112 |
-
return;
|
113 |
-
}
|
114 |
-
|
115 |
-
// load plain number
|
116 |
-
$number = $this->number;
|
117 |
-
|
118 |
-
// get dates
|
119 |
-
$order_date = WCX_Order::get_prop( $order, 'date_created' );
|
120 |
-
$document_date = $document->get_date();
|
121 |
-
// fallback to order date if no document date available
|
122 |
-
if (empty($document_date)) {
|
123 |
-
$document_date = $order_date;
|
124 |
-
}
|
125 |
-
|
126 |
-
// get format settings
|
127 |
-
$formats = array(
|
128 |
-
'prefix' => $this->prefix,
|
129 |
-
'suffix' => $this->suffix,
|
130 |
-
);
|
131 |
-
|
132 |
-
// load replacement values
|
133 |
-
$order_year = $order_date->date_i18n( 'Y' );
|
134 |
-
$order_month = $order_date->date_i18n( 'm' );
|
135 |
-
$order_day = $order_date->date_i18n( 'd' );
|
136 |
-
$document_year = $document_date->date_i18n( 'Y' );
|
137 |
-
$document_month = $document_date->date_i18n( 'm' );
|
138 |
-
$document_day = $document_date->date_i18n( 'd' );
|
139 |
-
$order_number = method_exists($order, 'get_order_number') ? $order->get_order_number() : '';
|
140 |
-
|
141 |
-
// make replacements
|
142 |
-
foreach ($formats as $key => $value) {
|
143 |
-
$value = str_replace('[order_year]', $order_year, $value);
|
144 |
-
$value = str_replace('[order_month]', $order_month, $value);
|
145 |
-
$value = str_replace('[order_day]', $order_day, $value);
|
146 |
-
$value = str_replace("[{$document->slug}_year]", $document_year, $value);
|
147 |
-
$value = str_replace("[{$document->slug}_month]", $document_month, $value);
|
148 |
-
$value = str_replace("[{$document->slug}_day]", $document_day, $value);
|
149 |
-
$value = str_replace('[order_number]', $order_number, $value);
|
150 |
-
|
151 |
-
// replace date tag in the form [invoice_date="{$date_format}"] or [order_date="{$date_format}"]
|
152 |
-
$date_types = array( 'order', $document->slug );
|
153 |
-
foreach ($date_types as $date_type) {
|
154 |
-
if ( strpos($value, "[{$date_type}_date=") !== false ) {
|
155 |
-
preg_match_all("/\[{$date_type}_date=\"(.*?)\"\]/", $value, $document_date_tags);
|
156 |
-
if (!empty($document_date_tags[1])) {
|
157 |
-
foreach ($document_date_tags[1] as $match_id => $date_format) {
|
158 |
-
if ($date_type == 'order') {
|
159 |
-
$value = str_replace($document_date_tags[0][$match_id], $order_date->date_i18n( $date_format ), $value);
|
160 |
-
} else {
|
161 |
-
$value = str_replace($document_date_tags[0][$match_id], $document_date->date_i18n( $date_format ), $value);
|
162 |
-
}
|
163 |
-
}
|
164 |
-
}
|
165 |
-
}
|
166 |
-
}
|
167 |
-
$formats[$key] = $value;
|
168 |
-
}
|
169 |
-
|
170 |
-
// Padding
|
171 |
-
if ( ctype_digit( (string)$this->padding ) ) {
|
172 |
-
$number = sprintf('%0'.$this->padding.'d', $number);
|
173 |
-
}
|
174 |
-
|
175 |
-
// Add prefix & suffix
|
176 |
-
$this->formatted_number = $formats['prefix'] . $number . $formats['suffix'] ;
|
177 |
-
// Apply filters and store
|
178 |
-
$this->formatted_number = apply_filters( 'wpo_wcpdf_format_document_number', $this->formatted_number, $this, $document, $order );
|
179 |
-
|
180 |
-
return $this->formatted_number;
|
181 |
-
}
|
182 |
-
|
183 |
-
public function to_array() {
|
184 |
-
return (array) $this;
|
185 |
-
}
|
186 |
-
}
|
187 |
-
|
188 |
-
endif; // class_exists
|
1 |
+
<?php
|
2 |
+
namespace WPO\WC\PDF_Invoices\Documents;
|
3 |
+
|
4 |
+
use WPO\WC\PDF_Invoices\Compatibility\WC_Core as WCX;
|
5 |
+
use WPO\WC\PDF_Invoices\Compatibility\Order as WCX_Order;
|
6 |
+
use WPO\WC\PDF_Invoices\Compatibility\Product as WCX_Product;
|
7 |
+
|
8 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
9 |
+
exit; // Exit if accessed directly
|
10 |
+
}
|
11 |
+
|
12 |
+
if ( !class_exists( '\\WPO\\WC\\PDF_Invoices\\Documents\\Document_Number' ) ) :
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Document Number class
|
16 |
+
*
|
17 |
+
* @class \WPO\WC\PDF_Invoices\Documents\Document_Number
|
18 |
+
* @version 2.0
|
19 |
+
* @category Class
|
20 |
+
* @author Ewout Fernhout
|
21 |
+
*/
|
22 |
+
|
23 |
+
class Document_Number {
|
24 |
+
/**
|
25 |
+
* The raw, unformatted number
|
26 |
+
* @var int
|
27 |
+
*/
|
28 |
+
public $number;
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Document number formatted for display
|
32 |
+
* @var String
|
33 |
+
*/
|
34 |
+
public $formatted_number;
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Number prefix
|
38 |
+
* @var string
|
39 |
+
*/
|
40 |
+
public $prefix;
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Number suffix
|
44 |
+
* @var string
|
45 |
+
*/
|
46 |
+
public $suffix;
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Document Type
|
50 |
+
* @var string
|
51 |
+
*/
|
52 |
+
public $document_type;
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Order ID
|
56 |
+
* @var int
|
57 |
+
*/
|
58 |
+
public $order_id;
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Zeros padding (total number of digits including leading zeros)
|
62 |
+
* @var int
|
63 |
+
*/
|
64 |
+
public $padding;
|
65 |
+
|
66 |
+
public function __construct( $number, $settings = array(), $document = null, $order = null ) {
|
67 |
+
$number = apply_filters( 'wpo_wcpdf_raw_document_number', $number, $settings, $document, $order );
|
68 |
+
if ( !is_array( $number ) && !empty( $number ) ) {
|
69 |
+
// we're creating a new number with settings as passed
|
70 |
+
$this->number = $number;
|
71 |
+
|
72 |
+
foreach ($settings as $key => $value) {
|
73 |
+
$this->{$key} = $value;
|
74 |
+
}
|
75 |
+
|
76 |
+
if ( !isset( $this->formatted_number ) ) {
|
77 |
+
$this->apply_formatting( $document, ( !empty( $document->order ) ? $document->order : $order ) );
|
78 |
+
}
|
79 |
+
|
80 |
+
} elseif ( is_array( $number ) ) {
|
81 |
+
// loaded with full number data
|
82 |
+
foreach ($number as $key => $value) {
|
83 |
+
$this->{$key} = $value;
|
84 |
+
}
|
85 |
+
}
|
86 |
+
|
87 |
+
if (!empty($document)) {
|
88 |
+
$this->document_type = $document->get_type();
|
89 |
+
}
|
90 |
+
if (!empty($order)) {
|
91 |
+
$this->order_id = WCX_Order::get_id( $order );
|
92 |
+
}
|
93 |
+
}
|
94 |
+
|
95 |
+
public function __toString() {
|
96 |
+
return (string) $this->get_formatted();
|
97 |
+
}
|
98 |
+
|
99 |
+
public function get_formatted() {
|
100 |
+
$formatted_number = isset( $this->formatted_number ) ? $this->formatted_number : '';
|
101 |
+
$formatted_number = apply_filters( 'wpo_wcpdf_formatted_document_number', $formatted_number, $this, $this->document_type, $this->order_id );
|
102 |
+
return $formatted_number;
|
103 |
+
}
|
104 |
+
|
105 |
+
public function get_plain() {
|
106 |
+
return $this->number;
|
107 |
+
}
|
108 |
+
|
109 |
+
public function apply_formatting( $document, $order ) {
|
110 |
+
if ( empty( $document ) || empty( $order ) ) {
|
111 |
+
$this->formatted_number = $this->number;
|
112 |
+
return;
|
113 |
+
}
|
114 |
+
|
115 |
+
// load plain number
|
116 |
+
$number = $this->number;
|
117 |
+
|
118 |
+
// get dates
|
119 |
+
$order_date = WCX_Order::get_prop( $order, 'date_created' );
|
120 |
+
$document_date = $document->get_date();
|
121 |
+
// fallback to order date if no document date available
|
122 |
+
if (empty($document_date)) {
|
123 |
+
$document_date = $order_date;
|
124 |
+
}
|
125 |
+
|
126 |
+
// get format settings
|
127 |
+
$formats = array(
|
128 |
+
'prefix' => $this->prefix,
|
129 |
+
'suffix' => $this->suffix,
|
130 |
+
);
|
131 |
+
|
132 |
+
// load replacement values
|
133 |
+
$order_year = $order_date->date_i18n( 'Y' );
|
134 |
+
$order_month = $order_date->date_i18n( 'm' );
|
135 |
+
$order_day = $order_date->date_i18n( 'd' );
|
136 |
+
$document_year = $document_date->date_i18n( 'Y' );
|
137 |
+
$document_month = $document_date->date_i18n( 'm' );
|
138 |
+
$document_day = $document_date->date_i18n( 'd' );
|
139 |
+
$order_number = method_exists($order, 'get_order_number') ? $order->get_order_number() : '';
|
140 |
+
|
141 |
+
// make replacements
|
142 |
+
foreach ($formats as $key => $value) {
|
143 |
+
$value = str_replace('[order_year]', $order_year, $value);
|
144 |
+
$value = str_replace('[order_month]', $order_month, $value);
|
145 |
+
$value = str_replace('[order_day]', $order_day, $value);
|
146 |
+
$value = str_replace("[{$document->slug}_year]", $document_year, $value);
|
147 |
+
$value = str_replace("[{$document->slug}_month]", $document_month, $value);
|
148 |
+
$value = str_replace("[{$document->slug}_day]", $document_day, $value);
|
149 |
+
$value = str_replace('[order_number]', $order_number, $value);
|
150 |
+
|
151 |
+
// replace date tag in the form [invoice_date="{$date_format}"] or [order_date="{$date_format}"]
|
152 |
+
$date_types = array( 'order', $document->slug );
|
153 |
+
foreach ($date_types as $date_type) {
|
154 |
+
if ( strpos($value, "[{$date_type}_date=") !== false ) {
|
155 |
+
preg_match_all("/\[{$date_type}_date=\"(.*?)\"\]/", $value, $document_date_tags);
|
156 |
+
if (!empty($document_date_tags[1])) {
|
157 |
+
foreach ($document_date_tags[1] as $match_id => $date_format) {
|
158 |
+
if ($date_type == 'order') {
|
159 |
+
$value = str_replace($document_date_tags[0][$match_id], $order_date->date_i18n( $date_format ), $value);
|
160 |
+
} else {
|
161 |
+
$value = str_replace($document_date_tags[0][$match_id], $document_date->date_i18n( $date_format ), $value);
|
162 |
+
}
|
163 |
+
}
|
164 |
+
}
|
165 |
+
}
|
166 |
+
}
|
167 |
+
$formats[$key] = $value;
|
168 |
+
}
|
169 |
+
|
170 |
+
// Padding
|
171 |
+
if ( ctype_digit( (string)$this->padding ) ) {
|
172 |
+
$number = sprintf('%0'.$this->padding.'d', $number);
|
173 |
+
}
|
174 |
+
|
175 |
+
// Add prefix & suffix
|
176 |
+
$this->formatted_number = $formats['prefix'] . $number . $formats['suffix'] ;
|
177 |
+
// Apply filters and store
|
178 |
+
$this->formatted_number = apply_filters( 'wpo_wcpdf_format_document_number', $this->formatted_number, $this, $document, $order );
|
179 |
+
|
180 |
+
return $this->formatted_number;
|
181 |
+
}
|
182 |
+
|
183 |
+
public function to_array() {
|
184 |
+
return (array) $this;
|
185 |
+
}
|
186 |
+
}
|
187 |
+
|
188 |
+
endif; // class_exists
|
readme.txt
CHANGED
@@ -5,7 +5,7 @@ Tags: woocommerce, pdf, invoices, packing slips, print, delivery notes, invoice,
|
|
5 |
Requires at least: 3.5
|
6 |
Tested up to: 5.2
|
7 |
Requires PHP: 5.3
|
8 |
-
Stable tag: 2.3.
|
9 |
License: GPLv2 or later
|
10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
|
@@ -103,6 +103,9 @@ There's a setting on the Status tab of the settings page that allows you to togg
|
|
103 |
|
104 |
== Changelog ==
|
105 |
|
|
|
|
|
|
|
106 |
= 2.3.0 =
|
107 |
* Feature: Setting to disable invoices globally for specific order statuses
|
108 |
* Feature: Control action buttons visibility from settings wizard.
|
5 |
Requires at least: 3.5
|
6 |
Tested up to: 5.2
|
7 |
Requires PHP: 5.3
|
8 |
+
Stable tag: 2.3.1
|
9 |
License: GPLv2 or later
|
10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
|
103 |
|
104 |
== Changelog ==
|
105 |
|
106 |
+
= 2.3.1 =
|
107 |
+
* Fix: Errors for filtered formatted invoice numbers
|
108 |
+
|
109 |
= 2.3.0 =
|
110 |
* Feature: Setting to disable invoices globally for specific order statuses
|
111 |
* Feature: Control action buttons visibility from settings wizard.
|
woocommerce-pdf-invoices-packingslips.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: WooCommerce PDF Invoices & Packing Slips
|
4 |
* Plugin URI: http://www.wpovernight.com
|
5 |
* Description: Create, print & email PDF invoices & packing slips for WooCommerce orders.
|
6 |
-
* Version: 2.3.
|
7 |
* Author: Ewout Fernhout
|
8 |
* Author URI: http://www.wpovernight.com
|
9 |
* License: GPLv2 or later
|
@@ -21,7 +21,7 @@ if ( !class_exists( 'WPO_WCPDF' ) ) :
|
|
21 |
|
22 |
class WPO_WCPDF {
|
23 |
|
24 |
-
public $version = '2.3.
|
25 |
public $plugin_basename;
|
26 |
public $legacy_mode;
|
27 |
|
3 |
* Plugin Name: WooCommerce PDF Invoices & Packing Slips
|
4 |
* Plugin URI: http://www.wpovernight.com
|
5 |
* Description: Create, print & email PDF invoices & packing slips for WooCommerce orders.
|
6 |
+
* Version: 2.3.1
|
7 |
* Author: Ewout Fernhout
|
8 |
* Author URI: http://www.wpovernight.com
|
9 |
* License: GPLv2 or later
|
21 |
|
22 |
class WPO_WCPDF {
|
23 |
|
24 |
+
public $version = '2.3.1';
|
25 |
public $plugin_basename;
|
26 |
public $legacy_mode;
|
27 |
|