WooCommerce PDF Invoices & Packing Slips - Version 2.3.2

Version Description

  • Fix: Load enhanced selection styles on settings page
  • Fix: WC Bookings email attachment
  • Tweak: Use WooCommerce 3.7 tax rate data when available.
Download this release

Release Info

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

Code changes from version 2.3.1 to 2.3.2

includes/class-wcpdf-assets.php CHANGED
@@ -87,7 +87,7 @@ class Assets {
87
  wp_enqueue_style(
88
  'wpo-wcpdf-settings-styles',
89
  WPO_WCPDF()->plugin_url() . '/assets/css/settings-styles.css',
90
- array(),
91
  WPO_WCPDF_VERSION
92
  );
93
  wp_add_inline_style( 'wpo-wcpdf-settings-styles', ".next-number-input.ajax-waiting {
87
  wp_enqueue_style(
88
  'wpo-wcpdf-settings-styles',
89
  WPO_WCPDF()->plugin_url() . '/assets/css/settings-styles.css',
90
+ array('woocommerce_admin_styles'),
91
  WPO_WCPDF_VERSION
92
  );
93
  wp_add_inline_style( 'wpo-wcpdf-settings-styles', ".next-number-input.ajax-waiting {
includes/class-wcpdf-main.php CHANGED
@@ -77,6 +77,7 @@ class Main {
77
  if ( get_post_type( $order_id ) == 'wc_booking' && isset($order->order) ) {
78
  // $order is actually a WC_Booking object!
79
  $order = $order->order;
 
80
  }
81
 
82
  // do not process low stock notifications, user emails etc!
@@ -107,7 +108,7 @@ class Main {
107
 
108
  try {
109
  // prepare document
110
- $document = wcpdf_get_document( $document_type, (array) $order_id, true );
111
  if ( !$document ) { // something went wrong, continue trying with other documents
112
  continue;
113
  }
77
  if ( get_post_type( $order_id ) == 'wc_booking' && isset($order->order) ) {
78
  // $order is actually a WC_Booking object!
79
  $order = $order->order;
80
+ $order_id = WCX_Order::get_id( $order );
81
  }
82
 
83
  // do not process low stock notifications, user emails etc!
108
 
109
  try {
110
  // prepare document
111
+ $document = wcpdf_get_document( $document_type, $order, true );
112
  if ( !$document ) { // something went wrong, continue trying with other documents
113
  continue;
114
  }
includes/documents/abstract-wcpdf-order-document-methods.php CHANGED
@@ -527,9 +527,8 @@ abstract class Order_Document_Methods extends Order_Document {
527
  $data['line_tax'] = $this->format_price( $item['line_tax'] );
528
  $data['single_line_tax'] = $this->format_price( $item['line_tax'] / max( 1, abs( $item['qty'] ) ) );
529
 
530
- $line_tax_data = maybe_unserialize( isset( $item['line_tax_data'] ) ? $item['line_tax_data'] : '' );
531
- $data['tax_rates'] = $this->get_tax_rate( $item['tax_class'], $item['line_total'], $item['line_tax'], $line_tax_data, true );
532
- $data['calculated_tax_rates'] = $this->get_tax_rate( $item['tax_class'], $item['line_total'], $item['line_tax'], $line_tax_data, false );
533
 
534
  // Set the line subtotal (=before discount)
535
  $data['line_subtotal'] = $this->format_price( $item['line_subtotal'] );
@@ -592,11 +591,18 @@ abstract class Order_Document_Methods extends Order_Document {
592
  }
593
 
594
  /**
595
- * Get the tax rates/percentages for a given tax class
596
- * @param string $tax_class tax class slug
 
 
597
  * @return string $tax_rates imploded list of tax rates
598
  */
599
- public function get_tax_rate( $tax_class, $line_total, $line_tax, $line_tax_data = '', $force_calculation = false ) {
 
 
 
 
 
600
  // first try the easy wc2.2+ way, using line_tax_data
601
  if ( !empty( $line_tax_data ) && isset($line_tax_data['total']) ) {
602
  $tax_rates = array();
@@ -604,7 +610,7 @@ abstract class Order_Document_Methods extends Order_Document {
604
  $line_taxes = $line_tax_data['subtotal'];
605
  foreach ( $line_taxes as $tax_id => $tax ) {
606
  if ( isset($tax) && $tax !== '' ) {
607
- $tax_rate = $this->get_tax_rate_by_id( $tax_id );
608
  if ( $tax_rate !== false && $force_calculation !== false ) {
609
  $tax_rates[] = $tax_rate . ' %';
610
  } else {
@@ -668,8 +674,15 @@ abstract class Order_Document_Methods extends Order_Document {
668
  * @param int $rate_id woocommerce tax rate id
669
  * @return float $rate percentage rate
670
  */
671
- public function get_tax_rate_by_id( $rate_id ) {
672
  global $wpdb;
 
 
 
 
 
 
 
673
  $rate = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %d;", $rate_id ) );
674
  if ($rate === NULL) {
675
  return false;
@@ -678,6 +691,24 @@ abstract class Order_Document_Methods extends Order_Document {
678
  }
679
  }
680
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
681
  /**
682
  * Returns a an array with rate_id => tax rate data (array) of all tax rates in woocommerce
683
  * @return array $tax_rate_ids keyed by id
527
  $data['line_tax'] = $this->format_price( $item['line_tax'] );
528
  $data['single_line_tax'] = $this->format_price( $item['line_tax'] / max( 1, abs( $item['qty'] ) ) );
529
 
530
+ $data['tax_rates'] = $this->get_tax_rate( $item, $this->order, true );
531
+ $data['calculated_tax_rates'] = $this->get_tax_rate( $item, $this->order, false );
 
532
 
533
  // Set the line subtotal (=before discount)
534
  $data['line_subtotal'] = $this->format_price( $item['line_subtotal'] );
591
  }
592
 
593
  /**
594
+ * Get the tax rates/percentages for an item
595
+ * @param object $item order item
596
+ * @param object $order WC_Order
597
+ * @param bool $force_calculation force calculation of rates rather than retrieving from db
598
  * @return string $tax_rates imploded list of tax rates
599
  */
600
+ public function get_tax_rate( $item, $order, $force_calculation = false ) {
601
+ $tax_class = $item['tax_class'];
602
+ $line_total = $item['line_total'];
603
+ $line_tax = $item['line_tax'];
604
+ $line_tax_data = maybe_unserialize( isset( $item['line_tax_data'] ) ? $item['line_tax_data'] : '' );
605
+
606
  // first try the easy wc2.2+ way, using line_tax_data
607
  if ( !empty( $line_tax_data ) && isset($line_tax_data['total']) ) {
608
  $tax_rates = array();
610
  $line_taxes = $line_tax_data['subtotal'];
611
  foreach ( $line_taxes as $tax_id => $tax ) {
612
  if ( isset($tax) && $tax !== '' ) {
613
+ $tax_rate = $this->get_tax_rate_by_id( $tax_id, $order );
614
  if ( $tax_rate !== false && $force_calculation !== false ) {
615
  $tax_rates[] = $tax_rate . ' %';
616
  } else {
674
  * @param int $rate_id woocommerce tax rate id
675
  * @return float $rate percentage rate
676
  */
677
+ public function get_tax_rate_by_id( $rate_id, $order = null ) {
678
  global $wpdb;
679
+ // WC 3.7+ stores rate in tax items!
680
+ if ( $order_rates = $this->get_tax_rates_from_order( $order ) ) {
681
+ if ( isset( $order_rates[ $rate_id ] ) ) {
682
+ return (float) $order_rates[ $rate_id ];
683
+ }
684
+ }
685
+
686
  $rate = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %d;", $rate_id ) );
687
  if ($rate === NULL) {
688
  return false;
691
  }
692
  }
693
 
694
+ public function get_tax_rates_from_order( $order ) {
695
+ if ( !empty( $order ) && method_exists( $order, 'get_version' ) && version_compare( $order->get_version(), '3.7', '>=' ) ) {
696
+ $tax_rates = array();
697
+ $tax_items = $order->get_items( array('tax') );
698
+
699
+ if ( empty( $tax_items ) ) {
700
+ return $tax_rates;
701
+ }
702
+
703
+ foreach( $tax_items as $tax_item_key => $tax_item ) {
704
+ $tax_rates[ $tax_item->get_rate_id() ] = $tax_item->get_rate_percent();
705
+ }
706
+ return $tax_rates;
707
+ } else {
708
+ return false;
709
+ }
710
+ }
711
+
712
  /**
713
  * Returns a an array with rate_id => tax rate data (array) of all tax rates in woocommerce
714
  * @return array $tax_rate_ids keyed by id
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.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -26,8 +26,7 @@ This WooCommerce extension automatically adds a PDF invoice to the order confirm
26
 
27
  In addition to this, we offer several premium extensions:
28
 
29
- * Create/email PDF Proforma Invoices, Credit Notes (for Refunds), email Packing Slips & more with [WooCommerce PDF Invoices & Packing Slips Professional](https://wpovernight.com/downloads/woocommerce-pdf-invoices-packing-slips-professional/)
30
- * Upload all invoices automatically to Dropbox with [WooCommerce PDF Invoices & Packing Slips to Dropbox](https://wpovernight.com/downloads/woocommerce-pdf-invoices-packing-slips-dropbox/)
31
  * Automatically send new orders or packing slips to your printer, as soon as the customer orders! [WooCommerce Automatic Order Printing](https://www.simbahosting.co.uk/s3/product/woocommerce-automatic-order-printing/?affiliates=2) (from our partners at Simba Hosting)
32
  * More advanced & stylish templates with [WooCommerce PDF Invoices & Packing Slips Premium Templates](https://wpovernight.com/downloads/woocommerce-pdf-invoices-packing-slips-premium-templates/)
33
 
@@ -67,7 +66,7 @@ In the search field type "WooCommerce PDF Invoices & Packing Slips" and click Se
67
 
68
  = Where can I find the documentation? =
69
 
70
- [WooCommerce PDF Invoices & Packing Slips documentation](http://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/)
71
 
72
  = It's not working! =
73
 
@@ -103,6 +102,11 @@ There's a setting on the Status tab of the settings page that allows you to togg
103
 
104
  == Changelog ==
105
 
 
 
 
 
 
106
  = 2.3.1 =
107
  * Fix: Errors for filtered formatted invoice numbers
108
 
5
  Requires at least: 3.5
6
  Tested up to: 5.2
7
  Requires PHP: 5.3
8
+ Stable tag: 2.3.2
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
26
 
27
  In addition to this, we offer several premium extensions:
28
 
29
+ * Create/email PDF Proforma Invoices, Credit Notes (for Refunds), email Packing Slips, automatic upload to Dropbox & more with [WooCommerce PDF Invoices & Packing Slips Professional](https://wpovernight.com/downloads/woocommerce-pdf-invoices-packing-slips-professional/)
 
30
  * Automatically send new orders or packing slips to your printer, as soon as the customer orders! [WooCommerce Automatic Order Printing](https://www.simbahosting.co.uk/s3/product/woocommerce-automatic-order-printing/?affiliates=2) (from our partners at Simba Hosting)
31
  * More advanced & stylish templates with [WooCommerce PDF Invoices & Packing Slips Premium Templates](https://wpovernight.com/downloads/woocommerce-pdf-invoices-packing-slips-premium-templates/)
32
 
66
 
67
  = Where can I find the documentation? =
68
 
69
+ [WooCommerce PDF Invoices & Packing Slips documentation](https://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/)
70
 
71
  = It's not working! =
72
 
102
 
103
  == Changelog ==
104
 
105
+ = 2.3.2 =
106
+ * Fix: Load enhanced selection styles on settings page
107
+ * Fix: WC Bookings email attachment
108
+ * Tweak: Use WooCommerce 3.7 tax rate data when available.
109
+
110
  = 2.3.1 =
111
  * Fix: Errors for filtered formatted invoice numbers
112
 
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.1
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.1';
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.2
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.2';
25
  public $plugin_basename;
26
  public $legacy_mode;
27