WooCommerce PDF Invoices & Packing Slips - Version 2.1.7

Version Description

  • Feature: add [order_number] placeholder for number format
  • Feature: $order and $order_id variables now available directly template (without needing the document object)
  • Feature: add actions before & after addresses
  • Fix: Sorting orders by invoice number
  • Fix: Aelia Currency Switcher - use decimal & Thousand separator settings
  • Fix: fix jquery migrate warnings for media upload script
  • Tweak: add calculated tax rate to item data
Download this release

Release Info

Developer pomegranate
Plugin Icon 128x128 WooCommerce PDF Invoices & Packing Slips
Version 2.1.7
Comparing to
See all releases

Code changes from version 2.1.6 to 2.1.7

assets/js/media-upload.js CHANGED
@@ -5,13 +5,11 @@ jQuery(document).ready(function($) {
5
 
6
  // Uploading files
7
  var file_frame;
8
-
9
- $('.wpo_upload_image_button').live('click', function( event ){
10
-
11
- // get input field id from data-input_id
12
- input_id = '#'+$( this ).data( 'input_id' );
13
- input_id_class = '.'+$( this ).data( 'input_id' );
14
- input_id_clean = $( this ).data( 'input_id' );
15
 
16
  // get remove button text
17
  remove_button_text = $( this ).data( 'remove_button_text' );
@@ -40,16 +38,15 @@ jQuery(document).ready(function($) {
40
  attachment = file_frame.state().get('selection').first().toJSON();
41
 
42
  // set the value of the input field to the attachment id
43
- $( input_id ).val(attachment.id);
44
 
45
- if ($( '#img-'+input_id_clean ).length){
46
- $( '#img-'+input_id_clean ).attr("src", attachment.url );
47
- } else {
48
  // show image & remove button
49
- attachment_img = '<img src="'+attachment.url+'" style="display:block" id="img-'+input_id_clean+'"/>';
50
- remove_button = '<span class="button wpo_remove_image_button" data-input_id="'+input_id_clean+'">'+remove_button_text+'</span>';
51
- $( input_id ).before(attachment_img+remove_button);
52
-
 
53
  }
54
  });
55
 
@@ -57,15 +54,14 @@ jQuery(document).ready(function($) {
57
  file_frame.open();
58
  });
59
 
60
- $('.wpo_remove_image_button').live('click', function( event ){
61
-
62
-
63
- // get input field from data-input_id
64
- input_id = '#'+$( this ).data( 'input_id' );
65
- img_id = '#img-'+$( this ).data( 'input_id' );
66
 
67
- $( input_id ).val('');
68
- $( img_id ).remove();
69
  $( this ).remove();
70
  $( '.attachment-resolution' ).remove();
71
  });
5
 
6
  // Uploading files
7
  var file_frame;
8
+ $('#wpo-wcpdf-settings').on('click', '.wpo_upload_image_button', function( event ){
9
+ // get corresponding input fields
10
+ $row = $(this).parent();
11
+ $id = $row.find('input#header_logo');
12
+ $logo = $row.find('img#img-header_logo');
 
 
13
 
14
  // get remove button text
15
  remove_button_text = $( this ).data( 'remove_button_text' );
38
  attachment = file_frame.state().get('selection').first().toJSON();
39
 
40
  // set the value of the input field to the attachment id
41
+ $id.val(attachment.id);
42
 
43
+ if ( $logo.length == 0 ) {
 
 
44
  // show image & remove button
45
+ attachment_img = '<img src="'+attachment.url+'" style="display:block" id="img-header_logo"/>';
46
+ remove_button = '<span class="button wpo_remove_image_button" data-input_id="header_logo">'+remove_button_text+'</span>';
47
+ $id.before(attachment_img+remove_button);
48
+ } else {
49
+ $logo.attr("src", attachment.url );
50
  }
51
  });
52
 
54
  file_frame.open();
55
  });
56
 
57
+ $('#wpo-wcpdf-settings').on('click', '.wpo_remove_image_button', function( event ){
58
+ // get corresponding input fields
59
+ $row = $(this).parent();
60
+ $id = $row.find('input#header_logo');
61
+ $logo = $row.find('img#img-header_logo');
 
62
 
63
+ $id.val('');
64
+ $logo.remove();
65
  $( this ).remove();
66
  $( '.attachment-resolution' ).remove();
67
  });
includes/class-wcpdf-admin.php CHANGED
@@ -32,7 +32,11 @@ class Admin {
32
  // add_action( 'wpo_wcpdf_after_pdf', array( $this,'update_pdf_counter' ), 10, 2 );
33
 
34
  add_filter( 'manage_edit-shop_order_sortable_columns', array( $this, 'invoice_number_column_sortable' ) );
35
- add_filter( 'pre_get_posts', array( $this, 'sort_by_invoice_number' ) );
 
 
 
 
36
  }
37
 
38
  // display review admin notice after 100 pdf downloads
@@ -472,14 +476,39 @@ class Admin {
472
  return $columns;
473
  }
474
 
475
- public function sort_by_invoice_number( $query ) {
476
- if( ! is_admin() )
 
 
 
 
477
  return;
 
478
  $orderby = $query->get( 'orderby');
479
  if( 'pdf_invoice_number' == $orderby ) {
480
  $query->set('meta_key','_wcpdf_invoice_number');
481
- $query->set('orderby','meta_value_num');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
482
  }
 
 
483
  }
484
 
485
  }
32
  // add_action( 'wpo_wcpdf_after_pdf', array( $this,'update_pdf_counter' ), 10, 2 );
33
 
34
  add_filter( 'manage_edit-shop_order_sortable_columns', array( $this, 'invoice_number_column_sortable' ) );
35
+ if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '3.0', '>=' ) ) {
36
+ add_filter( 'request', array( $this, 'request_query_sort_by_invoice_number' ) );
37
+ } else {
38
+ add_filter( 'pre_get_posts', array( $this, 'pre_get_posts_sort_by_invoice_number' ) );
39
+ }
40
  }
41
 
42
  // display review admin notice after 100 pdf downloads
476
  return $columns;
477
  }
478
 
479
+
480
+ /**
481
+ * Pre WC3.X sorting
482
+ */
483
+ public function pre_get_posts_sort_by_invoice_number( $query ) {
484
+ if( ! is_admin() ) {
485
  return;
486
+ }
487
  $orderby = $query->get( 'orderby');
488
  if( 'pdf_invoice_number' == $orderby ) {
489
  $query->set('meta_key','_wcpdf_invoice_number');
490
+ $query->set('orderby','meta_value');
491
+ }
492
+ }
493
+
494
+ /**
495
+ * WC3.X+ sorting
496
+ */
497
+ public function request_query_sort_by_invoice_number( $query_vars ) {
498
+ global $typenow;
499
+
500
+ if ( in_array( $typenow, wc_get_order_types( 'order-meta-boxes' ), true ) ) {
501
+ if ( isset( $query_vars['orderby'] ) ) {
502
+ if ( 'pdf_invoice_number' === $query_vars['orderby'] ) {
503
+ $query_vars = array_merge( $query_vars, array(
504
+ 'meta_key' => '_wcpdf_invoice_number',
505
+ 'orderby' => 'meta_value',
506
+ ) );
507
+ }
508
+ }
509
  }
510
+
511
+ return $query_vars;
512
  }
513
 
514
  }
includes/class-wcpdf-settings-callbacks.php CHANGED
@@ -369,7 +369,11 @@ class Settings_Callbacks {
369
  if (!empty($args['i18n_description'])) {
370
  $args['description'] = $args['i18n_description'];
371
  }
372
- call_user_func( array( $this, $callback ), $args );
 
 
 
 
373
  echo '</div>';
374
  }
375
  ?>
@@ -378,7 +382,11 @@ class Settings_Callbacks {
378
  <?php
379
  } else {
380
  $args['lang'] = 'default';
381
- call_user_func( array( $this, $callback ), $args );
 
 
 
 
382
  }
383
  }
384
 
369
  if (!empty($args['i18n_description'])) {
370
  $args['description'] = $args['i18n_description'];
371
  }
372
+ if ( is_array( $callback ) ) {
373
+ call_user_func( $callback, $args );
374
+ } else {
375
+ call_user_func( array( $this, $callback ), $args );
376
+ }
377
  echo '</div>';
378
  }
379
  ?>
382
  <?php
383
  } else {
384
  $args['lang'] = 'default';
385
+ if ( is_array( $callback ) ) {
386
+ call_user_func( $callback, $args );
387
+ } else {
388
+ call_user_func( array( $this, $callback ), $args );
389
+ }
390
  }
391
  }
392
 
includes/compatibility/class-wcpdf-compatibility-third-party-plugins.php CHANGED
@@ -46,6 +46,13 @@ class Third_Party_Plugins {
46
  add_filter( 'wpo_wcpdf_wc_emails', array( $this, 'wc_order_status_actions_emails' ), 10, 1 );
47
  }
48
 
 
 
 
 
 
 
 
49
  }
50
 
51
  /**
@@ -190,6 +197,23 @@ class Third_Party_Plugins {
190
  return $emails;
191
  }
192
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
  }
194
 
195
 
46
  add_filter( 'wpo_wcpdf_wc_emails', array( $this, 'wc_order_status_actions_emails' ), 10, 1 );
47
  }
48
 
49
+ // Aelia Currency Switcher compatibility
50
+ $currency_switcher_active = !empty($GLOBALS['woocommerce-aelia-currencyswitcher']);
51
+ if ( $currency_switcher_active ) {
52
+ add_action( 'wpo_wcpdf_before_html', array( $this, 'aelia_currency_formatting' ), 10, 2 );
53
+ }
54
+
55
+
56
  }
57
 
58
  /**
197
  return $emails;
198
  }
199
 
200
+
201
+ /**
202
+ * Aelia Currency Switcher compatibility
203
+ * Applies decimal & Thousand separator settings
204
+ */
205
+ function aelia_currency_formatting( $document_type, $document ) {
206
+ add_filter( 'wc_price_args', array( $this, 'aelia_currency_price_args' ), 10, 1 );
207
+ }
208
+
209
+ function aelia_currency_price_args( $args ) {
210
+ if ( !empty( $args['currency'] && class_exists("\\Aelia\\WC\\CurrencySwitcher\\WC_Aelia_CurrencySwitcher") ) ) {
211
+ $cs_settings = \Aelia\WC\CurrencySwitcher\WC_Aelia_CurrencySwitcher::settings();
212
+ $args['decimal_separator'] = $cs_settings->get_currency_decimal_separator( $args['currency'] );
213
+ $args['thousand_separator'] = $cs_settings->get_currency_thousand_separator( $args['currency'] );
214
+ }
215
+ return $args;
216
+ }
217
  }
218
 
219
 
includes/documents/abstract-wcpdf-order-document-methods.php CHANGED
@@ -488,7 +488,8 @@ abstract class Order_Document_Methods extends Order_Document {
488
  $data['single_line_tax'] = $this->format_price( $item['line_tax'] / max( 1, abs( $item['qty'] ) ) );
489
 
490
  $line_tax_data = maybe_unserialize( isset( $item['line_tax_data'] ) ? $item['line_tax_data'] : '' );
491
- $data['tax_rates'] = $this->get_tax_rate( $item['tax_class'], $item['line_total'], $item['line_tax'], $line_tax_data );
 
492
 
493
  // Set the line subtotal (=before discount)
494
  $data['line_subtotal'] = $this->format_price( $item['line_subtotal'] );
@@ -555,7 +556,7 @@ abstract class Order_Document_Methods extends Order_Document {
555
  * @param string $tax_class tax class slug
556
  * @return string $tax_rates imploded list of tax rates
557
  */
558
- public function get_tax_rate( $tax_class, $line_total, $line_tax, $line_tax_data = '' ) {
559
  // first try the easy wc2.2+ way, using line_tax_data
560
  if ( !empty( $line_tax_data ) && isset($line_tax_data['total']) ) {
561
  $tax_rates = array();
@@ -564,7 +565,7 @@ abstract class Order_Document_Methods extends Order_Document {
564
  foreach ( $line_taxes as $tax_id => $tax ) {
565
  if ( isset($tax) && $tax !== '' ) {
566
  $tax_rate = $this->get_tax_rate_by_id( $tax_id );
567
- if ( $tax_rate !== false ) {
568
  $tax_rates[] = $tax_rate . ' %';
569
  } else {
570
  $tax_rates[] = $this->calculate_tax_rate( $line_total, $line_tax );
488
  $data['single_line_tax'] = $this->format_price( $item['line_tax'] / max( 1, abs( $item['qty'] ) ) );
489
 
490
  $line_tax_data = maybe_unserialize( isset( $item['line_tax_data'] ) ? $item['line_tax_data'] : '' );
491
+ $data['tax_rates'] = $this->get_tax_rate( $item['tax_class'], $item['line_total'], $item['line_tax'], $line_tax_data, true );
492
+ $data['calculated_tax_rates'] = $this->get_tax_rate( $item['tax_class'], $item['line_total'], $item['line_tax'], $line_tax_data, false );
493
 
494
  // Set the line subtotal (=before discount)
495
  $data['line_subtotal'] = $this->format_price( $item['line_subtotal'] );
556
  * @param string $tax_class tax class slug
557
  * @return string $tax_rates imploded list of tax rates
558
  */
559
+ public function get_tax_rate( $tax_class, $line_total, $line_tax, $line_tax_data = '', $force_calculation = false ) {
560
  // first try the easy wc2.2+ way, using line_tax_data
561
  if ( !empty( $line_tax_data ) && isset($line_tax_data['total']) ) {
562
  $tax_rates = array();
565
  foreach ( $line_taxes as $tax_id => $tax ) {
566
  if ( isset($tax) && $tax !== '' ) {
567
  $tax_rate = $this->get_tax_rate_by_id( $tax_id );
568
+ if ( $tax_rate !== false && $force_calculation !== false ) {
569
  $tax_rates[] = $tax_rate . ' %';
570
  } else {
571
  $tax_rates[] = $this->calculate_tax_rate( $line_total, $line_tax );
includes/documents/abstract-wcpdf-order-document.php CHANGED
@@ -517,7 +517,11 @@ abstract class Order_Document {
517
  );
518
  $args = $args + $default_args;
519
 
520
- $html = $this->render_template( $this->locate_template_file( "{$this->type}.php" ) );
 
 
 
 
521
  if ($args['wrap_html_content']) {
522
  $html = $this->wrap_html_content( $html );
523
  }
517
  );
518
  $args = $args + $default_args;
519
 
520
+ $html = $this->render_template( $this->locate_template_file( "{$this->type}.php" ), array(
521
+ 'order' => $this->order,
522
+ 'order_id' => $this->order_id,
523
+ )
524
+ );
525
  if ($args['wrap_html_content']) {
526
  $html = $this->wrap_html_content( $html );
527
  }
includes/documents/class-wcpdf-document-number.php CHANGED
@@ -136,6 +136,7 @@ class Document_Number {
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
 
140
  // make replacements
141
  foreach ($formats as $key => $value) {
@@ -145,6 +146,7 @@ class Document_Number {
145
  $value = str_replace("[{$document->slug}_year]", $document_year, $value);
146
  $value = str_replace("[{$document->slug}_month]", $document_month, $value);
147
  $value = str_replace("[{$document->slug}_day]", $document_day, $value);
 
148
 
149
  // replace date tag in the form [invoice_date="{$date_format}"] or [order_date="{$date_format}"]
150
  $date_types = array( 'order', $document->slug );
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) {
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 );
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: 4.9
7
  Requires PHP: 5.3
8
- Stable tag: 2.1.6
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -103,6 +103,15 @@ There's a setting on the Status tab of the settings page that allows you to togg
103
 
104
  == Changelog ==
105
 
 
 
 
 
 
 
 
 
 
106
  = 2.1.6 =
107
  * Fix: Extended currency symbol setting for WooCommerce Currency Switcher by realmag777
108
  * Fix: Apply WooCommerce decimal settings to tax rates with decimals
@@ -241,5 +250,5 @@ There's a setting on the Status tab of the settings page that allows you to togg
241
 
242
  == Upgrade Notice ==
243
 
244
- = 2.1.6 =
245
- 2.X is a BIG update! Make a full site backup before upgrading!
5
  Requires at least: 3.5
6
  Tested up to: 4.9
7
  Requires PHP: 5.3
8
+ Stable tag: 2.1.7
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
103
 
104
  == Changelog ==
105
 
106
+ = 2.1.7 =
107
+ * Feature: add [order_number] placeholder for number format
108
+ * Feature: $order and $order_id variables now available directly template (without needing the document object)
109
+ * Feature: add actions before & after addresses
110
+ * Fix: Sorting orders by invoice number
111
+ * Fix: Aelia Currency Switcher - use decimal & Thousand separator settings
112
+ * Fix: fix jquery migrate warnings for media upload script
113
+ * Tweak: add calculated tax rate to item data
114
+
115
  = 2.1.6 =
116
  * Fix: Extended currency symbol setting for WooCommerce Currency Switcher by realmag777
117
  * Fix: Apply WooCommerce decimal settings to tax rates with decimals
250
 
251
  == Upgrade Notice ==
252
 
253
+ = 2.1.7 =
254
+ 2.X is a BIG update! Make a full site backup before upgrading if you were using version 1.X!
templates/Simple/invoice.php CHANGED
@@ -28,7 +28,9 @@
28
  <tr>
29
  <td class="address billing-address">
30
  <!-- <h3><?php _e( 'Billing Address:', 'woocommerce-pdf-invoices-packing-slips' ); ?></h3> -->
 
31
  <?php $this->billing_address(); ?>
 
32
  <?php if ( isset($this->settings['display_email']) ) { ?>
33
  <div class="billing-email"><?php $this->billing_email(); ?></div>
34
  <?php } ?>
@@ -39,7 +41,9 @@
39
  <td class="address shipping-address">
40
  <?php if ( isset($this->settings['display_shipping_address']) && $this->ships_to_different_address()) { ?>
41
  <h3><?php _e( 'Ship To:', 'woocommerce-pdf-invoices-packing-slips' ); ?></h3>
 
42
  <?php $this->shipping_address(); ?>
 
43
  <?php } ?>
44
  </td>
45
  <td class="order-data">
28
  <tr>
29
  <td class="address billing-address">
30
  <!-- <h3><?php _e( 'Billing Address:', 'woocommerce-pdf-invoices-packing-slips' ); ?></h3> -->
31
+ <?php do_action( 'wpo_wcpdf_before_billing_address', $this->type, $this->order ); ?>
32
  <?php $this->billing_address(); ?>
33
+ <?php do_action( 'wpo_wcpdf_after_billing_address', $this->type, $this->order ); ?>
34
  <?php if ( isset($this->settings['display_email']) ) { ?>
35
  <div class="billing-email"><?php $this->billing_email(); ?></div>
36
  <?php } ?>
41
  <td class="address shipping-address">
42
  <?php if ( isset($this->settings['display_shipping_address']) && $this->ships_to_different_address()) { ?>
43
  <h3><?php _e( 'Ship To:', 'woocommerce-pdf-invoices-packing-slips' ); ?></h3>
44
+ <?php do_action( 'wpo_wcpdf_before_shipping_address', $this->type, $this->order ); ?>
45
  <?php $this->shipping_address(); ?>
46
+ <?php do_action( 'wpo_wcpdf_after_shipping_address', $this->type, $this->order ); ?>
47
  <?php } ?>
48
  </td>
49
  <td class="order-data">
templates/Simple/packing-slip.php CHANGED
@@ -28,7 +28,9 @@
28
  <tr>
29
  <td class="address shipping-address">
30
  <!-- <h3><?php _e( 'Shipping Address:', 'woocommerce-pdf-invoices-packing-slips' ); ?></h3> -->
 
31
  <?php $this->shipping_address(); ?>
 
32
  <?php if ( isset($this->settings['display_email']) ) { ?>
33
  <div class="billing-email"><?php $this->billing_email(); ?></div>
34
  <?php } ?>
@@ -39,7 +41,9 @@
39
  <td class="address billing-address">
40
  <?php if ( isset($this->settings['display_billing_address']) && $this->ships_to_different_address()) { ?>
41
  <h3><?php _e( 'Billing Address:', 'woocommerce-pdf-invoices-packing-slips' ); ?></h3>
 
42
  <?php $this->billing_address(); ?>
 
43
  <?php } ?>
44
  </td>
45
  <td class="order-data">
28
  <tr>
29
  <td class="address shipping-address">
30
  <!-- <h3><?php _e( 'Shipping Address:', 'woocommerce-pdf-invoices-packing-slips' ); ?></h3> -->
31
+ <?php do_action( 'wpo_wcpdf_before_shipping_address', $this->type, $this->order ); ?>
32
  <?php $this->shipping_address(); ?>
33
+ <?php do_action( 'wpo_wcpdf_after_shipping_address', $this->type, $this->order ); ?>
34
  <?php if ( isset($this->settings['display_email']) ) { ?>
35
  <div class="billing-email"><?php $this->billing_email(); ?></div>
36
  <?php } ?>
41
  <td class="address billing-address">
42
  <?php if ( isset($this->settings['display_billing_address']) && $this->ships_to_different_address()) { ?>
43
  <h3><?php _e( 'Billing Address:', 'woocommerce-pdf-invoices-packing-slips' ); ?></h3>
44
+ <?php do_action( 'wpo_wcpdf_before_billing_address', $this->type, $this->order ); ?>
45
  <?php $this->billing_address(); ?>
46
+ <?php do_action( 'wpo_wcpdf_after_billing_address', $this->type, $this->order ); ?>
47
  <?php } ?>
48
  </td>
49
  <td class="order-data">
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.1.6
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.1.6';
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.1.7
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.1.7';
25
  public $plugin_basename;
26
  public $legacy_mode;
27