WooCommerce PDF Invoices & Packing Slips - Version 1.6.1

Version Description

  • Fix: Error with totals in credit notes
  • Fix: Always set invoice date when invoice is create (even display is disabled in the settings)
Download this release

Release Info

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

Code changes from version 1.6.0.2 to 1.6.1

includes/class-wcpdf-export.php CHANGED
@@ -288,6 +288,7 @@ if ( ! class_exists( 'WooCommerce_PDF_Invoices_Export' ) ) {
288
  // Set the invoice number
289
  if ( $template_type == 'invoice' ) {
290
  $this->set_invoice_number( $order_id );
 
291
  }
292
 
293
  $output_html[$order_id] = $this->get_template($template);
@@ -509,19 +510,24 @@ if ( ! class_exists( 'WooCommerce_PDF_Invoices_Export' ) ) {
509
  case 'invoice':
510
  $name = _n( 'invoice', 'invoices', $count, 'wpo_wcpdf' );
511
  $number = $this->get_display_number( $order_ids[0] );
512
- break;
513
  case 'packing-slip':
514
  $name = _n( 'packing-slip', 'packing-slips', $count, 'wpo_wcpdf' );
515
  $number = $this->order->get_order_number();
516
  break;
517
  default:
518
  $name = $template_type;
519
- $number = method_exists( $this->order, 'get_order_number' ) ? $this->order->get_order_number() : '';
 
 
 
 
 
520
  break;
521
  }
522
 
523
  if ( $count == 1 ) {
524
- $suffix = $number;
525
  } else {
526
  $suffix = date('Y-m-d'); // 2020-11-11
527
  }
@@ -746,6 +752,26 @@ if ( ! class_exists( 'WooCommerce_PDF_Invoices_Export' ) ) {
746
  }
747
  }
748
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
749
  /**
750
  * Add invoice number to WC REST API
751
  */
288
  // Set the invoice number
289
  if ( $template_type == 'invoice' ) {
290
  $this->set_invoice_number( $order_id );
291
+ $this->set_invoice_date( $order_id );
292
  }
293
 
294
  $output_html[$order_id] = $this->get_template($template);
510
  case 'invoice':
511
  $name = _n( 'invoice', 'invoices', $count, 'wpo_wcpdf' );
512
  $number = $this->get_display_number( $order_ids[0] );
513
+ break;
514
  case 'packing-slip':
515
  $name = _n( 'packing-slip', 'packing-slips', $count, 'wpo_wcpdf' );
516
  $number = $this->order->get_order_number();
517
  break;
518
  default:
519
  $name = $template_type;
520
+ $order_id = WCX_Order::get_id( $this->order );
521
+ if ( get_post_type( $order_id ) == 'shop_order_refund' ) {
522
+ $number = $order_id;
523
+ } else {
524
+ $number = method_exists( $this->order, 'get_order_number' ) ? $this->order->get_order_number() : '';
525
+ }
526
  break;
527
  }
528
 
529
  if ( $count == 1 ) {
530
+ $suffix = $number;
531
  } else {
532
  $suffix = date('Y-m-d'); // 2020-11-11
533
  }
752
  }
753
  }
754
 
755
+ public function set_invoice_date( $order_id ) {
756
+ $order = $this->get_order( $order_id );
757
+ $invoice_date = WCX_Order::get_meta( WPO_WCPDF()->export->order, '_wcpdf_invoice_date', true );
758
+
759
+ // add invoice date if it doesn't exist
760
+ if ( empty($invoice_date) || !isset($invoice_date) ) {
761
+ $invoice_date = current_time('mysql');
762
+ WCX_Order::update_meta_data( WPO_WCPDF()->export->order, '_wcpdf_invoice_date', $invoice_date );
763
+ }
764
+
765
+ return $invoice_date;
766
+ }
767
+
768
+ public function get_invoice_date( $order_id ) {
769
+ $invoice_date = $this->set_invoice_date( $order_id );
770
+ $formatted_invoice_date = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) );
771
+
772
+ return apply_filters( 'wpo_wcpdf_invoice_date', $formatted_invoice_date, $invoice_date );
773
+ }
774
+
775
  /**
776
  * Add invoice number to WC REST API
777
  */
includes/class-wcpdf-functions.php CHANGED
@@ -39,11 +39,11 @@ class WooCommerce_PDF_Invoices_Functions {
39
  if (file_exists($css)) {
40
  include($css);
41
  }
42
- $html = ob_get_clean();
43
  $html = apply_filters( 'wpo_wcpdf_template_styles', $html );
44
 
45
  echo $html;
46
- }
47
 
48
  /**
49
  * Return logo id
@@ -335,7 +335,7 @@ class WooCommerce_PDF_Invoices_Functions {
335
  $payment_method_label = __( 'Payment method', 'wpo_wcpdf' );
336
 
337
  // use parent for credit notes
338
- if ( get_post_type( $order_id ) == 'shop_order_refund' && $parent_order_id = wp_get_post_parent_id( WCX_Order::get_id( WPO_WCPDF()->export->order ) ) ) {
339
  $parent_order = WCX::get_order( $parent_order_id );
340
  $payment_method_title = WCX_Order::get_prop( $parent_order, 'payment_method_title', 'view' );
341
  $payment_method = __( $payment_method_title, 'woocommerce' );
@@ -427,17 +427,9 @@ class WooCommerce_PDF_Invoices_Functions {
427
  * Return/Show the invoice date
428
  */
429
  public function get_invoice_date() {
430
- $invoice_date = WCX_Order::get_meta( WPO_WCPDF()->export->order, '_wcpdf_invoice_date', true );
431
-
432
- // add invoice date if it doesn't exist
433
- if ( empty($invoice_date) || !isset($invoice_date) ) {
434
- $invoice_date = current_time('mysql');
435
- WCX_Order::update_meta_data( WPO_WCPDF()->export->order, '_wcpdf_invoice_date', $invoice_date );
436
- }
437
-
438
- $formatted_invoice_date = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) );
439
-
440
- return apply_filters( 'wpo_wcpdf_invoice_date', $formatted_invoice_date, $invoice_date );
441
  }
442
  public function invoice_date() {
443
  echo $this->get_invoice_date();
@@ -500,43 +492,47 @@ class WooCommerce_PDF_Invoices_Functions {
500
  $totals[$key]['label'] = $label;
501
  }
502
 
503
- // WC2.4 fix order_total for refunded orders
504
- if ( version_compare( WOOCOMMERCE_VERSION, '2.4', '>=' ) && isset($totals['order_total']) ) {
505
- $tax_display = WCX_Order::get_prop( WPO_WCPDF()->export->order, 'tax_display_cart' );
506
- $totals['order_total']['value'] = wc_price( WPO_WCPDF()->export->order->get_total(), array( 'currency' => WCX_Order::get_prop( WPO_WCPDF()->export->order, 'currency' ) ) );
507
- $order_total = WPO_WCPDF()->export->order->get_total();
508
- $tax_string = '';
509
-
510
- // Tax for inclusive prices
511
- if ( wc_tax_enabled() && 'incl' == $tax_display ) {
512
- $tax_string_array = array();
513
-
514
- if ( 'itemized' == get_option( 'woocommerce_tax_total_display' ) ) {
515
- foreach ( WPO_WCPDF()->export->order->get_tax_totals() as $code => $tax ) {
516
- $tax_amount = $tax->formatted_amount;
517
- $tax_string_array[] = sprintf( '%s %s', $tax_amount, $tax->label );
518
- }
519
- } else {
520
- $tax_string_array[] = sprintf( '%s %s', wc_price( WPO_WCPDF()->export->order->get_total_tax() - WPO_WCPDF()->export->order->get_total_tax_refunded(), array( 'currency' => WPO_WCPDF()->export->order->get_order_currency() ) ), WC()->countries->tax_or_vat() );
521
- }
522
- if ( ! empty( $tax_string_array ) ) {
523
- if ( version_compare( WOOCOMMERCE_VERSION, '2.6', '>=' ) ) {
524
- $tax_string = ' ' . sprintf( __( '(includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) );
525
  } else {
526
- // use old capitalized string
527
- $tax_string = ' ' . sprintf( __( '(Includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) );
 
 
 
 
 
 
 
528
  }
529
  }
530
- }
531
 
532
- $totals['order_total']['value'] .= $tax_string;
533
- }
534
 
535
- // remove refund lines (shouldn't be in invoice)
536
- foreach ( $totals as $key => $total ) {
537
- if ( strpos($key, 'refund_') !== false ) {
538
- unset( $totals[$key] );
 
539
  }
 
540
  }
541
 
542
  return apply_filters( 'wpo_wcpdf_woocommerce_totals', $totals, WPO_WCPDF()->export->order );
39
  if (file_exists($css)) {
40
  include($css);
41
  }
42
+ $html = ob_get_clean();
43
  $html = apply_filters( 'wpo_wcpdf_template_styles', $html );
44
 
45
  echo $html;
46
+ }
47
 
48
  /**
49
  * Return logo id
335
  $payment_method_label = __( 'Payment method', 'wpo_wcpdf' );
336
 
337
  // use parent for credit notes
338
+ if ( get_post_type( $order_id ) == 'shop_order_refund' && $parent_order_id = wp_get_post_parent_id( $order_id ) ) {
339
  $parent_order = WCX::get_order( $parent_order_id );
340
  $payment_method_title = WCX_Order::get_prop( $parent_order, 'payment_method_title', 'view' );
341
  $payment_method = __( $payment_method_title, 'woocommerce' );
427
  * Return/Show the invoice date
428
  */
429
  public function get_invoice_date() {
430
+ $order_id = WCX_Order::get_id( WPO_WCPDF()->export->order );
431
+ $invoice_date = WPO_WCPDF()->export->get_invoice_date( $order_id );
432
+ return $invoice_date;
 
 
 
 
 
 
 
 
433
  }
434
  public function invoice_date() {
435
  echo $this->get_invoice_date();
492
  $totals[$key]['label'] = $label;
493
  }
494
 
495
+ $order_id = WCX_Order::get_id( WPO_WCPDF()->export->order );
496
+ if ( get_post_type( $order_id ) != 'shop_order_refund' ) {
497
+ // WC2.4 fix order_total for refunded orders
498
+ if ( version_compare( WOOCOMMERCE_VERSION, '2.4', '>=' ) && isset($totals['order_total']) ) {
499
+ $tax_display = WCX_Order::get_prop( WPO_WCPDF()->export->order, 'tax_display_cart' );
500
+ $totals['order_total']['value'] = wc_price( WPO_WCPDF()->export->order->get_total(), array( 'currency' => WCX_Order::get_prop( WPO_WCPDF()->export->order, 'currency' ) ) );
501
+ $order_total = WPO_WCPDF()->export->order->get_total();
502
+ $tax_string = '';
503
+
504
+ // Tax for inclusive prices
505
+ if ( wc_tax_enabled() && 'incl' == $tax_display ) {
506
+ $tax_string_array = array();
507
+
508
+ if ( 'itemized' == get_option( 'woocommerce_tax_total_display' ) ) {
509
+ foreach ( WPO_WCPDF()->export->order->get_tax_totals() as $code => $tax ) {
510
+ $tax_amount = $tax->formatted_amount;
511
+ $tax_string_array[] = sprintf( '%s %s', $tax_amount, $tax->label );
512
+ }
 
 
 
 
513
  } else {
514
+ $tax_string_array[] = sprintf( '%s %s', wc_price( WPO_WCPDF()->export->order->get_total_tax() - WPO_WCPDF()->export->order->get_total_tax_refunded(), array( 'currency' => WPO_WCPDF()->export->order->get_order_currency() ) ), WC()->countries->tax_or_vat() );
515
+ }
516
+ if ( ! empty( $tax_string_array ) ) {
517
+ if ( version_compare( WOOCOMMERCE_VERSION, '2.6', '>=' ) ) {
518
+ $tax_string = ' ' . sprintf( __( '(includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) );
519
+ } else {
520
+ // use old capitalized string
521
+ $tax_string = ' ' . sprintf( __( '(Includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) );
522
+ }
523
  }
524
  }
 
525
 
526
+ $totals['order_total']['value'] .= $tax_string;
527
+ }
528
 
529
+ // remove refund lines (shouldn't be in invoice)
530
+ foreach ( $totals as $key => $total ) {
531
+ if ( strpos($key, 'refund_') !== false ) {
532
+ unset( $totals[$key] );
533
+ }
534
  }
535
+
536
  }
537
 
538
  return apply_filters( 'wpo_wcpdf_woocommerce_totals', $totals, WPO_WCPDF()->export->order );
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: pomegranate
3
  Tags: woocommerce, pdf, invoices, packing slips, print, delivery notes, invoice, packing slip, export, email, bulk, automatic
4
  Requires at least: 3.5
5
  Tested up to: 4.7
6
- Stable tag: 1.6.0.2
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -99,6 +99,10 @@ There's a setting on the Status tab of the settings page that allows you to togg
99
 
100
  == Changelog ==
101
 
 
 
 
 
102
  = 1.6.0.2 =
103
  * Fix: Don't crash with PHP 5.2 or older (5.3 or higher required, 5.6 or higher recommended)
104
 
@@ -520,5 +524,5 @@ There's a setting on the Status tab of the settings page that allows you to togg
520
 
521
  == Upgrade Notice ==
522
 
523
- = 1.6.0.2 =
524
  Important: Version 1.6 requires PHP 5.3 or higher to run!
3
  Tags: woocommerce, pdf, invoices, packing slips, print, delivery notes, invoice, packing slip, export, email, bulk, automatic
4
  Requires at least: 3.5
5
  Tested up to: 4.7
6
+ Stable tag: 1.6.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
99
 
100
  == Changelog ==
101
 
102
+ = 1.6.1 =
103
+ * Fix: Error with totals in credit notes
104
+ * Fix: Always set invoice date when invoice is create (even display is disabled in the settings)
105
+
106
  = 1.6.0.2 =
107
  * Fix: Don't crash with PHP 5.2 or older (5.3 or higher required, 5.6 or higher recommended)
108
 
524
 
525
  == Upgrade Notice ==
526
 
527
+ = 1.6.1 =
528
  Important: Version 1.6 requires PHP 5.3 or higher to run!
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.6.0.2
7
  * Author: Ewout Fernhout
8
  * Author URI: http://www.wpovernight.com
9
  * License: GPLv2 or later
@@ -48,7 +48,7 @@ if ( !class_exists( 'WooCommerce_PDF_Invoices' ) ) {
48
  self::$plugin_basename = plugin_basename(__FILE__);
49
  self::$plugin_url = plugin_dir_url(self::$plugin_basename);
50
  self::$plugin_path = trailingslashit(dirname(__FILE__));
51
- self::$version = '1.6.0.2';
52
 
53
  // load the localisation & classes
54
  add_action( 'plugins_loaded', array( $this, 'translations' ) ); // or use init?
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.6.1
7
  * Author: Ewout Fernhout
8
  * Author URI: http://www.wpovernight.com
9
  * License: GPLv2 or later
48
  self::$plugin_basename = plugin_basename(__FILE__);
49
  self::$plugin_url = plugin_dir_url(self::$plugin_basename);
50
  self::$plugin_path = trailingslashit(dirname(__FILE__));
51
+ self::$version = '1.6.1';
52
 
53
  // load the localisation & classes
54
  add_action( 'plugins_loaded', array( $this, 'translations' ) ); // or use init?