Version Description
- Feature: Manually edit invoice number on the edit order screen
- Feature: Set the first (/next) invoice number on the settings screen
- Fix: Bug where invoice number would be generated twice due to slow database calls
- Fix: php strict warnings
Download this release
Release Info
Developer | pomegranate |
Plugin | WooCommerce PDF Invoices & Packing Slips |
Version | 1.2.3 |
Comparing to | |
See all releases |
Code changes from version 1.2.2 to 1.2.3
- includes/class-wcpdf-export.php +26 -20
- includes/class-wcpdf-settings.php +41 -4
- includes/class-wcpdf-writepanels.php +23 -1
- readme.txt +10 -4
- templates/pdf/Simple/invoice.php +26 -4
- woocommerce-pdf-invoices-packingslips.php +13 -26
includes/class-wcpdf-export.php
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
/**
|
4 |
* PDF Export class
|
5 |
*/
|
@@ -15,6 +14,7 @@ if ( ! class_exists( 'WooCommerce_PDF_Invoices_Export' ) ) {
|
|
15 |
|
16 |
public $order;
|
17 |
public $template_type;
|
|
|
18 |
public $order_id;
|
19 |
public $output_body;
|
20 |
|
@@ -259,33 +259,39 @@ if ( ! class_exists( 'WooCommerce_PDF_Invoices_Export' ) ) {
|
|
259 |
}
|
260 |
|
261 |
public function get_invoice_number( $order_id ) {
|
262 |
-
//
|
263 |
-
global $wpdb;
|
264 |
-
|
265 |
$invoice_number = get_post_meta( $order_id, '_wcpdf_invoice_number', true );
|
266 |
|
|
|
|
|
|
|
|
|
|
|
267 |
// add invoice number if it doesn't exist
|
268 |
if ( empty($invoice_number) || !isset($invoice_number) ) {
|
269 |
-
|
270 |
-
// this seems to me like the safest way to avoid order number clashes
|
271 |
-
$success = false;
|
272 |
-
for ( $i = 0; $i < 3 && ! $success; $i++ ) {
|
273 |
-
// Get maximum invoice number in the DB
|
274 |
-
$max_invoice_number = $wpdb->get_var( 'SELECT max(cast(meta_value as UNSIGNED)) from ' . $wpdb->postmeta . ' where meta_key="_wcpdf_invoice_number"' );
|
275 |
-
|
276 |
-
if ($max_invoice_number == '') {
|
277 |
-
// First time! Use order number as starting point.
|
278 |
-
$order_number = ltrim($this->order->get_order_number(), '#');
|
279 |
-
$invoice_number = $order_number;
|
280 |
-
} else {
|
281 |
-
$invoice_number = $max_invoice_number+1;
|
282 |
-
}
|
283 |
|
284 |
-
|
|
|
|
|
|
|
|
|
|
|
285 |
}
|
286 |
-
|
|
|
|
|
287 |
}
|
288 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
289 |
return $invoice_number;
|
290 |
}
|
291 |
|
1 |
<?php
|
|
|
2 |
/**
|
3 |
* PDF Export class
|
4 |
*/
|
14 |
|
15 |
public $order;
|
16 |
public $template_type;
|
17 |
+
public $invoice_number;
|
18 |
public $order_id;
|
19 |
public $output_body;
|
20 |
|
259 |
}
|
260 |
|
261 |
public function get_invoice_number( $order_id ) {
|
262 |
+
// get invoice number from post meta
|
|
|
|
|
263 |
$invoice_number = get_post_meta( $order_id, '_wcpdf_invoice_number', true );
|
264 |
|
265 |
+
// double check with local variable
|
266 |
+
if (!empty($this->invoice_number) ) {
|
267 |
+
$invoice_number = $this->invoice_number;
|
268 |
+
}
|
269 |
+
|
270 |
// add invoice number if it doesn't exist
|
271 |
if ( empty($invoice_number) || !isset($invoice_number) ) {
|
272 |
+
$next_invoice_number = $this->template_settings['next_invoice_number'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
273 |
|
274 |
+
if ( empty($next_invoice_number) ) {
|
275 |
+
// First time! Use order number as starting point.
|
276 |
+
$order_number = ltrim($this->order->get_order_number(), '#');
|
277 |
+
$invoice_number = $order_number;
|
278 |
+
} else {
|
279 |
+
$invoice_number = $next_invoice_number;
|
280 |
}
|
281 |
+
|
282 |
+
// set invoice number in object to double check (slow databases)
|
283 |
+
$this->invoice_number = $invoice_number;
|
284 |
}
|
285 |
|
286 |
+
update_post_meta($order_id, '_wcpdf_invoice_number', $invoice_number);
|
287 |
+
|
288 |
+
// increase next_order_number
|
289 |
+
$template_settings = get_option('wpo_wcpdf_template_settings');
|
290 |
+
$template_settings['next_invoice_number'] = $invoice_number+1;
|
291 |
+
update_option( 'wpo_wcpdf_template_settings', $template_settings );
|
292 |
+
|
293 |
+
// die($invoice_number);
|
294 |
+
|
295 |
return $invoice_number;
|
296 |
}
|
297 |
|
includes/class-wcpdf-settings.php
CHANGED
@@ -7,9 +7,9 @@ if ( ! class_exists( 'WooCommerce_PDF_Invoices_Settings' ) ) {
|
|
7 |
|
8 |
class WooCommerce_PDF_Invoices_Settings {
|
9 |
|
10 |
-
public
|
11 |
-
public
|
12 |
-
public
|
13 |
|
14 |
public function __construct() {
|
15 |
add_action( 'admin_menu', array( &$this, 'menu' ) ); // Add menu.
|
@@ -333,6 +333,21 @@ if ( ! class_exists( 'WooCommerce_PDF_Invoices_Settings' ) ) {
|
|
333 |
)
|
334 |
);
|
335 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
336 |
add_settings_field(
|
337 |
'display_date',
|
338 |
__( 'Date to display on invoice', 'wpo_wcpdf' ),
|
@@ -407,8 +422,30 @@ if ( ! class_exists( 'WooCommerce_PDF_Invoices_Settings' ) ) {
|
|
407 |
|
408 |
// Register defaults if settings empty (might not work in case there's only checkboxes and they're all disabled)
|
409 |
$option_values = get_option($option);
|
410 |
-
if ( empty( $option_values ) )
|
411 |
$this->default_settings();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
412 |
}
|
413 |
|
414 |
/**
|
7 |
|
8 |
class WooCommerce_PDF_Invoices_Settings {
|
9 |
|
10 |
+
public $options_page_hook;
|
11 |
+
public $general_settings;
|
12 |
+
public $template_settings;
|
13 |
|
14 |
public function __construct() {
|
15 |
add_action( 'admin_menu', array( &$this, 'menu' ) ); // Add menu.
|
333 |
)
|
334 |
);
|
335 |
|
336 |
+
add_settings_field(
|
337 |
+
'next_invoice_number',
|
338 |
+
__( 'Next invoice number (without prefix/suffix etc.)', 'wpo_wcpdf' ),
|
339 |
+
array( &$this, 'text_element_callback' ),
|
340 |
+
$option,
|
341 |
+
'template_settings',
|
342 |
+
array(
|
343 |
+
'menu' => $option,
|
344 |
+
'id' => 'next_invoice_number',
|
345 |
+
'size' => '10',
|
346 |
+
'description' => __( 'This is the number that will be used on the next invoice that is created. By default, numbering starts from the WooCommerce Order Number of the first invoice that is created and increases for every new invoice. Note that if you override this and set it lower than the highest (PDF) invoice number, this could create double invoice numbers!<br/>Check the <a href="http://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/faq/" target="_blank">FAQ</a> for instructions on how to format the invoice number.', 'wpo_wcpdf' ),
|
347 |
+
)
|
348 |
+
);
|
349 |
+
|
350 |
+
|
351 |
add_settings_field(
|
352 |
'display_date',
|
353 |
__( 'Date to display on invoice', 'wpo_wcpdf' ),
|
422 |
|
423 |
// Register defaults if settings empty (might not work in case there's only checkboxes and they're all disabled)
|
424 |
$option_values = get_option($option);
|
425 |
+
if ( empty( $option_values ) ) {
|
426 |
$this->default_settings();
|
427 |
+
}
|
428 |
+
|
429 |
+
// determine highest invoice number if option not set
|
430 |
+
if ( !isset($option_values['next_invoice_number']) ) {
|
431 |
+
// Based on code from WooCommerce Sequential Order Numbers
|
432 |
+
global $wpdb;
|
433 |
+
// get highest invoice_number in postmeta table
|
434 |
+
$max_invoice_number = $wpdb->get_var( 'SELECT max(cast(meta_value as UNSIGNED)) from ' . $wpdb->postmeta . ' where meta_key="_wcpdf_invoice_number"' );
|
435 |
+
// get highest order_number in postmeta table
|
436 |
+
// $max_order_number = $wpdb->get_var( 'SELECT max(cast(meta_value as UNSIGNED)) from ' . $wpdb->postmeta . ' where meta_key="_order_number"' );
|
437 |
+
// get highest post_id with type shop_order in post table
|
438 |
+
// $max_order_id = $wpdb->get_var( 'SELECT max(cast(ID as UNSIGNED)) from ' . $wpdb->posts . ' where post_type="shop_order"' );
|
439 |
+
|
440 |
+
$next_invoice_number = '';
|
441 |
+
|
442 |
+
if ( isset($max_invoice_number) && !empty($max_invoice_number) ) {
|
443 |
+
$next_invoice_number = $max_invoice_number+1;
|
444 |
+
}
|
445 |
+
|
446 |
+
$option_values['next_invoice_number'] = $next_invoice_number;
|
447 |
+
update_option( $option, $option_values );
|
448 |
+
}
|
449 |
}
|
450 |
|
451 |
/**
|
includes/class-wcpdf-writepanels.php
CHANGED
@@ -17,6 +17,10 @@ if ( !class_exists( 'WooCommerce_PDF_Invoices_Writepanels' ) ) {
|
|
17 |
add_action( 'admin_print_scripts', array( $this, 'add_scripts' ) );
|
18 |
add_action( 'admin_print_styles', array( $this, 'add_styles' ) );
|
19 |
add_action( 'admin_footer-edit.php', array(&$this, 'bulk_actions') );
|
|
|
|
|
|
|
|
|
20 |
$this->general_settings = get_option('wpo_wcpdf_general_settings');
|
21 |
$this->template_settings = get_option('wpo_wcpdf_template_settings');
|
22 |
}
|
@@ -113,6 +117,7 @@ if ( !class_exists( 'WooCommerce_PDF_Invoices_Writepanels' ) ) {
|
|
113 |
</ul>
|
114 |
<?php
|
115 |
}
|
|
|
116 |
/**
|
117 |
* Add actions to menu
|
118 |
*/
|
@@ -131,6 +136,23 @@ if ( !class_exists( 'WooCommerce_PDF_Invoices_Writepanels' ) ) {
|
|
131 |
</script>
|
132 |
<?php
|
133 |
}
|
134 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
}
|
136 |
}
|
17 |
add_action( 'admin_print_scripts', array( $this, 'add_scripts' ) );
|
18 |
add_action( 'admin_print_styles', array( $this, 'add_styles' ) );
|
19 |
add_action( 'admin_footer-edit.php', array(&$this, 'bulk_actions') );
|
20 |
+
|
21 |
+
add_action( 'woocommerce_admin_order_data_after_order_details', array(&$this, 'edit_invoice_number') );
|
22 |
+
add_action( 'save_post', array( &$this,'save_invoice_number' ) );
|
23 |
+
|
24 |
$this->general_settings = get_option('wpo_wcpdf_general_settings');
|
25 |
$this->template_settings = get_option('wpo_wcpdf_template_settings');
|
26 |
}
|
117 |
</ul>
|
118 |
<?php
|
119 |
}
|
120 |
+
|
121 |
/**
|
122 |
* Add actions to menu
|
123 |
*/
|
136 |
</script>
|
137 |
<?php
|
138 |
}
|
139 |
+
}
|
140 |
+
|
141 |
+
/**
|
142 |
+
* Add actions to menu
|
143 |
+
*/
|
144 |
+
public function edit_invoice_number($order) {
|
145 |
+
woocommerce_wp_text_input( array( 'id' => '_wcpdf_invoice_number', 'label' => __( 'PDF Invoice Number', 'wpo_wcpdf' ) ) );
|
146 |
+
}
|
147 |
+
|
148 |
+
/**
|
149 |
+
* Save invoice number
|
150 |
+
*/
|
151 |
+
public function save_invoice_number($post_id) {
|
152 |
+
global $post_type;
|
153 |
+
if( $post_type == 'shop_order' ) {
|
154 |
+
update_post_meta( $post_id, '_wcpdf_invoice_number', stripslashes( $_POST['_wcpdf_invoice_number'] ));
|
155 |
+
}
|
156 |
+
}
|
157 |
}
|
158 |
}
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: pomegranate
|
|
3 |
Tags: woocommerce, print, pdf, bulk, packing slips, invoices, delivery notes, invoice, packing slip, export, email
|
4 |
Requires at least: 3.5 and WooCommerce 2.0
|
5 |
Tested up to: 3.8 and WooCommerce 2.1
|
6 |
-
Stable tag: 1.2.
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
@@ -76,12 +76,12 @@ You can do this via a filter in your theme's `functions.php` (Some themes have a
|
|
76 |
|
77 |
`
|
78 |
add_filter( 'wpo_wcpdf_invoice_number', 'wpo_wcpdf_invoice_number', 10, 4 );
|
79 |
-
|
80 |
function wpo_wcpdf_invoice_number( $invoice_number, $order_number, $order_id, $order_date ) {
|
81 |
$prefix = 'ABC';
|
82 |
$order_year = date_i18n( 'Y', strtotime( $order_date ) );
|
83 |
-
$
|
84 |
-
$
|
|
|
85 |
return $invoice_number;
|
86 |
}
|
87 |
`
|
@@ -99,6 +99,12 @@ This usually only happens on batch actions. PDF creation is a memory intensive j
|
|
99 |
|
100 |
== Changelog ==
|
101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
= 1.2.2 =
|
103 |
* PDF engine updated (dompdf 0.6.0)
|
104 |
* Simple template now uses Open Sans to include more international special characters
|
3 |
Tags: woocommerce, print, pdf, bulk, packing slips, invoices, delivery notes, invoice, packing slip, export, email
|
4 |
Requires at least: 3.5 and WooCommerce 2.0
|
5 |
Tested up to: 3.8 and WooCommerce 2.1
|
6 |
+
Stable tag: 1.2.3
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
76 |
|
77 |
`
|
78 |
add_filter( 'wpo_wcpdf_invoice_number', 'wpo_wcpdf_invoice_number', 10, 4 );
|
|
|
79 |
function wpo_wcpdf_invoice_number( $invoice_number, $order_number, $order_id, $order_date ) {
|
80 |
$prefix = 'ABC';
|
81 |
$order_year = date_i18n( 'Y', strtotime( $order_date ) );
|
82 |
+
$padding = 6; // number of digits - so 42 becomes 000042
|
83 |
+
$suffix = 'X';
|
84 |
+
$invoice_number = $prefix . $order_year . sprintf('%0'.$padding.'d', $invoice_number) . $suffix ;
|
85 |
return $invoice_number;
|
86 |
}
|
87 |
`
|
99 |
|
100 |
== Changelog ==
|
101 |
|
102 |
+
= 1.2.3 =
|
103 |
+
* Feature: Manually edit invoice number on the edit order screen
|
104 |
+
* Feature: Set the first (/next) invoice number on the settings screen
|
105 |
+
* Fix: Bug where invoice number would be generated twice due to slow database calls
|
106 |
+
* Fix: php strict warnings
|
107 |
+
|
108 |
= 1.2.2 =
|
109 |
* PDF engine updated (dompdf 0.6.0)
|
110 |
* Simple template now uses Open Sans to include more international special characters
|
templates/pdf/Simple/invoice.php
CHANGED
@@ -27,10 +27,32 @@
|
|
27 |
<tr>
|
28 |
<td>
|
29 |
<div class="order-information">
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
<span class="order-payment-label"><?php _e( 'Payment Method:', 'wpo_wcpdf' ); ?></span>
|
35 |
<span class="order-payment"><?php $wpo_wcpdf->payment_method(); ?></span><br />
|
36 |
</div>
|
27 |
<tr>
|
28 |
<td>
|
29 |
<div class="order-information">
|
30 |
+
<?php
|
31 |
+
$date_setting = isset($wpo_wcpdf->settings->template_settings['display_date'])?$wpo_wcpdf->settings->template_settings['display_date']:'order_date';
|
32 |
+
$number_setting = isset($wpo_wcpdf->settings->template_settings['display_number'])?$wpo_wcpdf->settings->template_settings['display_number']:'order_number';
|
33 |
+
|
34 |
+
// set $display date & label to user setting
|
35 |
+
if ( $date_setting == 'invoice_date' ) {
|
36 |
+
$display_date = $wpo_wcpdf->get_invoice_date();
|
37 |
+
$display_date_label = __( 'Invoice Date:', 'wpo_wcpdf' );
|
38 |
+
} else {
|
39 |
+
$display_date = $wpo_wcpdf->get_order_date();
|
40 |
+
$display_date_label = __( 'Order Date:', 'wpo_wcpdf' );
|
41 |
+
}
|
42 |
+
|
43 |
+
// set $display number & label to user setting
|
44 |
+
if ( $number_setting == 'invoice_number' ) {
|
45 |
+
$display_number = $wpo_wcpdf->get_invoice_number();
|
46 |
+
$display_number_label = __( 'Invoice Number:', 'wpo_wcpdf' );
|
47 |
+
} else {
|
48 |
+
$display_number = $wpo_wcpdf->get_order_number();
|
49 |
+
$display_number_label = __( 'Order Number:', 'wpo_wcpdf' );
|
50 |
+
}
|
51 |
+
?>
|
52 |
+
<span class="order-date-label"><?php echo $display_date_label; ?></span>
|
53 |
+
<span class="order-date"><?php echo $display_date; ?></span><br />
|
54 |
+
<span class="order-number-label"><?php echo $display_number_label; ?></span>
|
55 |
+
<span class="order-number"><?php echo $display_number; ?></span><br />
|
56 |
<span class="order-payment-label"><?php _e( 'Payment Method:', 'wpo_wcpdf' ); ?></span>
|
57 |
<span class="order-payment"><?php $wpo_wcpdf->payment_method(); ?></span><br />
|
58 |
</div>
|
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: 1.2.
|
7 |
* Author: Ewout Fernhout
|
8 |
* Author URI: http://www.wpovernight.com
|
9 |
* License: GPLv2 or later
|
@@ -273,31 +273,7 @@ if ( !class_exists( 'WooCommerce_PDF_Invoices' ) ) {
|
|
273 |
return apply_filters( 'wpo_wcpdf_order_number', $order_number);
|
274 |
}
|
275 |
public function order_number() {
|
276 |
-
|
277 |
-
$display_number = isset($this->settings->template_settings['display_number'])?$this->settings->template_settings['display_number']:'order_number';
|
278 |
-
if ( $display_number == 'invoice_number' ) {
|
279 |
-
echo $this->get_invoice_number();
|
280 |
-
} else {
|
281 |
-
echo $this->get_order_number();
|
282 |
-
}
|
283 |
-
}
|
284 |
-
|
285 |
-
/**
|
286 |
-
* Return/Show the order date
|
287 |
-
*/
|
288 |
-
public function get_order_date() {
|
289 |
-
$date = date_i18n( get_option( 'date_format' ), strtotime( $this->export->order->order_date ) );
|
290 |
-
return apply_filters( 'wpo_wcpdf_order_date', $date );
|
291 |
-
}
|
292 |
-
public function order_date() {
|
293 |
-
// Check for setting: not very semantical but helps a lot for backwards compatibiity!
|
294 |
-
$display_date = isset($this->settings->template_settings['display_date'])?$this->settings->template_settings['display_date']:'order_date';
|
295 |
-
|
296 |
-
if ( $display_date == 'order_date' ) {
|
297 |
-
echo $this->get_order_date();
|
298 |
-
} else {
|
299 |
-
echo $this->get_invoice_date();
|
300 |
-
}
|
301 |
}
|
302 |
|
303 |
/**
|
@@ -311,6 +287,17 @@ if ( !class_exists( 'WooCommerce_PDF_Invoices' ) ) {
|
|
311 |
echo $this->get_invoice_number();
|
312 |
}
|
313 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
314 |
/**
|
315 |
* Return/Show the invoice date
|
316 |
*/
|
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: 1.2.3
|
7 |
* Author: Ewout Fernhout
|
8 |
* Author URI: http://www.wpovernight.com
|
9 |
* License: GPLv2 or later
|
273 |
return apply_filters( 'wpo_wcpdf_order_number', $order_number);
|
274 |
}
|
275 |
public function order_number() {
|
276 |
+
echo $this->get_order_number();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
277 |
}
|
278 |
|
279 |
/**
|
287 |
echo $this->get_invoice_number();
|
288 |
}
|
289 |
|
290 |
+
/**
|
291 |
+
* Return/Show the order date
|
292 |
+
*/
|
293 |
+
public function get_order_date() {
|
294 |
+
$date = date_i18n( get_option( 'date_format' ), strtotime( $this->export->order->order_date ) );
|
295 |
+
return apply_filters( 'wpo_wcpdf_order_date', $date );
|
296 |
+
}
|
297 |
+
public function order_date() {
|
298 |
+
echo $this->get_order_date();
|
299 |
+
}
|
300 |
+
|
301 |
/**
|
302 |
* Return/Show the invoice date
|
303 |
*/
|