-
Notifications
You must be signed in to change notification settings - Fork 0
/
woocommerce-pdf-invoices-packingslips.php
executable file
·806 lines (690 loc) · 24.6 KB
/
woocommerce-pdf-invoices-packingslips.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
<?php
/**
* Plugin Name: WooCommerce PDF Invoices & Packing Slips
* Plugin URI: http://www.wpovernight.com
* Description: Create, print & email PDF invoices & packing slips for WooCommerce orders.
* Version: 1.5.0
* Author: Ewout Fernhout
* Author URI: http://www.wpovernight.com
* License: GPLv2 or later
* License URI: http://www.opensource.org/licenses/gpl-license.php
* Text Domain: wpo_wcpdf
*/
if ( !class_exists( 'WooCommerce_PDF_Invoices' ) ) {
class WooCommerce_PDF_Invoices {
public static $plugin_prefix;
public static $plugin_url;
public static $plugin_path;
public static $plugin_basename;
public static $version;
public $writepanels;
public $settings;
public $export;
/**
* Constructor
*/
public function __construct() {
self::$plugin_prefix = 'wpo_wcpdf_';
self::$plugin_basename = plugin_basename(__FILE__);
self::$plugin_url = plugin_dir_url(self::$plugin_basename);
self::$plugin_path = trailingslashit(dirname(__FILE__));
self::$version = '1.5.0';
// load the localisation & classes
add_action( 'plugins_loaded', array( $this, 'translations' ) ); // or use init?
add_action( 'init', array( $this, 'load_classes' ) );
// run lifecycle methods
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
// check if upgrading from versionless (1.4.14 and older)
if ( get_option('wpo_wcpdf_general_settings') && get_option('wpo_wcpdf_version') === false ) {
// tag 'versionless', so that we can apply necessary upgrade settings
add_option( 'wpo_wcpdf_version', 'versionless' );
}
add_action( 'wp_loaded', array( $this, 'do_install' ) );
}
}
/**
* Load the translation / textdomain files
*
* Note: the first-loaded translation file overrides any following ones if the same translation is present
*/
public function translations() {
$locale = apply_filters( 'plugin_locale', get_locale(), 'wpo_wcpdf' );
$dir = trailingslashit( WP_LANG_DIR );
/**
* Frontend/global Locale. Looks in:
*
* - WP_LANG_DIR/woocommerce-pdf-invoices-packing-slips/wpo_wcpdf-LOCALE.mo
* - woocommerce-pdf-invoices-packing-slips/languages/wpo_wcpdf-LOCALE.mo (which if not found falls back to:)
* - WP_LANG_DIR/plugins/wpo_wcpdf-LOCALE.mo
*/
load_textdomain( 'wpo_wcpdf', $dir . 'woocommerce-pdf-invoices-packing-slips/wpo_wcpdf-' . $locale . '.mo' );
load_plugin_textdomain( 'wpo_wcpdf', false, dirname( self::$plugin_basename ) . '/languages' );
}
/**
* Load the main plugin classes and functions
*/
public function includes() {
include_once( 'includes/class-wcpdf-settings.php' );
include_once( 'includes/class-wcpdf-writepanels.php' );
include_once( 'includes/class-wcpdf-export.php' );
}
/**
* Instantiate classes when woocommerce is activated
*/
public function load_classes() {
if ( $this->is_woocommerce_activated() ) {
$this->includes();
$this->settings = new WooCommerce_PDF_Invoices_Settings();
$this->writepanels = new WooCommerce_PDF_Invoices_Writepanels();
$this->export = new WooCommerce_PDF_Invoices_Export();
} else {
// display notice instead
add_action( 'admin_notices', array ( $this, 'need_woocommerce' ) );
}
}
/**
* Check if woocommerce is activated
*/
public function is_woocommerce_activated() {
$blog_plugins = get_option( 'active_plugins', array() );
$site_plugins = get_site_option( 'active_sitewide_plugins', array() );
if ( in_array( 'woocommerce/woocommerce.php', $blog_plugins ) || isset( $site_plugins['woocommerce/woocommerce.php'] ) ) {
return true;
} else {
return false;
}
}
/**
* WooCommerce not active notice.
*
* @return string Fallack notice.
*/
public function need_woocommerce() {
$error = sprintf( __( 'WooCommerce PDF Invoices & Packing Slips requires %sWooCommerce%s to be installed & activated!' , 'wpo_wcpdf' ), '<a href="http://wordpress.org/extend/plugins/woocommerce/">', '</a>' );
$message = '<div class="error"><p>' . $error . '</p></div>';
echo $message;
}
/** Lifecycle methods *******************************************************
* Because register_activation_hook only runs when the plugin is manually
* activated by the user, we're checking the current version against the
* version stored in the database
****************************************************************************/
/**
* Handles version checking
*/
public function do_install() {
$version_setting = 'wpo_wcpdf_version';
$installed_version = get_option( $version_setting );
// installed version lower than plugin version?
if ( version_compare( $installed_version, self::$version, '<' ) ) {
if ( ! $installed_version ) {
$this->install();
} else {
$this->upgrade( $installed_version );
}
// new version number
update_option( $version_setting, self::$version );
}
}
/**
* Plugin install method. Perform any installation tasks here
*/
protected function install() {
// Create temp folders
$tmp_base = $this->export->get_tmp_base();
// check if tmp folder exists => if not, initialize
if ( !@is_dir( $tmp_base ) ) {
$this->export->init_tmp( $tmp_base );
}
}
/**
* Plugin upgrade method. Perform any required upgrades here
*
* @param string $installed_version the currently installed version
*/
protected function upgrade( $installed_version ) {
if ( $installed_version == 'versionless') { // versionless = 1.4.14 and older
// We're upgrading from an old version, so we're enabling the option to use the plugin tmp folder.
// This is not per se the 'best' solution, but the good thing is that nothing is changed ]
// and nothing will be broken (that wasn't broken before)
$default = array( 'old_tmp' => 1 );
update_option( 'wpo_wcpdf_debug_settings', $default );
}
// sync fonts on every upgrade!
$debug_settings = get_option( 'wpo_wcpdf_debug_settings' ); // get temp setting
// do not copy if old_tmp function active!
if ( !isset($this->debug_settings['old_tmp']) ) {
$tmp_base = $this->export->get_tmp_base();
$font_path = $tmp_base . 'fonts/';
$this->export->copy_fonts( $font_path );
}
}
/***********************************************************************/
/********************** GENERAL TEMPLATE FUNCTIONS *********************/
/***********************************************************************/
/**
* Output template styles
*/
public function template_styles() {
$css = apply_filters( 'wpo_wcpdf_template_styles', $this->export->template_path. '/' .'style.css' );
ob_start();
if (file_exists($css)) {
include($css);
}
$html = ob_get_clean();
$html = apply_filters( 'wpo_wcpdf_template_styles', $html );
echo $html;
}
/**
* Return logo id
*/
public function get_header_logo_id() {
if (isset($this->settings->template_settings['header_logo'])) {
return apply_filters( 'wpo_wcpdf_header_logo_id', $this->settings->template_settings['header_logo'] );
}
}
/**
* Show logo html
*/
public function header_logo() {
if ($this->get_header_logo_id()) {
$attachment_id = $this->get_header_logo_id();
$company = isset($this->settings->template_settings['shop_name'])? $this->settings->template_settings['shop_name'] : '';
if( $attachment_id ) {
$attachment = wp_get_attachment_image_src( $attachment_id, 'full', false );
$attachment_src = $attachment[0];
$attachment_width = $attachment[1];
$attachment_height = $attachment[2];
$attachment_path = get_attached_file( $attachment_id );
if ( apply_filters('wpo_wcpdf_use_path', true) && file_exists($attachment_path) ) {
$src = $attachment_path;
} else {
$src = $attachment_src;
}
printf('<img src="%1$s" width="%2$d" height="%3$d" alt="%4$s" />', $src, $attachment_width, $attachment_height, esc_attr( $company ) );
}
}
}
/**
* Return/Show custom company name or default to blog name
*/
public function get_shop_name() {
if (!empty($this->settings->template_settings['shop_name'])) {
$name = trim( $this->settings->template_settings['shop_name'] );
return apply_filters( 'wpo_wcpdf_shop_name', wptexturize( $name ) );
} else {
return apply_filters( 'wpo_wcpdf_shop_name', get_bloginfo( 'name' ) );
}
}
public function shop_name() {
echo $this->get_shop_name();
}
/**
* Return/Show shop/company address if provided
*/
public function get_shop_address() {
if (isset($this->settings->template_settings['shop_address']))
return apply_filters( 'wpo_wcpdf_shop_address', wpautop( wptexturize( $this->settings->template_settings['shop_address'] ) ) );
}
public function shop_address() {
echo $this->get_shop_address();
}
/**
* Return/Show billing address
*/
public function get_billing_address() {
if ( $address = $this->export->order->get_formatted_billing_address() ) {
return apply_filters( 'wpo_wcpdf_billing_address', $address );
}
if ( !$address && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
// try parent address
// temporarily switch order to make all filters / order calls work correctly
$current_order = $this->export->order;
$this->export->order = new WC_Order( $parent_order_id );
$address = apply_filters( 'wpo_wcpdf_billing_address', $this->export->order->get_formatted_billing_address() );
// switch back & unset
$this->export->order = $current_order;
unset($current_order);
} else {
$address = __('N/A', 'wpo_wcpdf');
}
return $address;
}
public function billing_address() {
echo $this->get_billing_address();
}
/**
* Return/Show billing email
*/
public function get_billing_email() {
$billing_email = $this->export->order->billing_email;
if ( !$billing_email && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
// try parent
$billing_email = get_post_meta( $parent_order_id, '_billing_email', true );
}
return apply_filters( 'wpo_wcpdf_billing_email', $billing_email );
}
public function billing_email() {
echo $this->get_billing_email();
}
/**
* Return/Show billing phone
*/
public function get_billing_phone() {
$billing_phone = $this->export->order->billing_phone;
if ( !$billing_phone && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
// try parent
$billing_phone = get_post_meta( $parent_order_id, '_billing_phone', true );
}
return apply_filters( 'wpo_wcpdf_billing_phone', $billing_phone );
}
public function billing_phone() {
echo $this->get_billing_phone();
}
/**
* Return/Show shipping address
*/
public function get_shipping_address() {
if ( $address = $this->export->order->get_formatted_shipping_address() ) {
return apply_filters( 'wpo_wcpdf_shipping_address', $address );
}
if ( !$address && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
// try parent address
// temporarily switch order to make all filters / order calls work correctly
$current_order = $this->export->order;
$this->export->order = new WC_Order( $parent_order_id );
$address = apply_filters( 'wpo_wcpdf_shipping_address', $this->export->order->get_formatted_shipping_address() );
// switch back & unset
$this->export->order = $current_order;
unset($current_order);
} else {
$address = __('N/A', 'wpo_wcpdf');
}
return $address;
}
public function shipping_address() {
echo $this->get_shipping_address();
}
/**
* Return/Show a custom field
*/
public function get_custom_field( $field_name ) {
$custom_field = get_post_meta($this->export->order->id,$field_name,true);
if ( !$custom_field && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
// try parent
$custom_field = get_post_meta( $parent_order_id, $field_name, true );
}
return apply_filters( 'wpo_wcpdf_billing_custom_field', $custom_field );
}
public function custom_field( $field_name, $field_label = '', $display_empty = false ) {
$custom_field = $this->get_custom_field( $field_name );
if (!empty($field_label)){
// add a a trailing space to the label
$field_label .= ' ';
}
if (!empty($custom_field) || $display_empty) {
echo $field_label . nl2br ($custom_field);
}
}
/**
* Return/Show order notes
*/
public function get_order_notes( $filter = 'customer' ) {
$args = array(
'post_id' => $this->export->order->id,
'approve' => 'approve',
'type' => 'order_note'
);
remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 );
$notes = get_comments( $args );
add_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 );
if ( $notes ) {
foreach( $notes as $key => $note ) {
if ( $filter == 'customer' && !get_comment_meta( $note->comment_ID, 'is_customer_note', true ) ) {
unset($notes[$key]);
}
if ( $filter == 'private' && get_comment_meta( $note->comment_ID, 'is_customer_note', true ) ) {
unset($notes[$key]);
}
}
return $notes;
}
}
public function order_notes( $filter = 'customer' ) {
$notes = $this->get_order_notes( $filter );
if ( $notes ) {
foreach( $notes as $note ) {
?>
<div class="note_content">
<?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?>
</div>
<?php
}
}
}
/**
* Return/Show the current date
*/
public function get_current_date() {
return apply_filters( 'wpo_wcpdf_date', date_i18n( get_option( 'date_format' ) ) );
}
public function current_date() {
echo $this->get_current_date();
}
/**
* Return/Show payment method
*/
public function get_payment_method() {
$Payment_method_label = __( 'Payment method', 'wpo_wcpdf' );
return apply_filters( 'wpo_wcpdf_payment_method', __( $this->export->order->payment_method_title, 'woocommerce' ) );
}
public function payment_method() {
echo $this->get_payment_method();
}
/**
* Return/Show shipping method
*/
public function get_shipping_method() {
$shipping_method_label = __( 'Shipping method', 'wpo_wcpdf' );
return apply_filters( 'wpo_wcpdf_shipping_method', __( $this->export->order->get_shipping_method(), 'woocommerce' ) );
}
public function shipping_method() {
echo $this->get_shipping_method();
}
/**
* Return/Show order number (or invoice number)
*/
public function get_order_number() {
// try parent first
if ( get_post_type( $this->export->order->id ) == 'shop_order_refund' && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
$parent_order = new WC_Order( $parent_order_id );
$order_number = $parent_order->get_order_number();
} else {
$order_number = $this->export->order->get_order_number();
}
// Trim the hash to have a clean number but still
// support any filters that were applied before.
$order_number = ltrim($order_number, '#');
return apply_filters( 'wpo_wcpdf_order_number', $order_number);
}
public function order_number() {
echo $this->get_order_number();
}
/**
* Return/Show invoice number
*/
public function get_invoice_number() {
$invoice_number = $this->export->get_invoice_number( $this->export->order->id );
return $invoice_number;
}
public function invoice_number() {
echo $this->get_invoice_number();
}
/**
* Return/Show the order date
*/
public function get_order_date() {
if ( get_post_type( $this->export->order->id ) == 'shop_order_refund' && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
$parent_order = new WC_Order( $parent_order_id );
$date = $parent_order->order_date;
} else {
$date = $this->export->order->order_date;
}
$date = date_i18n( get_option( 'date_format' ), strtotime( $date ) );
return apply_filters( 'wpo_wcpdf_order_date', $date );
}
public function order_date() {
echo $this->get_order_date();
}
/**
* Return/Show the invoice date
*/
public function get_invoice_date() {
$invoice_date = get_post_meta($this->export->order->id,'_wcpdf_invoice_date',true);
// add invoice date if it doesn't exist
if ( empty($invoice_date) || !isset($invoice_date) ) {
$invoice_date = current_time('mysql');
update_post_meta( $this->export->order->id, '_wcpdf_invoice_date', $invoice_date );
}
$formatted_invoice_date = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) );
return apply_filters( 'wpo_wcpdf_invoice_date', $formatted_invoice_date, $invoice_date );
}
public function invoice_date() {
echo $this->get_invoice_date();
}
/**
* Return the order items
*/
public function get_order_items() {
return apply_filters( 'wpo_wcpdf_order_items', $this->export->get_order_items() );
}
/**
* Return the order totals listing
*/
public function get_woocommerce_totals() {
// get totals and remove the semicolon
$totals = apply_filters( 'wpo_wcpdf_raw_order_totals', $this->export->order->get_order_item_totals(), $this->export->order );
// remove the colon for every label
foreach ( $totals as $key => $total ) {
$label = $total['label'];
$colon = strrpos( $label, ':' );
if( $colon !== false ) {
$label = substr_replace( $label, '', $colon, 1 );
}
$totals[$key]['label'] = $label;
}
return apply_filters( 'wpo_wcpdf_woocommerce_totals', $totals, $this->export->order );
}
/**
* Return/show the order subtotal
*/
public function get_order_subtotal( $tax = 'excl', $discount = 'incl' ) { // set $tax to 'incl' to include tax, same for $discount
//$compound = ($discount == 'incl')?true:false;
$subtotal = $this->export->order->get_subtotal_to_display( false, $tax );
$subtotal = ($pos = strpos($subtotal, ' <small>')) ? substr($subtotal, 0, $pos) : $subtotal; //removing the 'excluding tax' text
$subtotal = array (
'label' => __('Subtotal', 'wpo_wcpdf'),
'value' => $subtotal,
);
return apply_filters( 'wpo_wcpdf_order_subtotal', $subtotal );
}
public function order_subtotal( $tax = 'excl', $discount = 'incl' ) {
$subtotal = $this->get_order_subtotal( $tax, $discount );
echo $subtotal['value'];
}
/**
* Return/show the order shipping costs
*/
public function get_order_shipping( $tax = 'excl' ) { // set $tax to 'incl' to include tax
if ($tax == 'excl' ) {
$shipping_costs = woocommerce_price ( $this->export->order->order_shipping );
} else {
$shipping_costs = woocommerce_price ( $this->export->order->order_shipping + $this->export->order->order_shipping_tax );
}
$shipping = array (
'label' => __('Shipping', 'wpo_wcpdf'),
'value' => $shipping_costs,
);
return apply_filters( 'wpo_wcpdf_order_shipping', $shipping );
}
public function order_shipping( $tax = 'excl' ) {
$shipping = $this->get_order_shipping( $tax );
echo $shipping['value'];
}
/**
* Return/show the total discount
*/
public function get_order_discount( $type = 'total', $tax = 'incl' ) {
if ( $tax == 'incl' ) {
switch ($type) {
case 'cart':
// Cart Discount - pre-tax discounts.
$discount_value = $this->export->order->get_cart_discount();
break;
case 'order':
// Order Discount - post-tax discounts.
$discount_value = $this->export->order->get_order_discount();
break;
case 'total':
// Total Discount - Cart & Order Discounts combined
$discount_value = $this->export->order->get_total_discount();
break;
default:
// Total Discount - Cart & Order Discounts combined
$discount_value = $this->export->order->get_total_discount();
break;
}
} else { // calculate discount excluding tax
$discount_value = 0;
$items = $this->export->order->get_items();;
if( sizeof( $items ) > 0 ) {
foreach( $items as $item ) {
$discount_value += ($item['line_subtotal'] - $item['line_total']);
}
}
}
$discount = array (
'label' => __('Discount', 'wpo_wcpdf'),
'value' => $this->export->wc_price($discount_value),
);
if ( $discount_value > 0 ) {
return apply_filters( 'wpo_wcpdf_order_discount', $discount );
}
}
public function order_discount( $type = 'total', $tax = 'incl' ) {
$discount = $this->get_order_discount( $type, $tax );
echo $discount['value'];
}
/**
* Return the order fees
*/
public function get_order_fees( $tax = 'excl' ) {
if ( $wcfees = $this->export->order->get_fees() ) {
foreach( $wcfees as $id => $fee ) {
if ($tax == 'excl' ) {
$fee_price = woocommerce_price( $fee['line_total'] );
} else {
$fee_price = woocommerce_price( $fee['line_total'] + $fee['line_tax'] );
}
$fees[ $id ] = array(
'label' => $fee['name'],
'value' => $fee_price
);
}
return $fees;
}
}
/**
* Return the order taxes
*/
public function get_order_taxes() {
$tax_label = __( 'VAT', 'wpo_wcpdf' ); // register alternate label translation
$tax_rate_ids = $this->export->get_tax_rate_ids();
if ($this->export->order->get_taxes()) {
foreach ( $this->export->order->get_taxes() as $key => $tax ) {
$taxes[ $key ] = array(
'label' => isset( $tax[ 'label' ] ) ? $tax[ 'label' ] : $tax[ 'name' ],
'value' => woocommerce_price( ( $tax[ 'tax_amount' ] + $tax[ 'shipping_tax_amount' ] ) ),
'rate_id' => $tax['rate_id'],
'tax_amount' => $tax['tax_amount'],
'shipping_tax_amount' => $tax['shipping_tax_amount'],
'rate' => isset( $tax_rate_ids[ $tax['rate_id'] ] ) ? ( (float) $tax_rate_ids[$tax['rate_id']]['tax_rate'] ) . ' %': '',
);
}
return apply_filters( 'wpo_wcpdf_order_taxes', $taxes );
}
}
/**
* Return/show the order grand total
*/
public function get_order_grand_total( $tax = 'incl' ) {
if ($tax == 'excl' ) {
$total_tax = 0;
foreach ( $this->export->order->get_taxes() as $tax ) {
$total_tax += ( $tax[ 'tax_amount' ] + $tax[ 'shipping_tax_amount' ] );
}
if ( version_compare( WOOCOMMERCE_VERSION, '2.1' ) >= 0 ) {
// WC 2.1 or newer is used
$total_unformatted = $this->export->order->get_total();
} else {
// Backwards compatibility
$total_unformatted = $this->export->order->get_order_total();
}
$total = woocommerce_price( ( $total_unformatted - $total_tax ) );
$label = __('Total ex. VAT');
} else {
$total = $this->export->order->get_formatted_order_total();
$label = __('Total');
}
$grand_total = array(
'label' => $label,
'value' => $total,
);
return apply_filters( 'wpo_wcpdf_order_grand_total', $grand_total );
}
public function order_grand_total( $tax = 'incl' ) {
$grand_total = $this->get_order_grand_total( $tax );
echo $grand_total['value'];
}
/**
* Return/Show shipping notes
*/
public function get_shipping_notes() {
$shipping_notes = wpautop( wptexturize( $this->export->order->customer_note ) );
return apply_filters( 'wpo_wcpdf_shipping_notes', $shipping_notes );
}
public function shipping_notes() {
echo $this->get_shipping_notes();
}
/**
* Return/Show shop/company footer imprint, copyright etc.
*/
public function get_footer() {
if (isset($this->settings->template_settings['footer'])) {
$footer = wpautop( wptexturize( $this->settings->template_settings[ 'footer' ] ) );
return apply_filters( 'wpo_wcpdf_footer', $footer );
}
}
public function footer() {
echo $this->get_footer();
}
/**
* Return/Show Extra field 1
*/
public function get_extra_1() {
if (isset($this->settings->template_settings['extra_1'])) {
$extra_1 = nl2br( wptexturize( $this->settings->template_settings[ 'extra_1' ] ) );
return apply_filters( 'wpo_wcpdf_extra_1', $extra_1 );
}
}
public function extra_1() {
echo $this->get_extra_1();
}
/**
* Return/Show Extra field 2
*/
public function get_extra_2() {
if (isset($this->settings->template_settings['extra_2'])) {
$extra_2 = nl2br( wptexturize( $this->settings->template_settings[ 'extra_2' ] ) );
return apply_filters( 'wpo_wcpdf_extra_2', $extra_2 );
}
}
public function extra_2() {
echo $this->get_extra_2();
}
/**
* Return/Show Extra field 3
*/
public function get_extra_3() {
if (isset($this->settings->template_settings['extra_3'])) {
$extra_3 = nl2br( wptexturize( $this->settings->template_settings[ 'extra_3' ] ) );
return apply_filters( 'wpo_wcpdf_extra_3', $extra_3 );
}
}
public function extra_3() {
echo $this->get_extra_3();
}
}
}
// Load main plugin class
$wpo_wcpdf = new WooCommerce_PDF_Invoices();