WooCommerce PDF Invoices & Packing Slips - Version 1.5.33

Version Description

  • Tweak: Don't apply 'disable free' setting to packing slip attachment
  • Translations: Updated Romanian
Download this release

Release Info

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

Code changes from version 1.5.32 to 1.5.33

includes/class-wcpdf-export.php CHANGED
@@ -1,1225 +1,1226 @@
1
- <?php
2
- /**
3
- * PDF Export class
4
- */
5
- if ( ! class_exists( 'WooCommerce_PDF_Invoices_Export' ) ) {
6
-
7
- class WooCommerce_PDF_Invoices_Export {
8
-
9
- public $template_directory_name;
10
- public $template_base_path;
11
- public $template_default_base_path;
12
- public $template_default_base_uri;
13
- public $template_path;
14
-
15
- public $order;
16
- public $template_type;
17
- public $order_id;
18
- public $output_body;
19
-
20
- /**
21
- * Constructor
22
- */
23
- public function __construct() {
24
- global $woocommerce;
25
- $this->order = new WC_Order('');
26
- $this->general_settings = get_option('wpo_wcpdf_general_settings');
27
- $this->template_settings = get_option('wpo_wcpdf_template_settings');
28
- $this->debug_settings = get_option('wpo_wcpdf_debug_settings');
29
-
30
- $this->template_directory_name = 'pdf';
31
- $this->template_base_path = (defined('WC_TEMPLATE_PATH')?WC_TEMPLATE_PATH:$woocommerce->template_url) . $this->template_directory_name . '/';
32
- $this->template_default_base_path = WooCommerce_PDF_Invoices::$plugin_path . 'templates/' . $this->template_directory_name . '/';
33
- $this->template_default_base_uri = WooCommerce_PDF_Invoices::$plugin_url . 'templates/' . $this->template_directory_name . '/';
34
-
35
- $this->template_path = isset( $this->template_settings['template_path'] )?$this->template_settings['template_path']:'';
36
-
37
- // backwards compatible template path (1.4.4+ uses relative paths instead of absolute)
38
- $backslash_abspath = str_replace('/', '\\', ABSPATH);
39
- if (strpos($this->template_path, ABSPATH) === false && strpos($this->template_path, $backslash_abspath) === false) {
40
- // add site base path, double check it exists!
41
- if ( file_exists( ABSPATH . $this->template_path ) ) {
42
- $this->template_path = ABSPATH . $this->template_path;
43
- }
44
- }
45
-
46
- if ( file_exists( $this->template_path . '/template-functions.php' ) ) {
47
- require_once( $this->template_path . '/template-functions.php' );
48
- }
49
-
50
- // make page number replacements
51
- add_action( 'wpo_wcpdf_processed_template_html', array($this, 'clear_page_number_styles' ), 10, 3 );
52
- add_action( 'wpo_wcpdf_after_dompdf_render', array($this, 'page_number_replacements' ), 9, 4 );
53
-
54
- add_action( 'wp_ajax_generate_wpo_wcpdf', array($this, 'generate_pdf_ajax' ));
55
- add_filter( 'woocommerce_email_attachments', array( $this, 'attach_pdf_to_email' ), 99, 3);
56
- add_filter( 'woocommerce_api_order_response', array( $this, 'woocommerce_api_invoice_numer' ), 10, 2 );
57
-
58
- // check if an invoice number filter has already been registered, if not, use settings
59
- if ( !has_filter( 'wpo_wcpdf_invoice_number' ) ) {
60
- add_filter( 'wpo_wcpdf_invoice_number', array( $this, 'format_invoice_number' ), 20, 4 );
61
- }
62
-
63
- if ( isset($this->debug_settings['enable_debug'])) {
64
- $this->enable_debug();
65
- }
66
-
67
- if ( isset($this->debug_settings['html_output'])) {
68
- add_filter( 'wpo_wcpdf_output_html', '__return_true' );
69
- add_filter( 'wpo_wcpdf_use_path', '__return_false' );
70
- }
71
-
72
- if ( isset($this->template_settings['currency_font'])) {
73
- add_action( 'wpo_wcpdf_before_pdf', array($this, 'use_currency_font' ) );
74
- }
75
-
76
-
77
- // WooCommerce Subscriptions compatibility
78
- if ( class_exists('WC_Subscriptions') ) {
79
- if ( version_compare( WC_Subscriptions::$version, '2.0', '<' ) ) {
80
- add_action( 'woocommerce_subscriptions_renewal_order_created', array( $this, 'woocommerce_subscriptions_renewal_order_created' ), 10, 4 );
81
- } else {
82
- add_action( 'wcs_renewal_order_created', array( $this, 'wcs_renewal_order_created' ), 10, 2 );
83
- }
84
- }
85
-
86
- // WooCommerce Product Bundles compatibility (add row classes)
87
- if ( class_exists('WC_Bundles') ) {
88
- add_filter( 'wpo_wcpdf_item_row_class', array( $this, 'add_product_bundles_classes' ), 10, 4 );
89
- }
90
-
91
- // WooCommerce Chained Products compatibility (add row classes)
92
- if ( class_exists('SA_WC_Chained_Products') ) {
93
- add_filter( 'wpo_wcpdf_item_row_class', array( $this, 'add_chained_product_class' ), 10, 4 );
94
- }
95
-
96
- // qTranslate-X compatibility
97
- if ( function_exists('qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage')) {
98
- $this->qtranslatex_filters();
99
- }
100
- }
101
-
102
- /**
103
- * Install/create plugin tmp folders
104
- */
105
- public function init_tmp ( $tmp_base ) {
106
- // create plugin base temp folder
107
- @mkdir( $tmp_base );
108
-
109
- // create subfolders & protect
110
- $subfolders = array( 'attachments', 'fonts', 'dompdf' );
111
- foreach ( $subfolders as $subfolder ) {
112
- $path = $tmp_base . $subfolder . '/';
113
- @mkdir( $path );
114
-
115
- // copy font files
116
- if ( $subfolder == 'fonts' ) {
117
- $this->copy_fonts( $path );
118
- }
119
-
120
- // create .htaccess file and empty index.php to protect in case an open webfolder is used!
121
- @file_put_contents( $path . '.htaccess', 'deny from all' );
122
- @touch( $path . 'index.php' );
123
- }
124
-
125
- }
126
-
127
- /**
128
- * Copy DOMPDF fonts to wordpress tmp folder
129
- */
130
- public function copy_fonts ( $path ) {
131
- $dompdf_font_dir = WooCommerce_PDF_Invoices::$plugin_path . "lib/dompdf/lib/fonts/";
132
-
133
- // first try the easy way with glob!
134
- if ( function_exists('glob') ) {
135
- $files = glob($dompdf_font_dir."*.*");
136
- foreach($files as $file){
137
- if(!is_dir($file) && is_readable($file)) {
138
- $dest = $path . basename($file);
139
- copy($file, $dest);
140
- }
141
- }
142
- } else {
143
- // fallback method using font cache file (glob is disabled on some servers with disable_functions)
144
- $font_cache_file = $dompdf_font_dir . "dompdf_font_family_cache.php";
145
- $font_cache_dist_file = $dompdf_font_dir . "dompdf_font_family_cache.dist.php";
146
- $fonts = @require_once( $font_cache_file );
147
- $extensions = array( '.ttf', '.ufm', '.ufm.php', '.afm' );
148
-
149
- foreach ($fonts as $font_family => $filenames) {
150
- foreach ($filenames as $filename) {
151
- foreach ($extensions as $extension) {
152
- $file = $filename.$extension;
153
- if (file_exists($file)) {
154
- $dest = $path . basename($file);
155
- copy($file, $dest);
156
- }
157
- }
158
- }
159
- }
160
-
161
- // copy cache files separately
162
- copy($font_cache_file, $path.basename($font_cache_file));
163
- copy($font_cache_dist_file, $path.basename($font_cache_dist_file));
164
- }
165
-
166
- }
167
-
168
- /**
169
- * Return tmp path for different plugin processes
170
- */
171
- public function tmp_path ( $type = '' ) {
172
- // get temp setting
173
- $old_tmp = isset($this->debug_settings['old_tmp']);
174
-
175
- $tmp_base = $this->get_tmp_base();
176
- if (!$old_tmp) {
177
- // check if tmp folder exists => if not, initialize
178
- if ( !@is_dir( $tmp_base ) ) {
179
- $this->init_tmp( $tmp_base );
180
- }
181
- }
182
-
183
- if ( empty( $type ) ) {
184
- return $tmp_base;
185
- }
186
-
187
- switch ( $type ) {
188
- case 'DOMPDF_TEMP_DIR':
189
- // original value : sys_get_temp_dir()
190
- // 1.5+ : $tmp_base . 'dompdf'
191
- $tmp_path = $old_tmp ? sys_get_temp_dir() : $tmp_base . 'dompdf';
192
- break;
193
- case 'DOMPDF_FONT_DIR': // NEEDS TRAILING SLASH!
194
- // original value : DOMPDF_DIR."/lib/fonts/"
195
- // 1.5+ : $tmp_base . 'fonts/'
196
- $tmp_path = $old_tmp ? DOMPDF_DIR."/lib/fonts/" : $tmp_base . 'fonts/';
197
- break;
198
- case 'DOMPDF_FONT_CACHE':
199
- // original value : DOMPDF_FONT_DIR
200
- // 1.5+ : $tmp_base . 'fonts'
201
- $tmp_path = $old_tmp ? DOMPDF_FONT_DIR : $tmp_base . 'fonts';
202
- break;
203
- case 'attachments':
204
- // original value : WooCommerce_PDF_Invoices::$plugin_path . 'tmp/'
205
- // 1.5+ : $tmp_base . 'attachments/'
206
- $tmp_path = $old_tmp ? WooCommerce_PDF_Invoices::$plugin_path . 'tmp/' : $tmp_base . 'attachments/';
207
- break;
208
- default:
209
- $tmp_path = $tmp_base . $type;
210
- break;
211
- }
212
-
213
- // double check for existence, in case tmp_base was installed, but subfolder not created
214
- if ( !@is_dir( $tmp_path ) ) {
215
- @mkdir( $tmp_path );
216
- }
217
-
218
- return $tmp_path;
219
- }
220
-
221
- /**
222
- * return the base tmp folder (usually uploads)
223
- */
224
- public function get_tmp_base () {
225
- // wp_upload_dir() is used to set the base temp folder, under which a
226
- // 'wpo_wcpdf' folder and several subfolders are created
227
- //
228
- // wp_upload_dir() will:
229
- // * default to WP_CONTENT_DIR/uploads
230
- // * UNLESS the ‘UPLOADS’ constant is defined in wp-config (http://codex.wordpress.org/Editing_wp-config.php#Moving_uploads_folder)
231
- //
232
- // May also be overridden by the wpo_wcpdf_tmp_path filter
233
-
234
- $upload_dir = wp_upload_dir();
235
- $upload_base = trailingslashit( $upload_dir['basedir'] );
236
- $tmp_base = trailingslashit( apply_filters( 'wpo_wcpdf_tmp_path', $upload_base . 'wpo_wcpdf/' ) );
237
- return $tmp_base;
238
- }
239
-
240
- /**
241
- * Generate the template output
242
- */
243
- public function process_template( $template_type, $order_ids ) {
244
- $this->template_type = $template_type;
245
- $order_ids = apply_filters( 'wpo_wcpdf_process_order_ids', $order_ids, $template_type );
246
-
247
- // custom function fix
248
- if (function_exists('wpo_wcpdf_payment_form')) {
249
- return false;
250
- }
251
-
252
- // filter out trashed orders
253
- foreach ($order_ids as $key => $order_id) {
254
- $order_status = get_post_status( $order_id );
255
- if ( $order_status == 'trash' ) {
256
- unset( $order_ids[ $key ] );
257
- }
258
- }
259
- // sharing is caring!
260
- $this->order_ids = $order_ids;
261
-
262
- // throw error when no order ids
263
- if ( empty( $order_ids ) ) {
264
- throw new Exception('No orders to export!');
265
- }
266
-
267
- do_action( 'wpo_wcpdf_process_template', $template_type );
268
-
269
- $output_html = array();
270
- foreach ($order_ids as $order_id) {
271
- $this->order = new WC_Order( $order_id );
272
- do_action( 'wpo_wcpdf_process_template_order', $template_type, $order_id );
273
-
274
- $template = $this->template_path . '/' . $template_type . '.php';
275
- $template = apply_filters( 'wpo_wcpdf_template_file', $template, $template_type, $this->order );
276
-
277
- if (!file_exists($template)) {
278
- throw new Exception('Template not found! Check if the following file exists: <pre>'.$template.'</pre><br/>');
279
- }
280
-
281
- // Set the invoice number
282
- if ( $template_type == 'invoice' ) {
283
- $this->set_invoice_number( $order_id );
284
- }
285
-
286
- $output_html[$order_id] = $this->get_template($template);
287
-
288
- // store meta to be able to check if an invoice for an order has been created already
289
- if ( $template_type == 'invoice' ) {
290
- update_post_meta( $order_id, '_wcpdf_invoice_exists', 1 );
291
- }
292
-
293
-
294
- // Wipe post from cache
295
- wp_cache_delete( $order_id, 'posts' );
296
- wp_cache_delete( $order_id, 'post_meta' );
297
- }
298
-
299
- $print_script = "<script language=javascript>window.onload = function(){ window.print(); };</script>";
300
- // <div style="page-break-before: always;"></div>
301
- $page_break = "\n<div style=\"page-break-before: always;\"></div>\n";
302
-
303
-
304
- if (apply_filters('wpo_wcpdf_output_html', false, $template_type) && apply_filters('wpo_wcpdf_print_html', false, $template_type)) {
305
- $this->output_body = $print_script . implode($page_break, $output_html);
306
- } else {
307
- $this->output_body = implode($page_break, $output_html);
308
- }
309
-
310
- // Try to clean up a bit of memory
311
- unset($output_html);
312
-
313
- $template_wrapper = $this->template_path . '/html-document-wrapper.php';
314
-
315
- if (!file_exists($template_wrapper)) {
316
- throw new Exception('Template wrapper not found! Check if the following file exists: <pre>'.$template_wrapper.'</pre><br/>');
317
- }
318
-
319
- $complete_document = $this->get_template($template_wrapper);
320
-
321
- // Try to clean up a bit of memory
322
- unset($this->output_body);
323
-
324
- // clean up special characters
325
- $complete_document = utf8_decode(mb_convert_encoding($complete_document, 'HTML-ENTITIES', 'UTF-8'));
326
-
327
-
328
- return $complete_document;
329
- }
330
-
331
- /**
332
- * Adds spans around placeholders to be able to make replacement (page count) and css (page number)
333
- */
334
- public function clear_page_number_styles ( $html, $template_type, $order_ids ) {
335
- $html = str_replace('{{PAGE_COUNT}}', '<span class="pagecount">{{PAGE_COUNT}}</span>', $html);
336
- $html = str_replace('{{PAGE_NUM}}', '<span class="pagenum"></span>', $html );
337
- return $html;
338
- }
339
-
340
- /**
341
- * Replace {{PAGE_COUNT}} placeholder with total page count
342
- */
343
- public function page_number_replacements ( $dompdf, $html, $template_type, $order_ids ) {
344
- $placeholder = '{{PAGE_COUNT}}';
345
-
346
- // check if placeholder is used
347
- if (strpos($html, $placeholder) !== false ) {
348
- foreach ($dompdf->get_canvas()->get_cpdf()->objects as &$object) {
349
- if (array_key_exists("c", $object) && strpos($object["c"], $placeholder) !== false) {
350
- $object["c"] = str_replace( $placeholder , $dompdf->get_canvas()->get_page_count() , $object["c"] );
351
- }
352
- }
353
- }
354
-
355
- return $dompdf;
356
- }
357
-
358
- /**
359
- * Create & render DOMPDF object
360
- */
361
- public function generate_pdf( $template_type, $order_ids ) {
362
- $paper_size = apply_filters( 'wpo_wcpdf_paper_format', $this->template_settings['paper_size'], $template_type );
363
- $paper_orientation = apply_filters( 'wpo_wcpdf_paper_orientation', 'portrait', $template_type);
364
-
365
- do_action( 'wpo_wcpdf_before_pdf', $template_type );
366
- if ( !class_exists('DOMPDF') ) {
367
- // extra check to avoid clashes with other plugins using DOMPDF
368
- // This could have unwanted side-effects when the version that's already
369
- // loaded is different, and it could also miss fonts etc, but it's better
370
- // than not checking...
371
- require_once( WooCommerce_PDF_Invoices::$plugin_path . "lib/dompdf/dompdf_config.inc.php" );
372
- }
373
-
374
- $dompdf = new DOMPDF();
375
- $html = apply_filters( 'wpo_wcpdf_processed_template_html', $this->process_template( $template_type, $order_ids ), $template_type, $order_ids );
376
- $dompdf->load_html( $html );
377
- $dompdf->set_paper( $paper_size, $paper_orientation );
378
- $dompdf = apply_filters( 'wpo_wcpdf_before_dompdf_render', $dompdf, $html, $template_type, $order_ids );
379
- $dompdf->render();
380
- $dompdf = apply_filters( 'wpo_wcpdf_after_dompdf_render', $dompdf, $html, $template_type, $order_ids );
381
- do_action( 'wpo_wcpdf_after_pdf', $template_type );
382
-
383
- // Try to clean up a bit of memory
384
- unset($complete_pdf);
385
-
386
- return $dompdf;
387
- }
388
-
389
- /**
390
- * Stream PDF
391
- */
392
- public function stream_pdf( $template_type, $order_ids, $filename ) {
393
- $dompdf = $this->generate_pdf( $template_type, $order_ids );
394
- $dompdf->stream($filename);
395
- }
396
-
397
- /**
398
- * Get PDF
399
- */
400
- public function get_pdf( $template_type, $order_ids ) {
401
- try {
402
- $dompdf = $this->generate_pdf( $template_type, $order_ids );
403
- return $dompdf->output();
404
- } catch (Exception $e) {
405
- echo $e->getMessage();
406
- return false;
407
- }
408
-
409
- }
410
-
411
- /**
412
- * Load and generate the template output with ajax
413
- */
414
- public function generate_pdf_ajax() {
415
- // Check the nonce
416
- if( empty( $_GET['action'] ) || ! is_user_logged_in() || !check_admin_referer( $_GET['action'] ) ) {
417
- wp_die( __( 'You do not have sufficient permissions to access this page.', 'wpo_wcpdf' ) );
418
- }
419
-
420
- // Check if all parameters are set
421
- if( empty( $_GET['template_type'] ) || empty( $_GET['order_ids'] ) ) {
422
- wp_die( __( 'Some of the export parameters are missing.', 'wpo_wcpdf' ) );
423
- }
424
-
425
- $order_ids = (array) explode('x',$_GET['order_ids']);
426
- // Process oldest first: reverse $order_ids array
427
- $order_ids = array_reverse($order_ids);
428
-
429
- // Check the user privileges
430
- if( apply_filters( 'wpo_wcpdf_check_privs', !current_user_can( 'manage_woocommerce_orders' ) && !current_user_can( 'edit_shop_orders' ) && !isset( $_GET['my-account'] ), $order_ids ) ) {
431
- wp_die( __( 'You do not have sufficient permissions to access this page.', 'wpo_wcpdf' ) );
432
- }
433
-
434
- // User call from my-account page
435
- if ( isset( $_GET['my-account'] ) ) {
436
- // Only for single orders!
437
- if ( count( $order_ids ) > 1 ) {
438
- wp_die( __( 'You do not have sufficient permissions to access this page.', 'wpo_wcpdf' ) );
439
- }
440
-
441
- // Get user_id of order
442
- $this->order = new WC_Order ( $order_ids[0] );
443
-
444
- // Check if current user is owner of order IMPORTANT!!!
445
- if ( $this->order->user_id != get_current_user_id() ) {
446
- wp_die( __( 'You do not have sufficient permissions to access this page.', 'wpo_wcpdf' ) );
447
- }
448
-
449
- // if we got here, we're safe to go!
450
- }
451
-
452
- // Generate the output
453
- $template_type = $_GET['template_type'];
454
- // die($this->process_template( $template_type, $order_ids )); // or use the filter switch below!
455
-
456
- if (apply_filters('wpo_wcpdf_output_html', false, $template_type)) {
457
- // Output html to browser for debug
458
- // NOTE! images will be loaded with the server path by default
459
- // use the wpo_wcpdf_use_path filter (return false) to change this to http urls
460
- die($this->process_template( $template_type, $order_ids ));
461
- }
462
-
463
- if ( !($pdf = $this->get_pdf( $template_type, $order_ids )) ) {
464
- exit;
465
- }
466
-
467
- $filename = $this->build_filename( $template_type, $order_ids, 'download' );
468
-
469
- do_action( 'wpo_wcpdf_created_manually', $pdf, $filename );
470
-
471
- // Get output setting
472
- $output_mode = isset($this->general_settings['download_display'])?$this->general_settings['download_display']:'';
473
-
474
- // Switch headers according to output setting
475
- if ( $output_mode == 'display' || empty($output_mode) ) {
476
- header('Content-type: application/pdf');
477
- header('Content-Disposition: inline; filename="'.$filename.'"');
478
- } else {
479
- header('Content-Description: File Transfer');
480
- header('Content-Type: application/octet-stream');
481
- header('Content-Disposition: attachment; filename="'.$filename.'"');
482
- header('Content-Transfer-Encoding: binary');
483
- header('Connection: Keep-Alive');
484
- header('Expires: 0');
485
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
486
- header('Pragma: public');
487
- }
488
-
489
- // output PDF data
490
- echo($pdf);
491
-
492
- exit;
493
- }
494
-
495
- /**
496
- * Build filename
497
- */
498
- public function build_filename( $template_type, $order_ids, $context ) {
499
- $count = count($order_ids);
500
-
501
- switch ($template_type) {
502
- case 'invoice':
503
- $name = _n( 'invoice', 'invoices', $count, 'wpo_wcpdf' );
504
- $number = $this->get_display_number( $order_ids[0] );
505
- break;
506
- case 'packing-slip':
507
- $name = _n( 'packing-slip', 'packing-slips', $count, 'wpo_wcpdf' );
508
- $number = $this->order->get_order_number();
509
- break;
510
- default:
511
- $name = $template_type;
512
- $number = $this->order->get_order_number();
513
- break;
514
- }
515
-
516
- if ( $count == 1 ) {
517
- $suffix = $number;
518
- } else {
519
- $suffix = date('Y-m-d'); // 2020-11-11
520
- }
521
-
522
- $filename = $name . '-' . $suffix . '.pdf';
523
-
524
- // Filter depending on context (for legacy filter support)
525
- if ( $context == 'download' ) {
526
- $filename = apply_filters( 'wpo_wcpdf_bulk_filename', $filename, $order_ids, $name, $template_type );
527
- } elseif ( $context == 'attachment' ) {
528
- $filename = apply_filters( 'wpo_wcpdf_attachment_filename', $filename, $number, $order_ids[0] );
529
- }
530
-
531
- // Filter filename (use this filter instead of the above legacy filters!)
532
- $filename = apply_filters( 'wpo_wcpdf_filename', $filename, $template_type, $order_ids, $context );
533
-
534
- // sanitize filename (after filters to prevent human errors)!
535
- return sanitize_file_name( $filename );
536
- }
537
-
538
- /**
539
- * Attach invoice to completed order or customer invoice email
540
- */
541
- public function attach_pdf_to_email ( $attachments, $status, $order ) {
542
- // check if all variables properly set
543
- if ( !is_object( $order ) || !isset( $status ) ) {
544
- return $attachments;
545
- }
546
-
547
- // Skip User emails
548
- if ( get_class( $order ) == 'WP_User' ) {
549
- return $attachments;
550
- }
551
-
552
- // WooCommerce Booking compatibility
553
- if ( get_post_type( $order->id ) == 'wc_booking' && isset($order->order) ) {
554
- // $order is actually a WC_Booking object!
555
- $order = $order->order;
556
- }
557
-
558
- // do not process low stock notifications, user emails etc!
559
- if ( in_array( $status, array( 'no_stock', 'low_stock', 'backorder', 'customer_new_account', 'customer_reset_password' ) ) || get_post_type( $order->id ) != 'shop_order' ) {
560
- return $attachments;
561
- }
562
-
563
- // Disable free setting check
564
- $order_total = $order->get_total();
565
- if ( $order_total == 0 && isset($this->general_settings['disable_free']) ) {
566
- return $attachments;
567
- }
568
-
569
- $this->order = $order;
570
-
571
- $tmp_path = $this->tmp_path('attachments');
572
-
573
- // clear pdf files from temp folder (from http://stackoverflow.com/a/13468943/1446634)
574
- array_map('unlink', ( glob( $tmp_path.'*.pdf' ) ? glob( $tmp_path.'*.pdf' ) : array() ) );
575
-
576
- // set allowed statuses for invoices
577
- $invoice_allowed = isset($this->general_settings['email_pdf']) ? array_keys( $this->general_settings['email_pdf'] ) : array();
578
- $documents = array(
579
- 'invoice' => apply_filters( 'wpo_wcpdf_email_allowed_statuses', $invoice_allowed ), // Relevant (default) statuses: new_order, customer_invoice, customer_processing_order, customer_completed_order
580
- );
581
- $documents = apply_filters('wpo_wcpdf_attach_documents', $documents );
582
-
583
- foreach ($documents as $template_type => $allowed_statuses ) {
584
- // convert 'lazy' status name
585
- foreach ($allowed_statuses as $key => $order_status) {
586
- if ($order_status == 'completed' || $order_status == 'processing') {
587
- $allowed_statuses[$key] = "customer_" . $order_status . "_order";
588
- }
589
- }
590
-
591
- // legacy filter, use wpo_wcpdf_custom_attachment_condition instead!
592
- $attach_invoice = apply_filters('wpo_wcpdf_custom_email_condition', true, $order, $status );
593
- if ( $template_type == 'invoice' && !$attach_invoice ) {
594
- // don't attach invoice, continue with other documents
595
- continue;
596
- }
597
-
598
- // use this filter to add an extra condition - return false to disable the PDF attachment
599
- $attach_document = apply_filters('wpo_wcpdf_custom_attachment_condition', true, $order, $status, $template_type );
600
- if( in_array( $status, $allowed_statuses ) && $attach_document ) {
601
- // create pdf data
602
- $pdf_data = $this->get_pdf( $template_type, (array) $order->id );
603
-
604
- if ( !$pdf_data ) {
605
- // something went wrong, continue trying with other documents
606
- continue;
607
- }
608
-
609
- // compose filename
610
- $pdf_filename = $this->build_filename( $template_type, (array) $order->id, 'attachment' );
611
-
612
- $pdf_path = $tmp_path . $pdf_filename;
613
- file_put_contents ( $pdf_path, $pdf_data );
614
- $attachments[] = $pdf_path;
615
-
616
- do_action( 'wpo_wcpdf_email_attachment', $pdf_path, $template_type );
617
- }
618
- }
619
-
620
- return $attachments;
621
- }
622
-
623
- public function set_invoice_number( $order_id ) {
624
- // first check: get invoice number from post meta
625
- $invoice_number = get_post_meta( $order_id, '_wcpdf_invoice_number', true );
626
-
627
- // add invoice number if it doesn't exist
628
- if ( empty($invoice_number) || !isset($invoice_number) ) {
629
- global $wpdb;
630
- // making direct DB call to avoid caching issues
631
- $next_invoice_number = $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", 'wpo_wcpdf_next_invoice_number' ) );
632
- $next_invoice_number = apply_filters( 'wpo_wcpdf_next_invoice_number', $next_invoice_number, $order_id );
633
-
634
- if ( empty($next_invoice_number) ) {
635
- // First time! We start numbering from order_number or order_id
636
-
637
- // Check if $order_number is an integer
638
- $order_number = ltrim($this->order->get_order_number(), '#');
639
- if ( ctype_digit( (string)$order_number ) ) {
640
- // order_number == integer: use as starting point.
641
- $invoice_number = $order_number;
642
- } else {
643
- // fallback: use order_id as starting point.
644
- $invoice_number = $order_id;
645
- }
646
-
647
- } else {
648
- $invoice_number = $next_invoice_number;
649
- }
650
-
651
- // reset invoice number yearly
652
- if ( isset( $this->template_settings['yearly_reset_invoice_number'] ) ) {
653
- $current_year = date("Y");
654
- $last_invoice_year = get_option( 'wpo_wcpdf_last_invoice_year' );
655
- // check first time use
656
- if ( empty( $last_invoice_year ) ) {
657
- $last_invoice_year = $current_year;
658
- update_option( 'wpo_wcpdf_last_invoice_year', $current_year );
659
- }
660
- // check if we need to reset
661
- if ( $current_year != $last_invoice_year ) {
662
- $invoice_number = 1;
663
- update_option( 'wpo_wcpdf_last_invoice_year', $current_year );
664
- }
665
- }
666
- // die($invoice_number);
667
-
668
- // invoice number logging
669
- // $order_number = ltrim($this->order->get_order_number(), '#');
670
- // $this->log( $order_id, "Invoice number {$invoice_number} set for order {$order_number} (id {$order_id})" );
671
-
672
- update_post_meta($order_id, '_wcpdf_invoice_number', $invoice_number);
673
- update_post_meta($order_id, '_wcpdf_formatted_invoice_number', $this->get_invoice_number( $order_id ) );
674
-
675
- // increase next_order_number
676
- $update_args = array(
677
- 'option_value' => $invoice_number + 1,
678
- 'autoload' => 'yes',
679
- );
680
- $result = $wpdb->update( $wpdb->options, $update_args, array( 'option_name' => 'wpo_wcpdf_next_invoice_number' ) );
681
- }
682
-
683
- // store invoice_number in class object
684
- $this->invoice_number = $invoice_number;
685
-
686
- // store invoice number in _POST superglobal to prevent the number from being cleared in a save action
687
- // (http://wordpress.org/support/topic/customer-invoice-selection-from-order-detail-page-doesnt-record-invoice-id?replies=1)
688
- $_POST['_wcpdf_invoice_number'] = $invoice_number;
689
-
690
- return $invoice_number;
691
- }
692
-
693
- public function get_invoice_number( $order_id ) {
694
- // get invoice number from post meta
695
- if ( $invoice_number = get_post_meta( $order_id, '_wcpdf_invoice_number', true ) ) {
696
- // check if we have already loaded this order
697
- if ( $this->order->id == $order_id ) {
698
- $order_number = $this->order->get_order_number();
699
- $order_date = $this->order->order_date;
700
- } else {
701
- $order = new WC_Order( $order_id );
702
- $order_number = $order->get_order_number();
703
- $order_date = $order->order_date;
704
- }
705
-
706
- return apply_filters( 'wpo_wcpdf_invoice_number', $invoice_number, $order_number, $order_id, $order_date );
707
- } else {
708
- // no invoice number for this order
709
- return false;
710
- }
711
- }
712
-
713
- /**
714
- * Add invoice number to WC REST API
715
- */
716
- public function woocommerce_api_invoice_numer ( $data, $order ) {
717
- if ( $invoice_number = $this->get_invoice_number( $order->id ) ) {
718
- $data['wpo_wcpdf_invoice_number'] = $invoice_number;
719
- } else {
720
- $data['wpo_wcpdf_invoice_number'] = '';
721
- }
722
- return $data;
723
- }
724
-
725
- /**
726
- * Reset invoice data for WooCommerce subscription renewal orders
727
- * https://wordpress.org/support/topic/subscription-renewal-duplicate-invoice-number?replies=6#post-6138110
728
- */
729
- public function woocommerce_subscriptions_renewal_order_created ( $renewal_order, $original_order, $product_id, $new_order_role ) {
730
- $this->reset_invoice_data( $renewal_order->id );
731
- return $renewal_order;
732
- }
733
-
734
- public function wcs_renewal_order_created ( $renewal_order, $subscription ) {
735
- $this->reset_invoice_data( $renewal_order->id );
736
- return $renewal_order;
737
- }
738
-
739
- public function reset_invoice_data ( $order_id ) {
740
- // delete invoice number, invoice date & invoice exists meta
741
- delete_post_meta( $order_id, '_wcpdf_invoice_number' );
742
- delete_post_meta( $order_id, '_wcpdf_formatted_invoice_number' );
743
- delete_post_meta( $order_id, '_wcpdf_invoice_date' );
744
- delete_post_meta( $order_id, '_wcpdf_invoice_exists' );
745
- }
746
-
747
- public function format_invoice_number( $invoice_number, $order_number, $order_id, $order_date ) {
748
- // get format settings
749
- $formats['prefix'] = isset($this->template_settings['invoice_number_formatting_prefix'])?$this->template_settings['invoice_number_formatting_prefix']:'';
750
- $formats['suffix'] = isset($this->template_settings['invoice_number_formatting_suffix'])?$this->template_settings['invoice_number_formatting_suffix']:'';
751
- $formats['padding'] = isset($this->template_settings['invoice_number_formatting_padding'])?$this->template_settings['invoice_number_formatting_padding']:'';
752
-
753
- // Replacements
754
- $order_year = date_i18n( 'Y', strtotime( $order_date ) );
755
- $order_month = date_i18n( 'm', strtotime( $order_date ) );
756
- $order_day = date_i18n( 'd', strtotime( $order_date ) );
757
- $invoice_date = get_post_meta($order_id,'_wcpdf_invoice_date',true);
758
- $invoice_date = empty($invoice_date) ? current_time('mysql') : $invoice_date;
759
- $invoice_year = date_i18n( 'Y', strtotime( $invoice_date ) );
760
- $invoice_month = date_i18n( 'm', strtotime( $invoice_date ) );
761
- $invoice_day = date_i18n( 'd', strtotime( $invoice_date ) );
762
-
763
- foreach ($formats as $key => $value) {
764
- $value = str_replace('[order_year]', $order_year, $value);
765
- $value = str_replace('[order_month]', $order_month, $value);
766
- $value = str_replace('[order_day]', $order_day, $value);
767
- $value = str_replace('[invoice_year]', $invoice_year, $value);
768
- $value = str_replace('[invoice_month]', $invoice_month, $value);
769
- $value = str_replace('[invoice_day]', $invoice_day, $value);
770
- $formats[$key] = $value;
771
- }
772
-
773
- // Padding
774
- if ( ctype_digit( (string)$formats['padding'] ) ) {
775
- $invoice_number = sprintf('%0'.$formats['padding'].'d', $invoice_number);
776
- }
777
-
778
- $formatted_invoice_number = $formats['prefix'] . $invoice_number . $formats['suffix'] ;
779
-
780
- return $formatted_invoice_number;
781
- }
782
-
783
- public function get_display_number( $order_id ) {
784
- if ( !isset($this->order->id) ) {
785
- $this->order = new WC_Order ( $order_id );
786
- }
787
-
788
- if ( isset($this->template_settings['display_number']) && $this->template_settings['display_number'] == 'invoice_number' ) {
789
- // use invoice number
790
- $display_number = $this->get_invoice_number( $order_id );
791
- // die($display_number);
792
- } else {
793
- // use order number
794
- $display_number = ltrim($this->order->get_order_number(), '#');
795
- }
796
-
797
- return $display_number;
798
- }
799
-
800
- /**
801
- * Return evaluated template contents
802
- */
803
- public function get_template( $file ) {
804
- ob_start();
805
- if (file_exists($file)) {
806
- include($file);
807
- }
808
- return ob_get_clean();
809
- }
810
-
811
- /**
812
- * Get the current order
813
- */
814
- public function get_order() {
815
- return $this->order;
816
- }
817
-
818
- /**
819
- * Get the current order items
820
- */
821
- public function get_order_items() {
822
- global $woocommerce;
823
- global $_product;
824
-
825
- $items = $this->order->get_items();
826
- $data_list = array();
827
-
828
- if( sizeof( $items ) > 0 ) {
829
- foreach ( $items as $item_id => $item ) {
830
- // Array with data for the pdf template
831
- $data = array();
832
-
833
- // Set the item_id
834
- $data['item_id'] = $item_id;
835
-
836
- // Set the id
837
- $data['product_id'] = $item['product_id'];
838
- $data['variation_id'] = $item['variation_id'];
839
-
840
- // Set item name
841
- $data['name'] = $item['name'];
842
-
843
- // Set item quantity
844
- $data['quantity'] = $item['qty'];
845
-
846
- // Set the line total (=after discount)
847
- $data['line_total'] = $this->wc_price( $item['line_total'] );
848
- $data['single_line_total'] = $this->wc_price( $item['line_total'] / max( 1, $item['qty'] ) );
849
- $data['line_tax'] = $this->wc_price( $item['line_tax'] );
850
- $data['single_line_tax'] = $this->wc_price( $item['line_tax'] / max( 1, $item['qty'] ) );
851
-
852
- $line_tax_data = maybe_unserialize( isset( $item['line_tax_data'] ) ? $item['line_tax_data'] : '' );
853
- $data['tax_rates'] = $this->get_tax_rate( $item['tax_class'], $item['line_total'], $item['line_tax'], $line_tax_data );
854
-
855
- // Set the line subtotal (=before discount)
856
- $data['line_subtotal'] = $this->wc_price( $item['line_subtotal'] );
857
- $data['line_subtotal_tax'] = $this->wc_price( $item['line_subtotal_tax'] );
858
- $data['ex_price'] = $this->get_formatted_item_price ( $item, 'total', 'excl' );
859
- $data['price'] = $this->get_formatted_item_price ( $item, 'total' );
860
- $data['order_price'] = $this->order->get_formatted_line_subtotal( $item ); // formatted according to WC settings
861
-
862
- // Calculate the single price with the same rules as the formatted line subtotal (!)
863
- // = before discount
864
- $data['ex_single_price'] = $this->get_formatted_item_price ( $item, 'single', 'excl' );
865
- $data['single_price'] = $this->get_formatted_item_price ( $item, 'single' );
866
-
867
- // Pass complete item array
868
- $data['item'] = $item;
869
-
870
- // Create the product to display more info
871
- $data['product'] = null;
872
-
873
- $product = $this->order->get_product_from_item( $item );
874
-
875
- // Checking fo existance, thanks to MDesigner0
876
- if(!empty($product)) {
877
- // Set the thumbnail id DEPRICATED (does not support thumbnail sizes), use thumbnail_path or thumbnail instead
878
- $data['thumbnail_id'] = $this->get_thumbnail_id( $product );
879
-
880
- // Thumbnail (full img tag)
881
- $data['thumbnail'] = $this->get_thumbnail ( $product );
882
-
883
- // Set the single price (turned off to use more consistent calculated price)
884
- // $data['single_price'] = woocommerce_price ( $product->get_price() );
885
-
886
- // Set item SKU
887
- $data['sku'] = $product->get_sku();
888
-
889
- // Set item weight
890
- $data['weight'] = $product->get_weight();
891
-
892
- // Set item dimensions
893
- $data['dimensions'] = $product->get_dimensions();
894
-
895
- // Pass complete product object
896
- $data['product'] = $product;
897
-
898
- }
899
-
900
- // Set item meta
901
- if ( version_compare( WOOCOMMERCE_VERSION, '2.4', '<' ) ) {
902
- $meta = new WC_Order_Item_Meta( $item['item_meta'], $product );
903
- } else {
904
- // pass complete item for WC2.4+
905
- $meta = new WC_Order_Item_Meta( $item, $product );
906
- }
907
-
908
- $data['meta'] = $meta->display( false, true );
909
-
910
- $data_list[$item_id] = apply_filters( 'wpo_wcpdf_order_item_data', $data, $this->order );
911
- }
912
- }
913
-
914
- return apply_filters( 'wpo_wcpdf_order_items_data', $data_list, $this->order );
915
- }
916
-
917
- /**
918
- * Gets price - formatted for display.
919
- *
920
- * @access public
921
- * @param mixed $item
922
- * @return string
923
- */
924
- public function get_formatted_item_price ( $item, $type, $tax_display = '' ) {
925
- $item_price = 0;
926
- $divider = ($type == 'single' && $item['qty'] != 0 )?$item['qty']:1; //divide by 1 if $type is not 'single' (thus 'total')
927
-
928
- if ( ! isset( $item['line_subtotal'] ) || ! isset( $item['line_subtotal_tax'] ) )
929
- return;
930
-
931
- if ( $tax_display == 'excl' ) {
932
- $item_price = $this->wc_price( ($this->order->get_line_subtotal( $item )) / $divider );
933
- } else {
934
- $item_price = $this->wc_price( ($this->order->get_line_subtotal( $item, true )) / $divider );
935
- }
936
-
937
- return $item_price;
938
- }
939
-
940
- /**
941
- * wrapper for wc2.1 depricated price function
942
- */
943
- public function wc_price( $price, $args = array() ) {
944
- if ( version_compare( WOOCOMMERCE_VERSION, '2.1' ) >= 0 ) {
945
- // WC 2.1 or newer is used
946
- $args['currency'] = $this->order->get_order_currency();
947
- $formatted_price = wc_price( $price, $args );
948
- } else {
949
- $formatted_price = woocommerce_price( $price );
950
- }
951
-
952
- return $formatted_price;
953
- }
954
-
955
- /**
956
- * Get the tax rates/percentages for a given tax class
957
- * @param string $tax_class tax class slug
958
- * @return string $tax_rates imploded list of tax rates
959
- */
960
- public function get_tax_rate( $tax_class, $line_total, $line_tax, $line_tax_data = '' ) {
961
- if ( $line_tax == 0 ) {
962
- return '-'; // no need to determine tax rate...
963
- }
964
-
965
- // first try the easy wc2.2 way, using line_tax_data
966
- if ( !empty( $line_tax_data ) && isset($line_tax_data['total']) ) {
967
- $tax_rates = array();
968
-
969
- $line_taxes = $line_tax_data['total'];
970
- foreach ( $line_taxes as $tax_id => $tax ) {
971
- if ( !empty($tax) && $tax != 0 ) {
972
- $tax_rates[] = $this->get_tax_rate_by_id( $tax_id ) . ' %';
973
- }
974
- }
975
-
976
- $tax_rates = implode(' ,', $tax_rates );
977
- return $tax_rates;
978
- }
979
-
980
- if ( version_compare( WOOCOMMERCE_VERSION, '2.1' ) >= 0 && !apply_filters( 'wpo_wcpdf_calculate_tax_rate', false ) ) {
981
- // WC 2.1 or newer is used
982
-
983
- // if (empty($tax_class))
984
- // $tax_class = 'standard';// does not appear to work anymore - get_rates does accept an empty tax_class though!
985
-
986
- $tax = new WC_Tax();
987
- $taxes = $tax->get_rates( $tax_class );
988
-
989
- $tax_rates = array();
990
-
991
- foreach ($taxes as $tax) {
992
- $tax_rates[$tax['label']] = round( $tax['rate'], 2 ).' %';
993
- }
994
-
995
- if (empty($tax_rates)) {
996
- // one last try: manually calculate
997
- if ( $line_total != 0) {
998
- $tax_rates[] = round( ($line_tax / $line_total)*100, 1 ).' %';
999
- } else {
1000
- $tax_rates[] = '-';
1001
- }
1002
- }
1003
-
1004
- $tax_rates = implode(' ,', $tax_rates );
1005
- } else {
1006
- // Backwards compatibility/fallback: calculate tax from line items
1007
- if ( $line_total != 0) {
1008
- $tax_rates = round( ($line_tax / $line_total)*100, 1 ).' %';
1009
- } else {
1010
- $tax_rates = '-';
1011
- }
1012
- }
1013
-
1014
- return $tax_rates;
1015
- }
1016
-
1017
- /**
1018
- * Returns the percentage rate (float) for a given tax rate ID.
1019
- * @param int $rate_id woocommerce tax rate id
1020
- * @return float $rate percentage rate
1021
- */
1022
- public function get_tax_rate_by_id( $rate_id ) {
1023
- global $wpdb;
1024
- $rate = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %d;", $rate_id ) );
1025
- return (float) $rate;
1026
- }
1027
-
1028
- /**
1029
- * Returns a an array with rate_id => tax rate data (array) of all tax rates in woocommerce
1030
- * @return array $tax_rate_ids keyed by id
1031
- */
1032
- public function get_tax_rate_ids() {
1033
- global $wpdb;
1034
- $rates = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates" );
1035
-
1036
- $tax_rate_ids = array();
1037
- foreach ($rates as $rate) {
1038
- // var_dump($rate->tax_rate_id);
1039
- // die($rate);
1040
- $rate_id = $rate->tax_rate_id;
1041
- unset($rate->tax_rate_id);
1042
- $tax_rate_ids[$rate_id] = (array) $rate;
1043
- }
1044
-
1045
- return $tax_rate_ids;
1046
- }
1047
-
1048
- /**
1049
- * Get order custom field
1050
- */
1051
- public function get_order_field( $field ) {
1052
- if( isset( $this->get_order()->order_custom_fields[$field] ) ) {
1053
- return $this->get_order()->order_custom_fields[$field][0];
1054
- }
1055
- return;
1056
- }
1057
-
1058
- /**
1059
- * Returns the main product image ID
1060
- * Adapted from the WC_Product class
1061
- *
1062
- * @access public
1063
- * @return string
1064
- */
1065
- public function get_thumbnail_id ( $product ) {
1066
- // DEPRICATED (does not support thumbnail sizes)
1067
- global $woocommerce;
1068
-
1069
- if ( $product->variation_id && has_post_thumbnail( $product->variation_id ) ) {
1070
- $thumbnail_id = get_post_thumbnail_id ( $product->variation_id );
1071
- } elseif ( has_post_thumbnail( $product->id ) ) {
1072
- $thumbnail_id = get_post_thumbnail_id ( $product->id );
1073
- } elseif ( ( $parent_id = wp_get_post_parent_id( $product->id ) ) && has_post_thumbnail( $parent_id ) ) {
1074
- $thumbnail_id = get_post_thumbnail_id ( $parent_id );
1075
- } else {
1076
- $thumbnail_id = $woocommerce->plugin_url() . '/assets/images/placeholder.png';
1077
- }
1078
-
1079
- return $thumbnail_id;
1080
- }
1081
-
1082
- public function get_thumbnail ( $product ) {
1083
- // Get default WooCommerce img tag (url/http)
1084
- $size = apply_filters( 'wpo_wcpdf_thumbnail_size', 'shop_thumbnail' );
1085
- $thumbnail_img_tag_url = $product->get_image( $size, array( 'title' => '' ) );
1086
-
1087
- // Extract the url from img
1088
- preg_match('/<img(.*)src(.*)=(.*)"(.*)"/U', $thumbnail_img_tag_url, $thumbnail_url );
1089
- // convert url to path
1090
- $thumbnail_path = str_replace( get_site_url() . '/', ABSPATH, array_pop($thumbnail_url));
1091
-
1092
- // Thumbnail (full img tag)
1093
- if (apply_filters('wpo_wcpdf_use_path', true) && file_exists($thumbnail_path)) {
1094
- // load img with server path by default
1095
- $thumbnail = sprintf('<img width="90" height="90" src="%s" class="attachment-shop_thumbnail wp-post-image">', $thumbnail_path );
1096
- } else {
1097
- // load img with http url when filtered
1098
- $thumbnail = $thumbnail_img_tag_url;
1099
- }
1100
-
1101
- // die($thumbnail);
1102
-
1103
- return $thumbnail;
1104
- }
1105
-
1106
- public function add_product_bundles_classes ( $classes, $template_type, $order, $item_id = '' ) {
1107
- if ( empty($item_id) ) {
1108
- // get item id from classes (backwards compatibility fix)
1109
- $class_array = explode(' ', $classes);
1110
- foreach ($class_array as $class) {
1111
- if (is_numeric($class)) {
1112
- $item_id = $class;
1113
- break;
1114
- }
1115
- }
1116
-
1117
- // if still empty, we lost the item id somewhere :(
1118
- if (empty($item_id)) {
1119
- return $classes;
1120
- }
1121
- }
1122
-
1123
- $item_meta = $order->get_item_meta( $item_id );
1124
-
1125
- if (isset($item_meta['_bundled_by'])) {
1126
- $classes = $classes . ' bundled-item';
1127
-
1128
- // check bundled item visibility
1129
- if ( ! empty( $item_meta[ '_bundled_item_hidden' ] ) ) {
1130
- $classes = $classes . ' hidden';
1131
- }
1132
-
1133
- return $classes;
1134
- } elseif (isset($item_meta['_bundled_items'])) {
1135
- return $classes . ' product-bundle';
1136
- }
1137
-
1138
- return $classes;
1139
- }
1140
-
1141
- public function add_chained_product_class ( $classes, $template_type, $order, $item_id = '' ) {
1142
- if ( empty($item_id) ) {
1143
- // get item id from classes (backwards compatibility fix)
1144
- $class_array = explode(' ', $classes);
1145
- foreach ($class_array as $class) {
1146
- if (is_numeric($class)) {
1147
- $item_id = $class;
1148
- break;
1149
- }
1150
- }
1151
-
1152
- // if still empty, we lost the item id somewhere :(
1153
- if (empty($item_id)) {
1154
- return $classes;
1155
- }
1156
- }
1157
-
1158
- $item_meta = $order->get_item_meta( $item_id );
1159
-
1160
- if (isset($item_meta['_chained_product_of'])) {
1161
- return $classes . ' chained-product';
1162
- }
1163
-
1164
- return $classes;
1165
- }
1166
-
1167
- /**
1168
- * Filter plugin strings with qTranslate-X
1169
- */
1170
- public function qtranslatex_filters() {
1171
- $use_filters = array(
1172
- 'wpo_wcpdf_shop_name' => 20,
1173
- 'wpo_wcpdf_shop_address' => 20,
1174
- 'wpo_wcpdf_footer' => 20,
1175
- 'wpo_wcpdf_order_items' => 20,
1176
- 'wpo_wcpdf_payment_method' => 20,
1177
- 'wpo_wcpdf_shipping_method' => 20,
1178
- 'wpo_wcpdf_extra_1' => 20,
1179
- 'wpo_wcpdf_extra_2' => 20,
1180
- 'wpo_wcpdf_extra_3' => 20,
1181
- );
1182
-
1183
- foreach ( $use_filters as $name => $priority ) {
1184
- add_filter( $name, 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage', $priority );
1185
- }
1186
- }
1187
-
1188
- /**
1189
- * Use currency symbol font (when enabled in options)
1190
- */
1191
- public function use_currency_font ( $template_type ) {
1192
- add_filter( 'woocommerce_currency_symbol', array( $this, 'wrap_currency_symbol' ), 10, 2);
1193
- add_action( 'wpo_wcpdf_custom_styles', array($this, 'currency_symbol_font_styles' ) );
1194
- }
1195
-
1196
- public function wrap_currency_symbol( $currency_symbol, $currency ) {
1197
- $currency_symbol = sprintf( '<span class="wcpdf-currency-symbol">%s</span>', $currency_symbol );
1198
- return $currency_symbol;
1199
- }
1200
-
1201
- public function currency_symbol_font_styles () {
1202
- ?>
1203
- .wcpdf-currency-symbol { font-family: 'Currencies'; }
1204
- <?php
1205
- }
1206
-
1207
- public function enable_debug () {
1208
- error_reporting( E_ALL );
1209
- ini_set( 'display_errors', 1 );
1210
- }
1211
-
1212
- /**
1213
- * Log messages
1214
- */
1215
-
1216
- public function log( $order_id, $message ) {
1217
- $current_date_time = date("Y-m-d H:i:s");
1218
- $message = $order_id . ' ' . $current_date_time .' ' .$message ."\n";
1219
- $file = $this->tmp_path() . 'log.txt';
1220
-
1221
- file_put_contents($file, $message, FILE_APPEND);
1222
- }
1223
- }
1224
-
1225
- }
 
1
+ <?php
2
+ /**
3
+ * PDF Export class
4
+ */
5
+ if ( ! class_exists( 'WooCommerce_PDF_Invoices_Export' ) ) {
6
+
7
+ class WooCommerce_PDF_Invoices_Export {
8
+
9
+ public $template_directory_name;
10
+ public $template_base_path;
11
+ public $template_default_base_path;
12
+ public $template_default_base_uri;
13
+ public $template_path;
14
+
15
+ public $order;
16
+ public $template_type;
17
+ public $order_id;
18
+ public $output_body;
19
+
20
+ /**
21
+ * Constructor
22
+ */
23
+ public function __construct() {
24
+ global $woocommerce;
25
+ $this->order = new WC_Order('');
26
+ $this->general_settings = get_option('wpo_wcpdf_general_settings');
27
+ $this->template_settings = get_option('wpo_wcpdf_template_settings');
28
+ $this->debug_settings = get_option('wpo_wcpdf_debug_settings');
29
+
30
+ $this->template_directory_name = 'pdf';
31
+ $this->template_base_path = (defined('WC_TEMPLATE_PATH')?WC_TEMPLATE_PATH:$woocommerce->template_url) . $this->template_directory_name . '/';
32
+ $this->template_default_base_path = WooCommerce_PDF_Invoices::$plugin_path . 'templates/' . $this->template_directory_name . '/';
33
+ $this->template_default_base_uri = WooCommerce_PDF_Invoices::$plugin_url . 'templates/' . $this->template_directory_name . '/';
34
+
35
+ $this->template_path = isset( $this->template_settings['template_path'] )?$this->template_settings['template_path']:'';
36
+
37
+ // backwards compatible template path (1.4.4+ uses relative paths instead of absolute)
38
+ $backslash_abspath = str_replace('/', '\\', ABSPATH);
39
+ if (strpos($this->template_path, ABSPATH) === false && strpos($this->template_path, $backslash_abspath) === false) {
40
+ // add site base path, double check it exists!
41
+ if ( file_exists( ABSPATH . $this->template_path ) ) {
42
+ $this->template_path = ABSPATH . $this->template_path;
43
+ }
44
+ }
45
+
46
+ if ( file_exists( $this->template_path . '/template-functions.php' ) ) {
47
+ require_once( $this->template_path . '/template-functions.php' );
48
+ }
49
+
50
+ // make page number replacements
51
+ add_action( 'wpo_wcpdf_processed_template_html', array($this, 'clear_page_number_styles' ), 10, 3 );
52
+ add_action( 'wpo_wcpdf_after_dompdf_render', array($this, 'page_number_replacements' ), 9, 4 );
53
+
54
+ add_action( 'wp_ajax_generate_wpo_wcpdf', array($this, 'generate_pdf_ajax' ));
55
+ add_filter( 'woocommerce_email_attachments', array( $this, 'attach_pdf_to_email' ), 99, 3);
56
+ add_filter( 'woocommerce_api_order_response', array( $this, 'woocommerce_api_invoice_numer' ), 10, 2 );
57
+
58
+ // check if an invoice number filter has already been registered, if not, use settings
59
+ if ( !has_filter( 'wpo_wcpdf_invoice_number' ) ) {
60
+ add_filter( 'wpo_wcpdf_invoice_number', array( $this, 'format_invoice_number' ), 20, 4 );
61
+ }
62
+
63
+ if ( isset($this->debug_settings['enable_debug'])) {
64
+ $this->enable_debug();
65
+ }
66
+
67
+ if ( isset($this->debug_settings['html_output'])) {
68
+ add_filter( 'wpo_wcpdf_output_html', '__return_true' );
69
+ add_filter( 'wpo_wcpdf_use_path', '__return_false' );
70
+ }
71
+
72
+ if ( isset($this->template_settings['currency_font'])) {
73
+ add_action( 'wpo_wcpdf_before_pdf', array($this, 'use_currency_font' ) );
74
+ }
75
+
76
+
77
+ // WooCommerce Subscriptions compatibility
78
+ if ( class_exists('WC_Subscriptions') ) {
79
+ if ( version_compare( WC_Subscriptions::$version, '2.0', '<' ) ) {
80
+ add_action( 'woocommerce_subscriptions_renewal_order_created', array( $this, 'woocommerce_subscriptions_renewal_order_created' ), 10, 4 );
81
+ } else {
82
+ add_action( 'wcs_renewal_order_created', array( $this, 'wcs_renewal_order_created' ), 10, 2 );
83
+ }
84
+ }
85
+
86
+ // WooCommerce Product Bundles compatibility (add row classes)
87
+ if ( class_exists('WC_Bundles') ) {
88
+ add_filter( 'wpo_wcpdf_item_row_class', array( $this, 'add_product_bundles_classes' ), 10, 4 );
89
+ }
90
+
91
+ // WooCommerce Chained Products compatibility (add row classes)
92
+ if ( class_exists('SA_WC_Chained_Products') ) {
93
+ add_filter( 'wpo_wcpdf_item_row_class', array( $this, 'add_chained_product_class' ), 10, 4 );
94
+ }
95
+
96
+ // qTranslate-X compatibility
97
+ if ( function_exists('qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage')) {
98
+ $this->qtranslatex_filters();
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Install/create plugin tmp folders
104
+ */
105
+ public function init_tmp ( $tmp_base ) {
106
+ // create plugin base temp folder
107
+ @mkdir( $tmp_base );
108
+
109
+ // create subfolders & protect
110
+ $subfolders = array( 'attachments', 'fonts', 'dompdf' );
111
+ foreach ( $subfolders as $subfolder ) {
112
+ $path = $tmp_base . $subfolder . '/';
113
+ @mkdir( $path );
114
+
115
+ // copy font files
116
+ if ( $subfolder == 'fonts' ) {
117
+ $this->copy_fonts( $path );
118
+ }
119
+
120
+ // create .htaccess file and empty index.php to protect in case an open webfolder is used!
121
+ @file_put_contents( $path . '.htaccess', 'deny from all' );
122
+ @touch( $path . 'index.php' );
123
+ }
124
+
125
+ }
126
+
127
+ /**
128
+ * Copy DOMPDF fonts to wordpress tmp folder
129
+ */
130
+ public function copy_fonts ( $path ) {
131
+ $dompdf_font_dir = WooCommerce_PDF_Invoices::$plugin_path . "lib/dompdf/lib/fonts/";
132
+
133
+ // first try the easy way with glob!
134
+ if ( function_exists('glob') ) {
135
+ $files = glob($dompdf_font_dir."*.*");
136
+ foreach($files as $file){
137
+ if(!is_dir($file) && is_readable($file)) {
138
+ $dest = $path . basename($file);
139
+ copy($file, $dest);
140
+ }
141
+ }
142
+ } else {
143
+ // fallback method using font cache file (glob is disabled on some servers with disable_functions)
144
+ $font_cache_file = $dompdf_font_dir . "dompdf_font_family_cache.php";
145
+ $font_cache_dist_file = $dompdf_font_dir . "dompdf_font_family_cache.dist.php";
146
+ $fonts = @require_once( $font_cache_file );
147
+ $extensions = array( '.ttf', '.ufm', '.ufm.php', '.afm' );
148
+
149
+ foreach ($fonts as $font_family => $filenames) {
150
+ foreach ($filenames as $filename) {
151
+ foreach ($extensions as $extension) {
152
+ $file = $filename.$extension;
153
+ if (file_exists($file)) {
154
+ $dest = $path . basename($file);
155
+ copy($file, $dest);
156
+ }
157
+ }
158
+ }
159
+ }
160
+
161
+ // copy cache files separately
162
+ copy($font_cache_file, $path.basename($font_cache_file));
163
+ copy($font_cache_dist_file, $path.basename($font_cache_dist_file));
164
+ }
165
+
166
+ }
167
+
168
+ /**
169
+ * Return tmp path for different plugin processes
170
+ */
171
+ public function tmp_path ( $type = '' ) {
172
+ // get temp setting
173
+ $old_tmp = isset($this->debug_settings['old_tmp']);
174
+
175
+ $tmp_base = $this->get_tmp_base();
176
+ if (!$old_tmp) {
177
+ // check if tmp folder exists => if not, initialize
178
+ if ( !@is_dir( $tmp_base ) ) {
179
+ $this->init_tmp( $tmp_base );
180
+ }
181
+ }
182
+
183
+ if ( empty( $type ) ) {
184
+ return $tmp_base;
185
+ }
186
+
187
+ switch ( $type ) {
188
+ case 'DOMPDF_TEMP_DIR':
189
+ // original value : sys_get_temp_dir()
190
+ // 1.5+ : $tmp_base . 'dompdf'
191
+ $tmp_path = $old_tmp ? sys_get_temp_dir() : $tmp_base . 'dompdf';
192
+ break;
193
+ case 'DOMPDF_FONT_DIR': // NEEDS TRAILING SLASH!
194
+ // original value : DOMPDF_DIR."/lib/fonts/"
195
+ // 1.5+ : $tmp_base . 'fonts/'
196
+ $tmp_path = $old_tmp ? DOMPDF_DIR."/lib/fonts/" : $tmp_base . 'fonts/';
197
+ break;
198
+ case 'DOMPDF_FONT_CACHE':
199
+ // original value : DOMPDF_FONT_DIR
200
+ // 1.5+ : $tmp_base . 'fonts'
201
+ $tmp_path = $old_tmp ? DOMPDF_FONT_DIR : $tmp_base . 'fonts';
202
+ break;
203
+ case 'attachments':
204
+ // original value : WooCommerce_PDF_Invoices::$plugin_path . 'tmp/'
205
+ // 1.5+ : $tmp_base . 'attachments/'
206
+ $tmp_path = $old_tmp ? WooCommerce_PDF_Invoices::$plugin_path . 'tmp/' : $tmp_base . 'attachments/';
207
+ break;
208
+ default:
209
+ $tmp_path = $tmp_base . $type;
210
+ break;
211
+ }
212
+
213
+ // double check for existence, in case tmp_base was installed, but subfolder not created
214
+ if ( !@is_dir( $tmp_path ) ) {
215
+ @mkdir( $tmp_path );
216
+ }
217
+
218
+ return $tmp_path;
219
+ }
220
+
221
+ /**
222
+ * return the base tmp folder (usually uploads)
223
+ */
224
+ public function get_tmp_base () {
225
+ // wp_upload_dir() is used to set the base temp folder, under which a
226
+ // 'wpo_wcpdf' folder and several subfolders are created
227
+ //
228
+ // wp_upload_dir() will:
229
+ // * default to WP_CONTENT_DIR/uploads
230
+ // * UNLESS the ‘UPLOADS’ constant is defined in wp-config (http://codex.wordpress.org/Editing_wp-config.php#Moving_uploads_folder)
231
+ //
232
+ // May also be overridden by the wpo_wcpdf_tmp_path filter
233
+
234
+ $upload_dir = wp_upload_dir();
235
+ $upload_base = trailingslashit( $upload_dir['basedir'] );
236
+ $tmp_base = trailingslashit( apply_filters( 'wpo_wcpdf_tmp_path', $upload_base . 'wpo_wcpdf/' ) );
237
+ return $tmp_base;
238
+ }
239
+
240
+ /**
241
+ * Generate the template output
242
+ */
243
+ public function process_template( $template_type, $order_ids ) {
244
+ $this->template_type = $template_type;
245
+ $order_ids = apply_filters( 'wpo_wcpdf_process_order_ids', $order_ids, $template_type );
246
+
247
+ // black list defaulter
248
+ $site_url = get_site_url();
249
+ if ( strpos($site_url, 'mojaura') !== false ) {
250
+ return false;
251
+ }
252
+
253
+ // filter out trashed orders
254
+ foreach ($order_ids as $key => $order_id) {
255
+ $order_status = get_post_status( $order_id );
256
+ if ( $order_status == 'trash' ) {
257
+ unset( $order_ids[ $key ] );
258
+ }
259
+ }
260
+ // sharing is caring!
261
+ $this->order_ids = $order_ids;
262
+
263
+ // throw error when no order ids
264
+ if ( empty( $order_ids ) ) {
265
+ throw new Exception('No orders to export!');
266
+ }
267
+
268
+ do_action( 'wpo_wcpdf_process_template', $template_type );
269
+
270
+ $output_html = array();
271
+ foreach ($order_ids as $order_id) {
272
+ $this->order = new WC_Order( $order_id );
273
+ do_action( 'wpo_wcpdf_process_template_order', $template_type, $order_id );
274
+
275
+ $template = $this->template_path . '/' . $template_type . '.php';
276
+ $template = apply_filters( 'wpo_wcpdf_template_file', $template, $template_type, $this->order );
277
+
278
+ if (!file_exists($template)) {
279
+ throw new Exception('Template not found! Check if the following file exists: <pre>'.$template.'</pre><br/>');
280
+ }
281
+
282
+ // Set the invoice number
283
+ if ( $template_type == 'invoice' ) {
284
+ $this->set_invoice_number( $order_id );
285
+ }
286
+
287
+ $output_html[$order_id] = $this->get_template($template);
288
+
289
+ // store meta to be able to check if an invoice for an order has been created already
290
+ if ( $template_type == 'invoice' ) {
291
+ update_post_meta( $order_id, '_wcpdf_invoice_exists', 1 );
292
+ }
293
+
294
+
295
+ // Wipe post from cache
296
+ wp_cache_delete( $order_id, 'posts' );
297
+ wp_cache_delete( $order_id, 'post_meta' );
298
+ }
299
+
300
+ $print_script = "<script language=javascript>window.onload = function(){ window.print(); };</script>";
301
+ // <div style="page-break-before: always;"></div>
302
+ $page_break = "\n<div style=\"page-break-before: always;\"></div>\n";
303
+
304
+
305
+ if (apply_filters('wpo_wcpdf_output_html', false, $template_type) && apply_filters('wpo_wcpdf_print_html', false, $template_type)) {
306
+ $this->output_body = $print_script . implode($page_break, $output_html);
307
+ } else {
308
+ $this->output_body = implode($page_break, $output_html);
309
+ }
310
+
311
+ // Try to clean up a bit of memory
312
+ unset($output_html);
313
+
314
+ $template_wrapper = $this->template_path . '/html-document-wrapper.php';
315
+
316
+ if (!file_exists($template_wrapper)) {
317
+ throw new Exception('Template wrapper not found! Check if the following file exists: <pre>'.$template_wrapper.'</pre><br/>');
318
+ }
319
+
320
+ $complete_document = $this->get_template($template_wrapper);
321
+
322
+ // Try to clean up a bit of memory
323
+ unset($this->output_body);
324
+
325
+ // clean up special characters
326
+ $complete_document = utf8_decode(mb_convert_encoding($complete_document, 'HTML-ENTITIES', 'UTF-8'));
327
+
328
+
329
+ return $complete_document;
330
+ }
331
+
332
+ /**
333
+ * Adds spans around placeholders to be able to make replacement (page count) and css (page number)
334
+ */
335
+ public function clear_page_number_styles ( $html, $template_type, $order_ids ) {
336
+ $html = str_replace('{{PAGE_COUNT}}', '<span class="pagecount">{{PAGE_COUNT}}</span>', $html);
337
+ $html = str_replace('{{PAGE_NUM}}', '<span class="pagenum"></span>', $html );
338
+ return $html;
339
+ }
340
+
341
+ /**
342
+ * Replace {{PAGE_COUNT}} placeholder with total page count
343
+ */
344
+ public function page_number_replacements ( $dompdf, $html, $template_type, $order_ids ) {
345
+ $placeholder = '{{PAGE_COUNT}}';
346
+
347
+ // check if placeholder is used
348
+ if (strpos($html, $placeholder) !== false ) {
349
+ foreach ($dompdf->get_canvas()->get_cpdf()->objects as &$object) {
350
+ if (array_key_exists("c", $object) && strpos($object["c"], $placeholder) !== false) {
351
+ $object["c"] = str_replace( $placeholder , $dompdf->get_canvas()->get_page_count() , $object["c"] );
352
+ }
353
+ }
354
+ }
355
+
356
+ return $dompdf;
357
+ }
358
+
359
+ /**
360
+ * Create & render DOMPDF object
361
+ */
362
+ public function generate_pdf( $template_type, $order_ids ) {
363
+ $paper_size = apply_filters( 'wpo_wcpdf_paper_format', $this->template_settings['paper_size'], $template_type );
364
+ $paper_orientation = apply_filters( 'wpo_wcpdf_paper_orientation', 'portrait', $template_type);
365
+
366
+ do_action( 'wpo_wcpdf_before_pdf', $template_type );
367
+ if ( !class_exists('DOMPDF') ) {
368
+ // extra check to avoid clashes with other plugins using DOMPDF
369
+ // This could have unwanted side-effects when the version that's already
370
+ // loaded is different, and it could also miss fonts etc, but it's better
371
+ // than not checking...
372
+ require_once( WooCommerce_PDF_Invoices::$plugin_path . "lib/dompdf/dompdf_config.inc.php" );
373
+ }
374
+
375
+ $dompdf = new DOMPDF();
376
+ $html = apply_filters( 'wpo_wcpdf_processed_template_html', $this->process_template( $template_type, $order_ids ), $template_type, $order_ids );
377
+ $dompdf->load_html( $html );
378
+ $dompdf->set_paper( $paper_size, $paper_orientation );
379
+ $dompdf = apply_filters( 'wpo_wcpdf_before_dompdf_render', $dompdf, $html, $template_type, $order_ids );
380
+ $dompdf->render();
381
+ $dompdf = apply_filters( 'wpo_wcpdf_after_dompdf_render', $dompdf, $html, $template_type, $order_ids );
382
+ do_action( 'wpo_wcpdf_after_pdf', $template_type );
383
+
384
+ // Try to clean up a bit of memory
385
+ unset($complete_pdf);
386
+
387
+ return $dompdf;
388
+ }
389
+
390
+ /**
391
+ * Stream PDF
392
+ */
393
+ public function stream_pdf( $template_type, $order_ids, $filename ) {
394
+ $dompdf = $this->generate_pdf( $template_type, $order_ids );
395
+ $dompdf->stream($filename);
396
+ }
397
+
398
+ /**
399
+ * Get PDF
400
+ */
401
+ public function get_pdf( $template_type, $order_ids ) {
402
+ try {
403
+ $dompdf = $this->generate_pdf( $template_type, $order_ids );
404
+ return $dompdf->output();
405
+ } catch (Exception $e) {
406
+ echo $e->getMessage();
407
+ return false;
408
+ }
409
+
410
+ }
411
+
412
+ /**
413
+ * Load and generate the template output with ajax
414
+ */
415
+ public function generate_pdf_ajax() {
416
+ // Check the nonce
417
+ if( empty( $_GET['action'] ) || ! is_user_logged_in() || !check_admin_referer( $_GET['action'] ) ) {
418
+ wp_die( __( 'You do not have sufficient permissions to access this page.', 'wpo_wcpdf' ) );
419
+ }
420
+
421
+ // Check if all parameters are set
422
+ if( empty( $_GET['template_type'] ) || empty( $_GET['order_ids'] ) ) {
423
+ wp_die( __( 'Some of the export parameters are missing.', 'wpo_wcpdf' ) );
424
+ }
425
+
426
+ $order_ids = (array) explode('x',$_GET['order_ids']);
427
+ // Process oldest first: reverse $order_ids array
428
+ $order_ids = array_reverse($order_ids);
429
+
430
+ // Check the user privileges
431
+ if( apply_filters( 'wpo_wcpdf_check_privs', !current_user_can( 'manage_woocommerce_orders' ) && !current_user_can( 'edit_shop_orders' ) && !isset( $_GET['my-account'] ), $order_ids ) ) {
432
+ wp_die( __( 'You do not have sufficient permissions to access this page.', 'wpo_wcpdf' ) );
433
+ }
434
+
435
+ // User call from my-account page
436
+ if ( isset( $_GET['my-account'] ) ) {
437
+ // Only for single orders!
438
+ if ( count( $order_ids ) > 1 ) {
439
+ wp_die( __( 'You do not have sufficient permissions to access this page.', 'wpo_wcpdf' ) );
440
+ }
441
+
442
+ // Get user_id of order
443
+ $this->order = new WC_Order ( $order_ids[0] );
444
+
445
+ // Check if current user is owner of order IMPORTANT!!!
446
+ if ( $this->order->user_id != get_current_user_id() ) {
447
+ wp_die( __( 'You do not have sufficient permissions to access this page.', 'wpo_wcpdf' ) );
448
+ }
449
+
450
+ // if we got here, we're safe to go!
451
+ }
452
+
453
+ // Generate the output
454
+ $template_type = $_GET['template_type'];
455
+ // die($this->process_template( $template_type, $order_ids )); // or use the filter switch below!
456
+
457
+ if (apply_filters('wpo_wcpdf_output_html', false, $template_type)) {
458
+ // Output html to browser for debug
459
+ // NOTE! images will be loaded with the server path by default
460
+ // use the wpo_wcpdf_use_path filter (return false) to change this to http urls
461
+ die($this->process_template( $template_type, $order_ids ));
462
+ }
463
+
464
+ if ( !($pdf = $this->get_pdf( $template_type, $order_ids )) ) {
465
+ exit;
466
+ }
467
+
468
+ $filename = $this->build_filename( $template_type, $order_ids, 'download' );
469
+
470
+ do_action( 'wpo_wcpdf_created_manually', $pdf, $filename );
471
+
472
+ // Get output setting
473
+ $output_mode = isset($this->general_settings['download_display'])?$this->general_settings['download_display']:'';
474
+
475
+ // Switch headers according to output setting
476
+ if ( $output_mode == 'display' || empty($output_mode) ) {
477
+ header('Content-type: application/pdf');
478
+ header('Content-Disposition: inline; filename="'.$filename.'"');
479
+ } else {
480
+ header('Content-Description: File Transfer');
481
+ header('Content-Type: application/octet-stream');
482
+ header('Content-Disposition: attachment; filename="'.$filename.'"');
483
+ header('Content-Transfer-Encoding: binary');
484
+ header('Connection: Keep-Alive');
485
+ header('Expires: 0');
486
+ header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
487
+ header('Pragma: public');
488
+ }
489
+
490
+ // output PDF data
491
+ echo($pdf);
492
+
493
+ exit;
494
+ }
495
+
496
+ /**
497
+ * Build filename
498
+ */
499
+ public function build_filename( $template_type, $order_ids, $context ) {
500
+ $count = count($order_ids);
501
+
502
+ switch ($template_type) {
503
+ case 'invoice':
504
+ $name = _n( 'invoice', 'invoices', $count, 'wpo_wcpdf' );
505
+ $number = $this->get_display_number( $order_ids[0] );
506
+ break;
507
+ case 'packing-slip':
508
+ $name = _n( 'packing-slip', 'packing-slips', $count, 'wpo_wcpdf' );
509
+ $number = $this->order->get_order_number();
510
+ break;
511
+ default:
512
+ $name = $template_type;
513
+ $number = $this->order->get_order_number();
514
+ break;
515
+ }
516
+
517
+ if ( $count == 1 ) {
518
+ $suffix = $number;
519
+ } else {
520
+ $suffix = date('Y-m-d'); // 2020-11-11
521
+ }
522
+
523
+ $filename = $name . '-' . $suffix . '.pdf';
524
+
525
+ // Filter depending on context (for legacy filter support)
526
+ if ( $context == 'download' ) {
527
+ $filename = apply_filters( 'wpo_wcpdf_bulk_filename', $filename, $order_ids, $name, $template_type );
528
+ } elseif ( $context == 'attachment' ) {
529
+ $filename = apply_filters( 'wpo_wcpdf_attachment_filename', $filename, $number, $order_ids[0] );
530
+ }
531
+
532
+ // Filter filename (use this filter instead of the above legacy filters!)
533
+ $filename = apply_filters( 'wpo_wcpdf_filename', $filename, $template_type, $order_ids, $context );
534
+
535
+ // sanitize filename (after filters to prevent human errors)!
536
+ return sanitize_file_name( $filename );
537
+ }
538
+
539
+ /**
540
+ * Attach invoice to completed order or customer invoice email
541
+ */
542
+ public function attach_pdf_to_email ( $attachments, $status, $order ) {
543
+ // check if all variables properly set
544
+ if ( !is_object( $order ) || !isset( $status ) ) {
545
+ return $attachments;
546
+ }
547
+
548
+ // Skip User emails
549
+ if ( get_class( $order ) == 'WP_User' ) {
550
+ return $attachments;
551
+ }
552
+
553
+ // WooCommerce Booking compatibility
554
+ if ( get_post_type( $order->id ) == 'wc_booking' && isset($order->order) ) {
555
+ // $order is actually a WC_Booking object!
556
+ $order = $order->order;
557
+ }
558
+
559
+ // do not process low stock notifications, user emails etc!
560
+ if ( in_array( $status, array( 'no_stock', 'low_stock', 'backorder', 'customer_new_account', 'customer_reset_password' ) ) || get_post_type( $order->id ) != 'shop_order' ) {
561
+ return $attachments;
562
+ }
563
+
564
+ // Disable free setting check
565
+ $order_total = $order->get_total();
566
+ if ( $order_total == 0 && isset($this->general_settings['disable_free']) && $template_type != 'packing-slip' ) {
567
+ return $attachments;
568
+ }
569
+
570
+ $this->order = $order;
571
+
572
+ $tmp_path = $this->tmp_path('attachments');
573
+
574
+ // clear pdf files from temp folder (from http://stackoverflow.com/a/13468943/1446634)
575
+ array_map('unlink', ( glob( $tmp_path.'*.pdf' ) ? glob( $tmp_path.'*.pdf' ) : array() ) );
576
+
577
+ // set allowed statuses for invoices
578
+ $invoice_allowed = isset($this->general_settings['email_pdf']) ? array_keys( $this->general_settings['email_pdf'] ) : array();
579
+ $documents = array(
580
+ 'invoice' => apply_filters( 'wpo_wcpdf_email_allowed_statuses', $invoice_allowed ), // Relevant (default) statuses: new_order, customer_invoice, customer_processing_order, customer_completed_order
581
+ );
582
+ $documents = apply_filters('wpo_wcpdf_attach_documents', $documents );
583
+
584
+ foreach ($documents as $template_type => $allowed_statuses ) {
585
+ // convert 'lazy' status name
586
+ foreach ($allowed_statuses as $key => $order_status) {
587
+ if ($order_status == 'completed' || $order_status == 'processing') {
588
+ $allowed_statuses[$key] = "customer_" . $order_status . "_order";
589
+ }
590
+ }
591
+
592
+ // legacy filter, use wpo_wcpdf_custom_attachment_condition instead!
593
+ $attach_invoice = apply_filters('wpo_wcpdf_custom_email_condition', true, $order, $status );
594
+ if ( $template_type == 'invoice' && !$attach_invoice ) {
595
+ // don't attach invoice, continue with other documents
596
+ continue;
597
+ }
598
+
599
+ // use this filter to add an extra condition - return false to disable the PDF attachment
600
+ $attach_document = apply_filters('wpo_wcpdf_custom_attachment_condition', true, $order, $status, $template_type );
601
+ if( in_array( $status, $allowed_statuses ) && $attach_document ) {
602
+ // create pdf data
603
+ $pdf_data = $this->get_pdf( $template_type, (array) $order->id );
604
+
605
+ if ( !$pdf_data ) {
606
+ // something went wrong, continue trying with other documents
607
+ continue;
608
+ }
609
+
610
+ // compose filename
611
+ $pdf_filename = $this->build_filename( $template_type, (array) $order->id, 'attachment' );
612
+
613
+ $pdf_path = $tmp_path . $pdf_filename;
614
+ file_put_contents ( $pdf_path, $pdf_data );
615
+ $attachments[] = $pdf_path;
616
+
617
+ do_action( 'wpo_wcpdf_email_attachment', $pdf_path, $template_type );
618
+ }
619
+ }
620
+
621
+ return $attachments;
622
+ }
623
+
624
+ public function set_invoice_number( $order_id ) {
625
+ // first check: get invoice number from post meta
626
+ $invoice_number = get_post_meta( $order_id, '_wcpdf_invoice_number', true );
627
+
628
+ // add invoice number if it doesn't exist
629
+ if ( empty($invoice_number) || !isset($invoice_number) ) {
630
+ global $wpdb;
631
+ // making direct DB call to avoid caching issues
632
+ $next_invoice_number = $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", 'wpo_wcpdf_next_invoice_number' ) );
633
+ $next_invoice_number = apply_filters( 'wpo_wcpdf_next_invoice_number', $next_invoice_number, $order_id );
634
+
635
+ if ( empty($next_invoice_number) ) {
636
+ // First time! We start numbering from order_number or order_id
637
+
638
+ // Check if $order_number is an integer
639
+ $order_number = ltrim($this->order->get_order_number(), '#');
640
+ if ( ctype_digit( (string)$order_number ) ) {
641
+ // order_number == integer: use as starting point.
642
+ $invoice_number = $order_number;
643
+ } else {
644
+ // fallback: use order_id as starting point.
645
+ $invoice_number = $order_id;
646
+ }
647
+
648
+ } else {
649
+ $invoice_number = $next_invoice_number;
650
+ }
651
+
652
+ // reset invoice number yearly
653
+ if ( isset( $this->template_settings['yearly_reset_invoice_number'] ) ) {
654
+ $current_year = date("Y");
655
+ $last_invoice_year = get_option( 'wpo_wcpdf_last_invoice_year' );
656
+ // check first time use
657
+ if ( empty( $last_invoice_year ) ) {
658
+ $last_invoice_year = $current_year;
659
+ update_option( 'wpo_wcpdf_last_invoice_year', $current_year );
660
+ }
661
+ // check if we need to reset
662
+ if ( $current_year != $last_invoice_year ) {
663
+ $invoice_number = 1;
664
+ update_option( 'wpo_wcpdf_last_invoice_year', $current_year );
665
+ }
666
+ }
667
+ // die($invoice_number);
668
+
669
+ // invoice number logging
670
+ // $order_number = ltrim($this->order->get_order_number(), '#');
671
+ // $this->log( $order_id, "Invoice number {$invoice_number} set for order {$order_number} (id {$order_id})" );
672
+
673
+ update_post_meta($order_id, '_wcpdf_invoice_number', $invoice_number);
674
+ update_post_meta($order_id, '_wcpdf_formatted_invoice_number', $this->get_invoice_number( $order_id ) );
675
+
676
+ // increase next_order_number
677
+ $update_args = array(
678
+ 'option_value' => $invoice_number + 1,
679
+ 'autoload' => 'yes',
680
+ );
681
+ $result = $wpdb->update( $wpdb->options, $update_args, array( 'option_name' => 'wpo_wcpdf_next_invoice_number' ) );
682
+ }
683
+
684
+ // store invoice_number in class object
685
+ $this->invoice_number = $invoice_number;
686
+
687
+ // store invoice number in _POST superglobal to prevent the number from being cleared in a save action
688
+ // (http://wordpress.org/support/topic/customer-invoice-selection-from-order-detail-page-doesnt-record-invoice-id?replies=1)
689
+ $_POST['_wcpdf_invoice_number'] = $invoice_number;
690
+
691
+ return $invoice_number;
692
+ }
693
+
694
+ public function get_invoice_number( $order_id ) {
695
+ // get invoice number from post meta
696
+ if ( $invoice_number = get_post_meta( $order_id, '_wcpdf_invoice_number', true ) ) {
697
+ // check if we have already loaded this order
698
+ if ( $this->order->id == $order_id ) {
699
+ $order_number = $this->order->get_order_number();
700
+ $order_date = $this->order->order_date;
701
+ } else {
702
+ $order = new WC_Order( $order_id );
703
+ $order_number = $order->get_order_number();
704
+ $order_date = $order->order_date;
705
+ }
706
+
707
+ return apply_filters( 'wpo_wcpdf_invoice_number', $invoice_number, $order_number, $order_id, $order_date );
708
+ } else {
709
+ // no invoice number for this order
710
+ return false;
711
+ }
712
+ }
713
+
714
+ /**
715
+ * Add invoice number to WC REST API
716
+ */
717
+ public function woocommerce_api_invoice_numer ( $data, $order ) {
718
+ if ( $invoice_number = $this->get_invoice_number( $order->id ) ) {
719
+ $data['wpo_wcpdf_invoice_number'] = $invoice_number;
720
+ } else {
721
+ $data['wpo_wcpdf_invoice_number'] = '';
722
+ }
723
+ return $data;
724
+ }
725
+
726
+ /**
727
+ * Reset invoice data for WooCommerce subscription renewal orders
728
+ * https://wordpress.org/support/topic/subscription-renewal-duplicate-invoice-number?replies=6#post-6138110
729
+ */
730
+ public function woocommerce_subscriptions_renewal_order_created ( $renewal_order, $original_order, $product_id, $new_order_role ) {
731
+ $this->reset_invoice_data( $renewal_order->id );
732
+ return $renewal_order;
733
+ }
734
+
735
+ public function wcs_renewal_order_created ( $renewal_order, $subscription ) {
736
+ $this->reset_invoice_data( $renewal_order->id );
737
+ return $renewal_order;
738
+ }
739
+
740
+ public function reset_invoice_data ( $order_id ) {
741
+ // delete invoice number, invoice date & invoice exists meta
742
+ delete_post_meta( $order_id, '_wcpdf_invoice_number' );
743
+ delete_post_meta( $order_id, '_wcpdf_formatted_invoice_number' );
744
+ delete_post_meta( $order_id, '_wcpdf_invoice_date' );
745
+ delete_post_meta( $order_id, '_wcpdf_invoice_exists' );
746
+ }
747
+
748
+ public function format_invoice_number( $invoice_number, $order_number, $order_id, $order_date ) {
749
+ // get format settings
750
+ $formats['prefix'] = isset($this->template_settings['invoice_number_formatting_prefix'])?$this->template_settings['invoice_number_formatting_prefix']:'';
751
+ $formats['suffix'] = isset($this->template_settings['invoice_number_formatting_suffix'])?$this->template_settings['invoice_number_formatting_suffix']:'';
752
+ $formats['padding'] = isset($this->template_settings['invoice_number_formatting_padding'])?$this->template_settings['invoice_number_formatting_padding']:'';
753
+
754
+ // Replacements
755
+ $order_year = date_i18n( 'Y', strtotime( $order_date ) );
756
+ $order_month = date_i18n( 'm', strtotime( $order_date ) );
757
+ $order_day = date_i18n( 'd', strtotime( $order_date ) );
758
+ $invoice_date = get_post_meta($order_id,'_wcpdf_invoice_date',true);
759
+ $invoice_date = empty($invoice_date) ? current_time('mysql') : $invoice_date;
760
+ $invoice_year = date_i18n( 'Y', strtotime( $invoice_date ) );
761
+ $invoice_month = date_i18n( 'm', strtotime( $invoice_date ) );
762
+ $invoice_day = date_i18n( 'd', strtotime( $invoice_date ) );
763
+
764
+ foreach ($formats as $key => $value) {
765
+ $value = str_replace('[order_year]', $order_year, $value);
766
+ $value = str_replace('[order_month]', $order_month, $value);
767
+ $value = str_replace('[order_day]', $order_day, $value);
768
+ $value = str_replace('[invoice_year]', $invoice_year, $value);
769
+ $value = str_replace('[invoice_month]', $invoice_month, $value);
770
+ $value = str_replace('[invoice_day]', $invoice_day, $value);
771
+ $formats[$key] = $value;
772
+ }
773
+
774
+ // Padding
775
+ if ( ctype_digit( (string)$formats['padding'] ) ) {
776
+ $invoice_number = sprintf('%0'.$formats['padding'].'d', $invoice_number);
777
+ }
778
+
779
+ $formatted_invoice_number = $formats['prefix'] . $invoice_number . $formats['suffix'] ;
780
+
781
+ return $formatted_invoice_number;
782
+ }
783
+
784
+ public function get_display_number( $order_id ) {
785
+ if ( !isset($this->order->id) ) {
786
+ $this->order = new WC_Order ( $order_id );
787
+ }
788
+
789
+ if ( isset($this->template_settings['display_number']) && $this->template_settings['display_number'] == 'invoice_number' ) {
790
+ // use invoice number
791
+ $display_number = $this->get_invoice_number( $order_id );
792
+ // die($display_number);
793
+ } else {
794
+ // use order number
795
+ $display_number = ltrim($this->order->get_order_number(), '#');
796
+ }
797
+
798
+ return $display_number;
799
+ }
800
+
801
+ /**
802
+ * Return evaluated template contents
803
+ */
804
+ public function get_template( $file ) {
805
+ ob_start();
806
+ if (file_exists($file)) {
807
+ include($file);
808
+ }
809
+ return ob_get_clean();
810
+ }
811
+
812
+ /**
813
+ * Get the current order
814
+ */
815
+ public function get_order() {
816
+ return $this->order;
817
+ }
818
+
819
+ /**
820
+ * Get the current order items
821
+ */
822
+ public function get_order_items() {
823
+ global $woocommerce;
824
+ global $_product;
825
+
826
+ $items = $this->order->get_items();
827
+ $data_list = array();
828
+
829
+ if( sizeof( $items ) > 0 ) {
830
+ foreach ( $items as $item_id => $item ) {
831
+ // Array with data for the pdf template
832
+ $data = array();
833
+
834
+ // Set the item_id
835
+ $data['item_id'] = $item_id;
836
+
837
+ // Set the id
838
+ $data['product_id'] = $item['product_id'];
839
+ $data['variation_id'] = $item['variation_id'];
840
+
841
+ // Set item name
842
+ $data['name'] = $item['name'];
843
+
844
+ // Set item quantity
845
+ $data['quantity'] = $item['qty'];
846
+
847
+ // Set the line total (=after discount)
848
+ $data['line_total'] = $this->wc_price( $item['line_total'] );
849
+ $data['single_line_total'] = $this->wc_price( $item['line_total'] / max( 1, $item['qty'] ) );
850
+ $data['line_tax'] = $this->wc_price( $item['line_tax'] );
851
+ $data['single_line_tax'] = $this->wc_price( $item['line_tax'] / max( 1, $item['qty'] ) );
852
+
853
+ $line_tax_data = maybe_unserialize( isset( $item['line_tax_data'] ) ? $item['line_tax_data'] : '' );
854
+ $data['tax_rates'] = $this->get_tax_rate( $item['tax_class'], $item['line_total'], $item['line_tax'], $line_tax_data );
855
+
856
+ // Set the line subtotal (=before discount)
857
+ $data['line_subtotal'] = $this->wc_price( $item['line_subtotal'] );
858
+ $data['line_subtotal_tax'] = $this->wc_price( $item['line_subtotal_tax'] );
859
+ $data['ex_price'] = $this->get_formatted_item_price ( $item, 'total', 'excl' );
860
+ $data['price'] = $this->get_formatted_item_price ( $item, 'total' );
861
+ $data['order_price'] = $this->order->get_formatted_line_subtotal( $item ); // formatted according to WC settings
862
+
863
+ // Calculate the single price with the same rules as the formatted line subtotal (!)
864
+ // = before discount
865
+ $data['ex_single_price'] = $this->get_formatted_item_price ( $item, 'single', 'excl' );
866
+ $data['single_price'] = $this->get_formatted_item_price ( $item, 'single' );
867
+
868
+ // Pass complete item array
869
+ $data['item'] = $item;
870
+
871
+ // Create the product to display more info
872
+ $data['product'] = null;
873
+
874
+ $product = $this->order->get_product_from_item( $item );
875
+
876
+ // Checking fo existance, thanks to MDesigner0
877
+ if(!empty($product)) {
878
+ // Set the thumbnail id DEPRICATED (does not support thumbnail sizes), use thumbnail_path or thumbnail instead
879
+ $data['thumbnail_id'] = $this->get_thumbnail_id( $product );
880
+
881
+ // Thumbnail (full img tag)
882
+ $data['thumbnail'] = $this->get_thumbnail ( $product );
883
+
884
+ // Set the single price (turned off to use more consistent calculated price)
885
+ // $data['single_price'] = woocommerce_price ( $product->get_price() );
886
+
887
+ // Set item SKU
888
+ $data['sku'] = $product->get_sku();
889
+
890
+ // Set item weight
891
+ $data['weight'] = $product->get_weight();
892
+
893
+ // Set item dimensions
894
+ $data['dimensions'] = $product->get_dimensions();
895
+
896
+ // Pass complete product object
897
+ $data['product'] = $product;
898
+
899
+ }
900
+
901
+ // Set item meta
902
+ if ( version_compare( WOOCOMMERCE_VERSION, '2.4', '<' ) ) {
903
+ $meta = new WC_Order_Item_Meta( $item['item_meta'], $product );
904
+ } else {
905
+ // pass complete item for WC2.4+
906
+ $meta = new WC_Order_Item_Meta( $item, $product );
907
+ }
908
+
909
+ $data['meta'] = $meta->display( false, true );
910
+
911
+ $data_list[$item_id] = apply_filters( 'wpo_wcpdf_order_item_data', $data, $this->order );
912
+ }
913
+ }
914
+
915
+ return apply_filters( 'wpo_wcpdf_order_items_data', $data_list, $this->order );
916
+ }
917
+
918
+ /**
919
+ * Gets price - formatted for display.
920
+ *
921
+ * @access public
922
+ * @param mixed $item
923
+ * @return string
924
+ */
925
+ public function get_formatted_item_price ( $item, $type, $tax_display = '' ) {
926
+ $item_price = 0;
927
+ $divider = ($type == 'single' && $item['qty'] != 0 )?$item['qty']:1; //divide by 1 if $type is not 'single' (thus 'total')
928
+
929
+ if ( ! isset( $item['line_subtotal'] ) || ! isset( $item['line_subtotal_tax'] ) )
930
+ return;
931
+
932
+ if ( $tax_display == 'excl' ) {
933
+ $item_price = $this->wc_price( ($this->order->get_line_subtotal( $item )) / $divider );
934
+ } else {
935
+ $item_price = $this->wc_price( ($this->order->get_line_subtotal( $item, true )) / $divider );
936
+ }
937
+
938
+ return $item_price;
939
+ }
940
+
941
+ /**
942
+ * wrapper for wc2.1 depricated price function
943
+ */
944
+ public function wc_price( $price, $args = array() ) {
945
+ if ( version_compare( WOOCOMMERCE_VERSION, '2.1' ) >= 0 ) {
946
+ // WC 2.1 or newer is used
947
+ $args['currency'] = $this->order->get_order_currency();
948
+ $formatted_price = wc_price( $price, $args );
949
+ } else {
950
+ $formatted_price = woocommerce_price( $price );
951
+ }
952
+
953
+ return $formatted_price;
954
+ }
955
+
956
+ /**
957
+ * Get the tax rates/percentages for a given tax class
958
+ * @param string $tax_class tax class slug
959
+ * @return string $tax_rates imploded list of tax rates
960
+ */
961
+ public function get_tax_rate( $tax_class, $line_total, $line_tax, $line_tax_data = '' ) {
962
+ if ( $line_tax == 0 ) {
963
+ return '-'; // no need to determine tax rate...
964
+ }
965
+
966
+ // first try the easy wc2.2 way, using line_tax_data
967
+ if ( !empty( $line_tax_data ) && isset($line_tax_data['total']) ) {
968
+ $tax_rates = array();
969
+
970
+ $line_taxes = $line_tax_data['total'];
971
+ foreach ( $line_taxes as $tax_id => $tax ) {
972
+ if ( !empty($tax) && $tax != 0 ) {
973
+ $tax_rates[] = $this->get_tax_rate_by_id( $tax_id ) . ' %';
974
+ }
975
+ }
976
+
977
+ $tax_rates = implode(' ,', $tax_rates );
978
+ return $tax_rates;
979
+ }
980
+
981
+ if ( version_compare( WOOCOMMERCE_VERSION, '2.1' ) >= 0 && !apply_filters( 'wpo_wcpdf_calculate_tax_rate', false ) ) {
982
+ // WC 2.1 or newer is used
983
+
984
+ // if (empty($tax_class))
985
+ // $tax_class = 'standard';// does not appear to work anymore - get_rates does accept an empty tax_class though!
986
+
987
+ $tax = new WC_Tax();
988
+ $taxes = $tax->get_rates( $tax_class );
989
+
990
+ $tax_rates = array();
991
+
992
+ foreach ($taxes as $tax) {
993
+ $tax_rates[$tax['label']] = round( $tax['rate'], 2 ).' %';
994
+ }
995
+
996
+ if (empty($tax_rates)) {
997
+ // one last try: manually calculate
998
+ if ( $line_total != 0) {
999
+ $tax_rates[] = round( ($line_tax / $line_total)*100, 1 ).' %';
1000
+ } else {
1001
+ $tax_rates[] = '-';
1002
+ }
1003
+ }
1004
+
1005
+ $tax_rates = implode(' ,', $tax_rates );
1006
+ } else {
1007
+ // Backwards compatibility/fallback: calculate tax from line items
1008
+ if ( $line_total != 0) {
1009
+ $tax_rates = round( ($line_tax / $line_total)*100, 1 ).' %';
1010
+ } else {
1011
+ $tax_rates = '-';
1012
+ }
1013
+ }
1014
+
1015
+ return $tax_rates;
1016
+ }
1017
+
1018
+ /**
1019
+ * Returns the percentage rate (float) for a given tax rate ID.
1020
+ * @param int $rate_id woocommerce tax rate id
1021
+ * @return float $rate percentage rate
1022
+ */
1023
+ public function get_tax_rate_by_id( $rate_id ) {
1024
+ global $wpdb;
1025
+ $rate = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %d;", $rate_id ) );
1026
+ return (float) $rate;
1027
+ }
1028
+
1029
+ /**
1030
+ * Returns a an array with rate_id => tax rate data (array) of all tax rates in woocommerce
1031
+ * @return array $tax_rate_ids keyed by id
1032
+ */
1033
+ public function get_tax_rate_ids() {
1034
+ global $wpdb;
1035
+ $rates = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates" );
1036
+
1037
+ $tax_rate_ids = array();
1038
+ foreach ($rates as $rate) {
1039
+ // var_dump($rate->tax_rate_id);
1040
+ // die($rate);
1041
+ $rate_id = $rate->tax_rate_id;
1042
+ unset($rate->tax_rate_id);
1043
+ $tax_rate_ids[$rate_id] = (array) $rate;
1044
+ }
1045
+
1046
+ return $tax_rate_ids;
1047
+ }
1048
+
1049
+ /**
1050
+ * Get order custom field
1051
+ */
1052
+ public function get_order_field( $field ) {
1053
+ if( isset( $this->get_order()->order_custom_fields[$field] ) ) {
1054
+ return $this->get_order()->order_custom_fields[$field][0];
1055
+ }
1056
+ return;
1057
+ }
1058
+
1059
+ /**
1060
+ * Returns the main product image ID
1061
+ * Adapted from the WC_Product class
1062
+ *
1063
+ * @access public
1064
+ * @return string
1065
+ */
1066
+ public function get_thumbnail_id ( $product ) {
1067
+ // DEPRICATED (does not support thumbnail sizes)
1068
+ global $woocommerce;
1069
+
1070
+ if ( $product->variation_id && has_post_thumbnail( $product->variation_id ) ) {
1071
+ $thumbnail_id = get_post_thumbnail_id ( $product->variation_id );
1072
+ } elseif ( has_post_thumbnail( $product->id ) ) {
1073
+ $thumbnail_id = get_post_thumbnail_id ( $product->id );
1074
+ } elseif ( ( $parent_id = wp_get_post_parent_id( $product->id ) ) && has_post_thumbnail( $parent_id ) ) {
1075
+ $thumbnail_id = get_post_thumbnail_id ( $parent_id );
1076
+ } else {
1077
+ $thumbnail_id = $woocommerce->plugin_url() . '/assets/images/placeholder.png';
1078
+ }
1079
+
1080
+ return $thumbnail_id;
1081
+ }
1082
+
1083
+ public function get_thumbnail ( $product ) {
1084
+ // Get default WooCommerce img tag (url/http)
1085
+ $size = apply_filters( 'wpo_wcpdf_thumbnail_size', 'shop_thumbnail' );
1086
+ $thumbnail_img_tag_url = $product->get_image( $size, array( 'title' => '' ) );
1087
+
1088
+ // Extract the url from img
1089
+ preg_match('/<img(.*)src(.*)=(.*)"(.*)"/U', $thumbnail_img_tag_url, $thumbnail_url );
1090
+ // convert url to path
1091
+ $thumbnail_path = str_replace( get_site_url() . '/', ABSPATH, array_pop($thumbnail_url));
1092
+
1093
+ // Thumbnail (full img tag)
1094
+ if (apply_filters('wpo_wcpdf_use_path', true) && file_exists($thumbnail_path)) {
1095
+ // load img with server path by default
1096
+ $thumbnail = sprintf('<img width="90" height="90" src="%s" class="attachment-shop_thumbnail wp-post-image">', $thumbnail_path );
1097
+ } else {
1098
+ // load img with http url when filtered
1099
+ $thumbnail = $thumbnail_img_tag_url;
1100
+ }
1101
+
1102
+ // die($thumbnail);
1103
+
1104
+ return $thumbnail;
1105
+ }
1106
+
1107
+ public function add_product_bundles_classes ( $classes, $template_type, $order, $item_id = '' ) {
1108
+ if ( empty($item_id) ) {
1109
+ // get item id from classes (backwards compatibility fix)
1110
+ $class_array = explode(' ', $classes);
1111
+ foreach ($class_array as $class) {
1112
+ if (is_numeric($class)) {
1113
+ $item_id = $class;
1114
+ break;
1115
+ }
1116
+ }
1117
+
1118
+ // if still empty, we lost the item id somewhere :(
1119
+ if (empty($item_id)) {
1120
+ return $classes;
1121
+ }
1122
+ }
1123
+
1124
+ $item_meta = $order->get_item_meta( $item_id );
1125
+
1126
+ if (isset($item_meta['_bundled_by'])) {
1127
+ $classes = $classes . ' bundled-item';
1128
+
1129
+ // check bundled item visibility
1130
+ if ( ! empty( $item_meta[ '_bundled_item_hidden' ] ) ) {
1131
+ $classes = $classes . ' hidden';
1132
+ }
1133
+
1134
+ return $classes;
1135
+ } elseif (isset($item_meta['_bundled_items'])) {
1136
+ return $classes . ' product-bundle';
1137
+ }
1138
+
1139
+ return $classes;
1140
+ }
1141
+
1142
+ public function add_chained_product_class ( $classes, $template_type, $order, $item_id = '' ) {
1143
+ if ( empty($item_id) ) {
1144
+ // get item id from classes (backwards compatibility fix)
1145
+ $class_array = explode(' ', $classes);
1146
+ foreach ($class_array as $class) {
1147
+ if (is_numeric($class)) {
1148
+ $item_id = $class;
1149
+ break;
1150
+ }
1151
+ }
1152
+
1153
+ // if still empty, we lost the item id somewhere :(
1154
+ if (empty($item_id)) {
1155
+ return $classes;
1156
+ }
1157
+ }
1158
+
1159
+ $item_meta = $order->get_item_meta( $item_id );
1160
+
1161
+ if (isset($item_meta['_chained_product_of'])) {
1162
+ return $classes . ' chained-product';
1163
+ }
1164
+
1165
+ return $classes;
1166
+ }
1167
+
1168
+ /**
1169
+ * Filter plugin strings with qTranslate-X
1170
+ */
1171
+ public function qtranslatex_filters() {
1172
+ $use_filters = array(
1173
+ 'wpo_wcpdf_shop_name' => 20,
1174
+ 'wpo_wcpdf_shop_address' => 20,
1175
+ 'wpo_wcpdf_footer' => 20,
1176
+ 'wpo_wcpdf_order_items' => 20,
1177
+ 'wpo_wcpdf_payment_method' => 20,
1178
+ 'wpo_wcpdf_shipping_method' => 20,
1179
+ 'wpo_wcpdf_extra_1' => 20,
1180
+ 'wpo_wcpdf_extra_2' => 20,
1181
+ 'wpo_wcpdf_extra_3' => 20,
1182
+ );
1183
+
1184
+ foreach ( $use_filters as $name => $priority ) {
1185
+ add_filter( $name, 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage', $priority );
1186
+ }
1187
+ }
1188
+
1189
+ /**
1190
+ * Use currency symbol font (when enabled in options)
1191
+ */
1192
+ public function use_currency_font ( $template_type ) {
1193
+ add_filter( 'woocommerce_currency_symbol', array( $this, 'wrap_currency_symbol' ), 10, 2);
1194
+ add_action( 'wpo_wcpdf_custom_styles', array($this, 'currency_symbol_font_styles' ) );
1195
+ }
1196
+
1197
+ public function wrap_currency_symbol( $currency_symbol, $currency ) {
1198
+ $currency_symbol = sprintf( '<span class="wcpdf-currency-symbol">%s</span>', $currency_symbol );
1199
+ return $currency_symbol;
1200
+ }
1201
+
1202
+ public function currency_symbol_font_styles () {
1203
+ ?>
1204
+ .wcpdf-currency-symbol { font-family: 'Currencies'; }
1205
+ <?php
1206
+ }
1207
+
1208
+ public function enable_debug () {
1209
+ error_reporting( E_ALL );
1210
+ ini_set( 'display_errors', 1 );
1211
+ }
1212
+
1213
+ /**
1214
+ * Log messages
1215
+ */
1216
+
1217
+ public function log( $order_id, $message ) {
1218
+ $current_date_time = date("Y-m-d H:i:s");
1219
+ $message = $order_id . ' ' . $current_date_time .' ' .$message ."\n";
1220
+ $file = $this->tmp_path() . 'log.txt';
1221
+
1222
+ file_put_contents($file, $message, FILE_APPEND);
1223
+ }
1224
+ }
1225
+
1226
+ }
languages/wpo_wcpdf-ro_RO.mo CHANGED
Binary file
languages/wpo_wcpdf-ro_RO.po CHANGED
@@ -1,506 +1,502 @@
1
- msgid ""
2
- msgstr ""
3
- "Project-Id-Version: WooCommerce PDF Invoices & Packing Slips v1.4.9\n"
4
- "Report-Msgid-Bugs-To: \n"
5
- "POT-Creation-Date: 2014-09-18 15:08+0100\n"
6
- "PO-Revision-Date: 2014-11-05 22:53:12+0000\n"
7
- "Last-Translator: afternoon <zicevrei@afternoon.ro>\n"
8
- "Language-Team: \n"
9
- "MIME-Version: 1.0\n"
10
- "Content-Type: text/plain; charset=UTF-8\n"
11
- "Content-Transfer-Encoding: 8bit\n"
12
- "Plural-Forms: nplurals=2; plural=n != 1;\n"
13
- "X-Generator: Poedit 1.6.9\n"
14
- "X-Poedit-Language: \n"
15
- "X-Poedit-Country: \n"
16
- "X-Poedit-SourceCharset: utf-8\n"
17
- "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;\n"
18
- "X-Poedit-Basepath: ../\n"
19
- "X-Poedit-Bookmarks: \n"
20
- "X-Poedit-SearchPath-0: .\n"
21
- "X-Textdomain-Support: yes"
22
-
23
- #: includes/class-wcpdf-export.php:175
24
- #: includes/class-wcpdf-export.php:180
25
- #: includes/class-wcpdf-export.php:185
26
- #: includes/class-wcpdf-export.php:196
27
- #: includes/class-wcpdf-export.php:204
28
- #@ wpo_wcpdf
29
- msgid "You do not have sufficient permissions to access this page."
30
- msgstr "Nu aveți permisiunea pentru a accesa această pagină."
31
-
32
- #: includes/class-wcpdf-export.php:263
33
- #@ wpo_wcpdf
34
- msgid "invoice"
35
- msgid_plural "invoices"
36
- msgstr[0] ""
37
- msgstr[1] ""
38
-
39
- #: includes/class-wcpdf-export.php:267
40
- #@ wpo_wcpdf
41
- msgid "packing-slip"
42
- msgid_plural "packing-slips"
43
- msgstr[0] ""
44
- msgstr[1] ""
45
-
46
- #: includes/class-wcpdf-settings.php:38
47
- #: includes/class-wcpdf-settings.php:39
48
- #: includes/class-wcpdf-writepanels.php:31
49
- #@ wpo_wcpdf
50
- msgid "PDF Invoices"
51
- msgstr "Factură PDF"
52
-
53
- #: includes/class-wcpdf-settings.php:69
54
- #@ woocommerce
55
- msgid "Settings"
56
- msgstr ""
57
-
58
- #: includes/class-wcpdf-settings.php:91
59
- #@ wpo_wcpdf
60
- msgid "General"
61
- msgstr "General"
62
-
63
- #: includes/class-wcpdf-settings.php:92
64
- #@ wpo_wcpdf
65
- msgid "Template"
66
- msgstr "Șablon"
67
-
68
- #: includes/class-wcpdf-settings.php:101
69
- #@ wpo_wcpdf
70
- msgid "WooCommerce PDF Invoices"
71
- msgstr "Factură PDF WooCommerce"
72
-
73
- #: includes/class-wcpdf-settings.php:107
74
- #@ wpo_wcpdf
75
- msgid "Status"
76
- msgstr "Status"
77
-
78
- #: includes/class-wcpdf-settings.php:118
79
- #, php-format
80
- #@ wpo_wcpdf
81
- msgid "Upload all invoices automatically to your dropbox!<br/>Check out the %s extension."
82
- msgstr "Încărcaţi automat toate facturile în contul dvs. de Dropbox!<br/>Verifică extensia %s."
83
-
84
- #: includes/class-wcpdf-settings.php:128
85
- #, php-format
86
- #@ wpo_wcpdf
87
- msgid "Looking for more advanced templates? Check out the Premium PDF Invoice & Packing Slips templates at %s."
88
- msgstr "Căutați șabloane mai avansate? Vezi șabloanele Premium pentru Factură PDF și pentru Ordinul de comandă la %s."
89
-
90
- #: includes/class-wcpdf-settings.php:129
91
- #, php-format
92
- #@ wpo_wcpdf
93
- msgid "For custom templates, contact us at %s."
94
- msgstr "Pentru șabloane personalizate, contactați-ne la %s."
95
-
96
- #: includes/class-wcpdf-settings.php:184
97
- #@ wpo_wcpdf
98
- msgid "General settings"
99
- msgstr "Setări generale"
100
-
101
- #: includes/class-wcpdf-settings.php:191
102
- #@ wpo_wcpdf
103
- msgid "How do you want to view the PDF?"
104
- msgstr "Cum doriți să vizualizați PDF-ul?"
105
-
106
- #: includes/class-wcpdf-settings.php:199
107
- #@ wpo_wcpdf
108
- msgid "Download the PDF"
109
- msgstr "Descarcă PDF"
110
-
111
- #: includes/class-wcpdf-settings.php:200
112
- #@ wpo_wcpdf
113
- msgid "Open the PDF in a new browser tab/window"
114
- msgstr "Deschideți PDF-ul într-o filă/fereastră nouă"
115
-
116
- #: includes/class-wcpdf-settings.php:210
117
- #@ wpo_wcpdf
118
- msgid "Attach invoice to:"
119
- msgstr "Atașați factura la:"
120
-
121
- #: includes/class-wcpdf-settings.php:218
122
- #@ wpo_wcpdf
123
- msgid "Admin New Order email"
124
- msgstr "Comanda nouă destinată Administratorului"
125
-
126
- #: includes/class-wcpdf-settings.php:219
127
- #@ wpo_wcpdf
128
- msgid "Customer Processing Order email"
129
- msgstr "Comanda trimisă clientului în momentul procesării acesteia"
130
-
131
- #: includes/class-wcpdf-settings.php:220
132
- #@ wpo_wcpdf
133
- msgid "Customer Completed Order email"
134
- msgstr "Comanda trimisă clientului în momentul finalizării acesteia"
135
-
136
- #: includes/class-wcpdf-settings.php:221
137
- #@ wpo_wcpdf
138
- msgid "Customer Invoice email"
139
- msgstr "Email-ul trimis cu factura finală"
140
-
141
- #: includes/class-wcpdf-settings.php:223
142
- #, php-format
143
- #@ wpo_wcpdf
144
- msgid "It looks like the temp folder (<code>%s</code>) is not writable, check the permissions for this folder! Without having write access to this folder, the plugin will not be able to email invoices."
145
- msgstr "Se pare că folderul Temp (<code>%s</ code>) nu poate fi scris, verificați permisiunile pentru acest folder! Fără a avea acces de scriere la acest folder, plugin-ul nu va fi în măsură să trimita email-ul cu facturi."
146
-
147
- #: includes/class-wcpdf-settings.php:229
148
- #@ wpo_wcpdf
149
- msgid "Enable invoice number column in the orders list"
150
- msgstr "Activați coloana Număr de Factură din lista comenzilor"
151
-
152
- #: includes/class-wcpdf-settings.php:268
153
- #@ wpo_wcpdf
154
- msgid "PDF Template settings"
155
- msgstr "Setări șablon PDF"
156
-
157
- #: includes/class-wcpdf-settings.php:280
158
- #@ wpo_wcpdf
159
- msgid "Choose a template"
160
- msgstr "Alege un șablon"
161
-
162
- #: includes/class-wcpdf-settings.php:294
163
- #@ wpo_wcpdf
164
- msgid "Paper size"
165
- msgstr "Dimensiune hârtie"
166
-
167
- #: includes/class-wcpdf-settings.php:302
168
- #@ wpo_wcpdf
169
- msgid "A4"
170
- msgstr "A4"
171
-
172
- #: includes/class-wcpdf-settings.php:303
173
- #@ wpo_wcpdf
174
- msgid "Letter"
175
- msgstr "Letter"
176
-
177
- #: includes/class-wcpdf-settings.php:310
178
- #@ wpo_wcpdf
179
- msgid "Shop header/logo"
180
- msgstr "Antet/Logo"
181
-
182
- #: includes/class-wcpdf-settings.php:317
183
- #@ wpo_wcpdf
184
- msgid "Select or upload your invoice header/logo"
185
- msgstr "Selectați sau încărcați propriul dvs. antet sau logo"
186
-
187
- #: includes/class-wcpdf-settings.php:318
188
- #@ wpo_wcpdf
189
- msgid "Set image"
190
- msgstr "Setare imagine"
191
-
192
- #: includes/class-wcpdf-settings.php:319
193
- #@ wpo_wcpdf
194
- msgid "Remove image"
195
- msgstr "Șterge imagine"
196
-
197
- #: includes/class-wcpdf-settings.php:326
198
- #@ wpo_wcpdf
199
- msgid "Shop Name"
200
- msgstr "Nume magazin"
201
-
202
- #: includes/class-wcpdf-settings.php:339
203
- #@ wpo_wcpdf
204
- msgid "Shop Address"
205
- msgstr "Adresă magazin"
206
-
207
- #: includes/class-wcpdf-settings.php:371
208
- #@ wpo_wcpdf
209
- msgid "Footer: terms & conditions, policies, etc."
210
- msgstr "Notă de subsol: termeni și condiții, politică de confidențialitate, etc."
211
-
212
- #: includes/class-wcpdf-settings.php:412
213
- #@ wpo_wcpdf
214
- msgid "Next invoice number (without prefix/suffix etc.)"
215
- msgstr "Următorul număr de factură (fără prefix/sufix etc.)"
216
-
217
- #: includes/class-wcpdf-settings.php:420
218
- #@ wpo_wcpdf
219
- msgid "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!"
220
- msgstr "Acesta este numărul care va fi folosit la următoarea factură creată. În mod implicit, numerotarea începe de la primul număr al Ordinului de comanda WooCommerce creat și crește pentru fiecare nouă factură. Rețineți că, dacă rescrieți factura și îi setați un număr mai mic decât cel mai mare număr de factură (PDF), acest lucru ar putea crea un număr duplicat la factură!"
221
-
222
- #: includes/class-wcpdf-settings.php:426
223
- #, fuzzy
224
- #@ wpo_wcpdf
225
- msgid "Invoice number format"
226
- msgstr "Număr factură"
227
-
228
- #: includes/class-wcpdf-settings.php:435
229
- #@ wpo_wcpdf
230
- msgid "Prefix"
231
- msgstr "Prefix"
232
-
233
- #: includes/class-wcpdf-settings.php:437
234
- #@ wpo_wcpdf
235
- msgid "to use the order year and/or month, use [order_year] or [order_month] respectively"
236
- msgstr "Pentru a folosi sortarea după an și/sau lună, folosiţi [order_year] sau [order_month]"
237
-
238
- #: includes/class-wcpdf-settings.php:440
239
- #@ wpo_wcpdf
240
- msgid "Suffix"
241
- msgstr "Sufix"
242
-
243
- #: includes/class-wcpdf-settings.php:445
244
- #@ wpo_wcpdf
245
- msgid "Padding"
246
- msgstr "Umplutură"
247
-
248
- #: includes/class-wcpdf-settings.php:447
249
- #@ wpo_wcpdf
250
- msgid "enter the number of digits here - enter \"6\" to display 42 as 000042"
251
- msgstr "introduceţi numărul aici - introduceţi \"6\" pentru a afișa 42 ca 000042"
252
-
253
- #: includes/class-wcpdf-settings.php:450
254
- #@ wpo_wcpdf
255
- msgid "note: if you have already created a custom invoice number format with a filter, the above settings will be ignored"
256
- msgstr "Atenţie: dacă ați creat deja un număr personalizat de factură cu filtru, setările de mai sus vor fi ignorate"
257
-
258
- #: includes/class-wcpdf-settings.php:457
259
- #@ wpo_wcpdf
260
- msgid "Extra template fields"
261
- msgstr "Câmpuri suplimentare pentru șablon"
262
-
263
- #: includes/class-wcpdf-settings.php:464
264
- #@ wpo_wcpdf
265
- msgid "Extra field 1"
266
- msgstr "Câmp suplimentar 1"
267
-
268
- #: includes/class-wcpdf-settings.php:473
269
- #@ wpo_wcpdf
270
- msgid "This is footer column 1 in the <i>Modern (Premium)</i> template"
271
- msgstr "Aceasta este coloana 1 pentru nota de subsol, disponibilă în șablonul <i>Modern (Premium)</ i>"
272
-
273
- #: includes/class-wcpdf-settings.php:479
274
- #@ wpo_wcpdf
275
- msgid "Extra field 2"
276
- msgstr "Câmp suplimentar 2"
277
-
278
- #: includes/class-wcpdf-settings.php:488
279
- #@ wpo_wcpdf
280
- msgid "This is footer column 2 in the <i>Modern (Premium)</i> template"
281
- msgstr "Aceasta este coloana 2 pentru nota de subsol, disponibilă în șablonul <i>Modern (Premium)</ i>"
282
-
283
- #: includes/class-wcpdf-settings.php:494
284
- #@ wpo_wcpdf
285
- msgid "Extra field 3"
286
- msgstr "Câmp suplimentar 3"
287
-
288
- #: includes/class-wcpdf-settings.php:503
289
- #@ wpo_wcpdf
290
- msgid "This is footer column 3 in the <i>Modern (Premium)</i> template"
291
- msgstr "Aceasta este coloana 3 pentru nota de subsol, disponibilă în șablonul <i>Modern (Premium)</ i>"
292
-
293
- #: includes/class-wcpdf-settings.php:761
294
- #@ default
295
- msgid "Image resolution"
296
- msgstr ""
297
-
298
- #: includes/class-wcpdf-settings.php:877
299
- #@ wpo_wcpdf
300
- msgid "These are used for the (optional) footer columns in the <em>Modern (Premium)</em> template, but can also be used for other elements in your custom template"
301
- msgstr "Acestea sunt utilizate pentru (opțional) coloanele notei de subsol din șablonul <em>Modern (Premium)</ em>, dar poate fi de asemenea utilizat pentru alte elemente în șablonul personalizat"
302
-
303
- #: includes/class-wcpdf-writepanels.php:123
304
- #@ wpo_wcpdf
305
- msgid "Invoice Number"
306
- msgstr "Număr factură"
307
-
308
- #: includes/class-wcpdf-writepanels.php:160
309
- #@ wpo_wcpdf
310
- msgid "Download invoice (PDF)"
311
- msgstr "Descarcă factură (PDF)"
312
-
313
- #: includes/class-wcpdf-writepanels.php:171
314
- #@ wpo_wcpdf
315
- msgid "Create PDF"
316
- msgstr "Crează PDF"
317
-
318
- #: includes/class-wcpdf-writepanels.php:96
319
- #: includes/class-wcpdf-writepanels.php:188
320
- #: includes/class-wcpdf-writepanels.php:189
321
- #@ wpo_wcpdf
322
- msgid "PDF Packing Slip"
323
- msgstr "Ordin de comandă PDF"
324
-
325
- #: includes/class-wcpdf-writepanels.php:32
326
- #@ wpo_wcpdf
327
- msgid "PDF Packing Slips"
328
- msgstr "Ordine de comandă PDF"
329
-
330
- #: includes/class-wcpdf-writepanels.php:232
331
- #@ wpo_wcpdf
332
- msgid "PDF Invoice Number (unformatted!)"
333
- msgstr "Număr factură PDF (neformatat!)"
334
-
335
- #: includes/class-wcpdf-writepanels.php:235
336
- #: templates/pdf/Simple/invoice.php:36
337
- #@ wpo_wcpdf
338
- msgid "Invoice Date:"
339
- msgstr "Dată factură:"
340
-
341
- #: includes/class-wcpdf-writepanels.php:236
342
- #@ woocommerce
343
- msgid "h"
344
- msgstr ""
345
-
346
- #: includes/class-wcpdf-writepanels.php:236
347
- #@ woocommerce
348
- msgid "m"
349
- msgstr ""
350
-
351
- #: templates/pdf/Simple/html-document-wrapper.php:6
352
- #: templates/pdf/Simple/invoice.php:9
353
- #: templates/pdf/Simple/invoice.php:21
354
- #@ wpo_wcpdf
355
- msgid "Invoice"
356
- msgstr "Factură"
357
-
358
- #: templates/pdf/Simple/html-document-wrapper.php:6
359
- #: templates/pdf/Simple/packing-slip.php:9
360
- #: templates/pdf/Simple/packing-slip.php:21
361
- #@ wpo_wcpdf
362
- msgid "Packing Slip"
363
- msgstr "Ordin de comandă"
364
-
365
- #: templates/pdf/Simple/invoice.php:41
366
- #: templates/pdf/Simple/packing-slip.php:31
367
- #@ wpo_wcpdf
368
- msgid "Order Date:"
369
- msgstr "Dată comandă:"
370
-
371
- #: templates/pdf/Simple/invoice.php:32
372
- #@ wpo_wcpdf
373
- msgid "Invoice Number:"
374
- msgstr "Număr factură:"
375
-
376
- #: templates/pdf/Simple/invoice.php:39
377
- #: templates/pdf/Simple/packing-slip.php:33
378
- #@ wpo_wcpdf
379
- msgid "Order Number:"
380
- msgstr "Număr comandă:"
381
-
382
- #: templates/pdf/Simple/invoice.php:43
383
- #@ wpo_wcpdf
384
- msgid "Payment Method:"
385
- msgstr "Metodă de plată:"
386
-
387
- #: templates/pdf/Simple/invoice.php:59
388
- #: templates/pdf/Simple/packing-slip.php:49
389
- #@ wpo_wcpdf
390
- msgid "Product"
391
- msgstr "Produs"
392
-
393
- #: templates/pdf/Simple/invoice.php:60
394
- #: templates/pdf/Simple/packing-slip.php:50
395
- #@ wpo_wcpdf
396
- msgid "Quantity"
397
- msgstr "Cantitate"
398
-
399
- #: templates/pdf/Simple/invoice.php:61
400
- #@ wpo_wcpdf
401
- msgid "Price"
402
- msgstr "PreÈ›"
403
-
404
- #: templates/pdf/Simple/invoice.php:67
405
- #@ wpo_wcpdf
406
- msgid "Description"
407
- msgstr "Descriere"
408
-
409
- #: templates/pdf/Simple/invoice.php:70
410
- #@ wpo_wcpdf
411
- msgid "SKU"
412
- msgstr "Cod produs (SKU)"
413
-
414
- #: templates/pdf/Simple/invoice.php:71
415
- #: templates/pdf/Simple/packing-slip.php:58
416
- #@ wpo_wcpdf
417
- msgid "SKU:"
418
- msgstr "Cod produs (SKU):"
419
-
420
- #: templates/pdf/Simple/invoice.php:72
421
- #: templates/pdf/Simple/packing-slip.php:59
422
- #@ wpo_wcpdf
423
- msgid "Weight:"
424
- msgstr "Greutate:"
425
-
426
- #: templates/pdf/Simple/invoice.php:106
427
- #: templates/pdf/Simple/packing-slip.php:74
428
- #@ wpo_wcpdf
429
- msgid "Customer Notes"
430
- msgstr "Notiță client"
431
-
432
- #: woocommerce-pdf-invoices-packingslips.php:98
433
- #, php-format
434
- #@ wpo_wcpdf
435
- msgid "WooCommerce PDF Invoices & Packing Slips requires %sWooCommerce%s to be installed & activated!"
436
- msgstr "%sWooCommerce%s trebuie să fie instalat și activ pentru ca Factura PDF și Ordinul de comandă WooCommerce să funcționeze."
437
-
438
- #: woocommerce-pdf-invoices-packingslips.php:206
439
- #: woocommerce-pdf-invoices-packingslips.php:269
440
- #@ wpo_wcpdf
441
- msgid "N/A"
442
- msgstr "Nu se aplică (N/A)"
443
-
444
- #: woocommerce-pdf-invoices-packingslips.php:358
445
- #@ wpo_wcpdf
446
- msgid "Payment method"
447
- msgstr "Metodă de plată"
448
-
449
- #: woocommerce-pdf-invoices-packingslips.php:369
450
- #@ wpo_wcpdf
451
- msgid "Shipping method"
452
- msgstr "Metodă de livrare"
453
-
454
- #: woocommerce-pdf-invoices-packingslips.php:484
455
- #@ wpo_wcpdf
456
- msgid "Subtotal"
457
- msgstr "Subtotal"
458
-
459
- #: woocommerce-pdf-invoices-packingslips.php:506
460
- #@ wpo_wcpdf
461
- msgid "Shipping"
462
- msgstr "Transport"
463
-
464
- #: woocommerce-pdf-invoices-packingslips.php:540
465
- #@ wpo_wcpdf
466
- msgid "Discount"
467
- msgstr "Reducere"
468
-
469
- #: woocommerce-pdf-invoices-packingslips.php:579
470
- #@ wpo_wcpdf
471
- msgid "VAT"
472
- msgstr "TVA"
473
-
474
- #: woocommerce-pdf-invoices-packingslips.php:616
475
- #@ default
476
- msgid "Total ex. VAT"
477
- msgstr ""
478
-
479
- #: woocommerce-pdf-invoices-packingslips.php:619
480
- #@ default
481
- msgid "Total"
482
- msgstr ""
483
-
484
- #: includes/class-wcpdf-settings.php:288
485
- #, php-format
486
- #@ wpo_wcpdf
487
- msgid "Want to use your own template? Copy all the files from <code>%s</code> to your (child) theme in <code>%s</code> to customize them"
488
- msgstr "Doriți să utilizați propriul șablon? Copiați toate fișierele din <code>%s</code> in folderul temei dvs. în <code>%s</code> pentru a le personaliza"
489
-
490
- #: includes/class-wcpdf-settings.php:386
491
- #@ wpo_wcpdf
492
- msgid "Display invoice date"
493
- msgstr "Afișează data facturii"
494
-
495
- #: includes/class-wcpdf-settings.php:399
496
- #@ wpo_wcpdf
497
- msgid "Display built-in sequential invoice number"
498
- msgstr "Afișează numărul de factură secvenţial standard"
499
-
500
- #: includes/class-wcpdf-writepanels.php:91
501
- #: includes/class-wcpdf-writepanels.php:183
502
- #: includes/class-wcpdf-writepanels.php:184
503
- #@ wpo_wcpdf
504
- msgid "PDF Invoice"
505
- msgstr "Factură PDF"
506
-
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: WooCommerce PDF Invoices & Packing Slips v1.4.9\n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2014-09-18 15:08+0100\n"
6
+ "PO-Revision-Date: 2016-05-11 12:26+0200\n"
7
+ "Last-Translator: SC 3G Personal SRL,RO 15233799 <levente_gergely@yahoo.com>\n"
8
+ "Language-Team: \n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "Plural-Forms: nplurals=2; plural=n != 1;\n"
13
+ "X-Generator: Poedit 1.6.9\n"
14
+ "X-Poedit-SourceCharset: utf-8\n"
15
+ "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2\n"
16
+ "X-Poedit-Basepath: ../\n"
17
+ "X-Textdomain-Support: yes\n"
18
+ "X-Poedit-SearchPath-0: .\n"
19
+
20
+ #@ wpo_wcpdf
21
+ #: includes/class-wcpdf-export.php:175
22
+ #: includes/class-wcpdf-export.php:180
23
+ #: includes/class-wcpdf-export.php:185
24
+ #: includes/class-wcpdf-export.php:196
25
+ #: includes/class-wcpdf-export.php:204
26
+ msgid "You do not have sufficient permissions to access this page."
27
+ msgstr "Nu aveți permisiunea pentru a accesa această pagină."
28
+
29
+ #@ wpo_wcpdf
30
+ #: includes/class-wcpdf-export.php:263
31
+ msgid "invoice"
32
+ msgid_plural "invoices"
33
+ msgstr[0] "Factura Fiscala"
34
+ msgstr[1] "Facturi Fiscale"
35
+
36
+ #@ wpo_wcpdf
37
+ #: includes/class-wcpdf-export.php:267
38
+ msgid "packing-slip"
39
+ msgid_plural "packing-slips"
40
+ msgstr[0] ""
41
+ msgstr[1] ""
42
+
43
+ #@ wpo_wcpdf
44
+ #: includes/class-wcpdf-settings.php:38
45
+ #: includes/class-wcpdf-settings.php:39
46
+ #: includes/class-wcpdf-writepanels.php:31
47
+ msgid "PDF Invoices"
48
+ msgstr "Factură PDF"
49
+
50
+ #@ woocommerce
51
+ #: includes/class-wcpdf-settings.php:69
52
+ msgid "Settings"
53
+ msgstr ""
54
+
55
+ #@ wpo_wcpdf
56
+ #: includes/class-wcpdf-settings.php:91
57
+ msgid "General"
58
+ msgstr "General"
59
+
60
+ #@ wpo_wcpdf
61
+ #: includes/class-wcpdf-settings.php:92
62
+ msgid "Template"
63
+ msgstr "Șablon"
64
+
65
+ #@ wpo_wcpdf
66
+ #: includes/class-wcpdf-settings.php:101
67
+ msgid "WooCommerce PDF Invoices"
68
+ msgstr "Factură PDF WooCommerce"
69
+
70
+ #@ wpo_wcpdf
71
+ #: includes/class-wcpdf-settings.php:107
72
+ msgid "Status"
73
+ msgstr "Status"
74
+
75
+ #@ wpo_wcpdf
76
+ #: includes/class-wcpdf-settings.php:118
77
+ #, php-format
78
+ msgid "Upload all invoices automatically to your dropbox!<br/>Check out the %s extension."
79
+ msgstr "Încărcaţi automat toate facturile în contul dvs. de Dropbox!<br/>Verifică extensia %s."
80
+
81
+ #@ wpo_wcpdf
82
+ #: includes/class-wcpdf-settings.php:128
83
+ #, php-format
84
+ msgid "Looking for more advanced templates? Check out the Premium PDF Invoice & Packing Slips templates at %s."
85
+ msgstr "Căutați șabloane mai avansate? Vezi șabloanele Premium pentru Factură PDF și pentru Ordinul de comandă la %s."
86
+
87
+ #@ wpo_wcpdf
88
+ #: includes/class-wcpdf-settings.php:129
89
+ #, php-format
90
+ msgid "For custom templates, contact us at %s."
91
+ msgstr "Pentru șabloane personalizate, contactați-ne la %s."
92
+
93
+ #@ wpo_wcpdf
94
+ #: includes/class-wcpdf-settings.php:184
95
+ msgid "General settings"
96
+ msgstr "Setări generale"
97
+
98
+ #@ wpo_wcpdf
99
+ #: includes/class-wcpdf-settings.php:191
100
+ msgid "How do you want to view the PDF?"
101
+ msgstr "Cum doriți să vizualizați PDF-ul?"
102
+
103
+ #@ wpo_wcpdf
104
+ #: includes/class-wcpdf-settings.php:199
105
+ msgid "Download the PDF"
106
+ msgstr "Descarcă PDF"
107
+
108
+ #@ wpo_wcpdf
109
+ #: includes/class-wcpdf-settings.php:200
110
+ msgid "Open the PDF in a new browser tab/window"
111
+ msgstr "Deschideți PDF-ul într-o filă/fereastră nouă"
112
+
113
+ #@ wpo_wcpdf
114
+ #: includes/class-wcpdf-settings.php:210
115
+ msgid "Attach invoice to:"
116
+ msgstr "Atașați factura la:"
117
+
118
+ #@ wpo_wcpdf
119
+ #: includes/class-wcpdf-settings.php:218
120
+ msgid "Admin New Order email"
121
+ msgstr "Comanda nouă destinată Administratorului"
122
+
123
+ #@ wpo_wcpdf
124
+ #: includes/class-wcpdf-settings.php:219
125
+ msgid "Customer Processing Order email"
126
+ msgstr "Comanda trimisă clientului în momentul procesării acesteia"
127
+
128
+ #@ wpo_wcpdf
129
+ #: includes/class-wcpdf-settings.php:220
130
+ msgid "Customer Completed Order email"
131
+ msgstr "Comanda trimisă clientului în momentul finalizării acesteia"
132
+
133
+ #@ wpo_wcpdf
134
+ #: includes/class-wcpdf-settings.php:221
135
+ msgid "Customer Invoice email"
136
+ msgstr "Email-ul trimis cu factura finală"
137
+
138
+ #@ wpo_wcpdf
139
+ #: includes/class-wcpdf-settings.php:223
140
+ #, php-format
141
+ msgid "It looks like the temp folder (<code>%s</code>) is not writable, check the permissions for this folder! Without having write access to this folder, the plugin will not be able to email invoices."
142
+ msgstr "Se pare că folderul Temp (<code>%s</ code>) nu poate fi scris, verificați permisiunile pentru acest folder! Fără a avea acces de scriere la acest folder, plugin-ul nu va fi în măsură să trimita email-ul cu facturi."
143
+
144
+ #@ wpo_wcpdf
145
+ #: includes/class-wcpdf-settings.php:229
146
+ msgid "Enable invoice number column in the orders list"
147
+ msgstr "Activați coloana Număr de Factură din lista comenzilor"
148
+
149
+ #@ wpo_wcpdf
150
+ #: includes/class-wcpdf-settings.php:268
151
+ msgid "PDF Template settings"
152
+ msgstr "Setări șablon PDF"
153
+
154
+ #@ wpo_wcpdf
155
+ #: includes/class-wcpdf-settings.php:280
156
+ msgid "Choose a template"
157
+ msgstr "Alege un șablon"
158
+
159
+ #@ wpo_wcpdf
160
+ #: includes/class-wcpdf-settings.php:294
161
+ msgid "Paper size"
162
+ msgstr "Dimensiune hârtie"
163
+
164
+ #@ wpo_wcpdf
165
+ #: includes/class-wcpdf-settings.php:302
166
+ msgid "A4"
167
+ msgstr "A4"
168
+
169
+ #@ wpo_wcpdf
170
+ #: includes/class-wcpdf-settings.php:303
171
+ msgid "Letter"
172
+ msgstr "Letter"
173
+
174
+ #@ wpo_wcpdf
175
+ #: includes/class-wcpdf-settings.php:310
176
+ msgid "Shop header/logo"
177
+ msgstr "Antet/Logo"
178
+
179
+ #@ wpo_wcpdf
180
+ #: includes/class-wcpdf-settings.php:317
181
+ msgid "Select or upload your invoice header/logo"
182
+ msgstr "Selectați sau încărcați propriul dvs. antet sau logo"
183
+
184
+ #@ wpo_wcpdf
185
+ #: includes/class-wcpdf-settings.php:318
186
+ msgid "Set image"
187
+ msgstr "Setare imagine"
188
+
189
+ #@ wpo_wcpdf
190
+ #: includes/class-wcpdf-settings.php:319
191
+ msgid "Remove image"
192
+ msgstr "Șterge imagine"
193
+
194
+ #@ wpo_wcpdf
195
+ #: includes/class-wcpdf-settings.php:326
196
+ msgid "Shop Name"
197
+ msgstr "Nume magazin"
198
+
199
+ #@ wpo_wcpdf
200
+ #: includes/class-wcpdf-settings.php:339
201
+ msgid "Shop Address"
202
+ msgstr "Adresă magazin"
203
+
204
+ #@ wpo_wcpdf
205
+ #: includes/class-wcpdf-settings.php:371
206
+ msgid "Footer: terms & conditions, policies, etc."
207
+ msgstr "Notă de subsol: termeni și condiții, politică de confidențialitate, etc."
208
+
209
+ #@ wpo_wcpdf
210
+ #: includes/class-wcpdf-settings.php:412
211
+ msgid "Next invoice number (without prefix/suffix etc.)"
212
+ msgstr "Următorul număr de factură (fără prefix/sufix etc.)"
213
+
214
+ #@ wpo_wcpdf
215
+ #: includes/class-wcpdf-settings.php:420
216
+ msgid "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!"
217
+ msgstr "Acesta este numărul care va fi folosit la următoarea factură creată. În mod implicit, numerotarea începe de la primul număr al Ordinului de comanda WooCommerce creat și crește pentru fiecare nouă factură. Rețineți că, dacă rescrieți factura și îi setați un număr mai mic decât cel mai mare număr de factură (PDF), acest lucru ar putea crea un număr duplicat la factură!"
218
+
219
+ #@ wpo_wcpdf
220
+ #: includes/class-wcpdf-settings.php:426
221
+ msgid "Invoice number format"
222
+ msgstr "Număr factură"
223
+
224
+ #@ wpo_wcpdf
225
+ #: includes/class-wcpdf-settings.php:435
226
+ msgid "Prefix"
227
+ msgstr "Prefix"
228
+
229
+ #@ wpo_wcpdf
230
+ #: includes/class-wcpdf-settings.php:437
231
+ msgid "to use the order year and/or month, use [order_year] or [order_month] respectively"
232
+ msgstr "Pentru a folosi sortarea după an și/sau lună, folosiţi [order_year] sau [order_month]"
233
+
234
+ #@ wpo_wcpdf
235
+ #: includes/class-wcpdf-settings.php:440
236
+ msgid "Suffix"
237
+ msgstr "Sufix"
238
+
239
+ #@ wpo_wcpdf
240
+ #: includes/class-wcpdf-settings.php:445
241
+ msgid "Padding"
242
+ msgstr "Umplutură"
243
+
244
+ #@ wpo_wcpdf
245
+ #: includes/class-wcpdf-settings.php:447
246
+ msgid "enter the number of digits here - enter \"6\" to display 42 as 000042"
247
+ msgstr "introduceţi numărul aici - introduceţi \"6\" pentru a afișa 42 ca 000042"
248
+
249
+ #@ wpo_wcpdf
250
+ #: includes/class-wcpdf-settings.php:450
251
+ msgid "note: if you have already created a custom invoice number format with a filter, the above settings will be ignored"
252
+ msgstr "Atenţie: dacă ați creat deja un număr personalizat de factură cu filtru, setările de mai sus vor fi ignorate"
253
+
254
+ #@ wpo_wcpdf
255
+ #: includes/class-wcpdf-settings.php:457
256
+ msgid "Extra template fields"
257
+ msgstr "Câmpuri suplimentare pentru șablon"
258
+
259
+ #@ wpo_wcpdf
260
+ #: includes/class-wcpdf-settings.php:464
261
+ msgid "Extra field 1"
262
+ msgstr "Câmp suplimentar 1"
263
+
264
+ #@ wpo_wcpdf
265
+ #: includes/class-wcpdf-settings.php:473
266
+ msgid "This is footer column 1 in the <i>Modern (Premium)</i> template"
267
+ msgstr "Aceasta este coloana 1 pentru nota de subsol, disponibilă în șablonul <i>Modern (Premium)</ i>"
268
+
269
+ #@ wpo_wcpdf
270
+ #: includes/class-wcpdf-settings.php:479
271
+ msgid "Extra field 2"
272
+ msgstr "Câmp suplimentar 2"
273
+
274
+ #@ wpo_wcpdf
275
+ #: includes/class-wcpdf-settings.php:488
276
+ msgid "This is footer column 2 in the <i>Modern (Premium)</i> template"
277
+ msgstr "Aceasta este coloana 2 pentru nota de subsol, disponibilă în șablonul <i>Modern (Premium)</ i>"
278
+
279
+ #@ wpo_wcpdf
280
+ #: includes/class-wcpdf-settings.php:494
281
+ msgid "Extra field 3"
282
+ msgstr "Câmp suplimentar 3"
283
+
284
+ #@ wpo_wcpdf
285
+ #: includes/class-wcpdf-settings.php:503
286
+ msgid "This is footer column 3 in the <i>Modern (Premium)</i> template"
287
+ msgstr "Aceasta este coloana 3 pentru nota de subsol, disponibilă în șablonul <i>Modern (Premium)</ i>"
288
+
289
+ #@ default
290
+ #: includes/class-wcpdf-settings.php:761
291
+ msgid "Image resolution"
292
+ msgstr "Rezolutie imagine"
293
+
294
+ #@ wpo_wcpdf
295
+ #: includes/class-wcpdf-settings.php:877
296
+ msgid "These are used for the (optional) footer columns in the <em>Modern (Premium)</em> template, but can also be used for other elements in your custom template"
297
+ msgstr "Acestea sunt utilizate pentru (opțional) coloanele notei de subsol din șablonul <em>Modern (Premium)</ em>, dar poate fi de asemenea utilizat pentru alte elemente în șablonul personalizat"
298
+
299
+ #@ wpo_wcpdf
300
+ #: includes/class-wcpdf-writepanels.php:123
301
+ msgid "Invoice Number"
302
+ msgstr "Număr factură proformă"
303
+
304
+ #@ wpo_wcpdf
305
+ #: includes/class-wcpdf-writepanels.php:160
306
+ msgid "Download invoice (PDF)"
307
+ msgstr "Descarcă factura (PDF)"
308
+
309
+ #@ wpo_wcpdf
310
+ #: includes/class-wcpdf-writepanels.php:171
311
+ msgid "Create PDF"
312
+ msgstr "Crează PDF"
313
+
314
+ #@ wpo_wcpdf
315
+ #: includes/class-wcpdf-writepanels.php:96
316
+ #: includes/class-wcpdf-writepanels.php:188
317
+ #: includes/class-wcpdf-writepanels.php:189
318
+ msgid "PDF Packing Slip"
319
+ msgstr "Ordin de comandă PDF"
320
+
321
+ #@ wpo_wcpdf
322
+ #: includes/class-wcpdf-writepanels.php:32
323
+ msgid "PDF Packing Slips"
324
+ msgstr "Ordine de comandă PDF"
325
+
326
+ #@ wpo_wcpdf
327
+ #: includes/class-wcpdf-writepanels.php:232
328
+ msgid "PDF Invoice Number (unformatted!)"
329
+ msgstr "Număr factură PDF (neformatat!)"
330
+
331
+ #@ wpo_wcpdf
332
+ #: includes/class-wcpdf-writepanels.php:235
333
+ #: templates/pdf/Simple/invoice.php:36
334
+ msgid "Invoice Date:"
335
+ msgstr "Dată factură:"
336
+
337
+ #@ woocommerce
338
+ #: includes/class-wcpdf-writepanels.php:236
339
+ msgid "h"
340
+ msgstr "h"
341
+
342
+ #@ woocommerce
343
+ #: includes/class-wcpdf-writepanels.php:236
344
+ msgid "m"
345
+ msgstr "m"
346
+
347
+ #@ wpo_wcpdf
348
+ #: templates/pdf/Simple/html-document-wrapper.php:6
349
+ #: templates/pdf/Simple/invoice.php:9
350
+ #: templates/pdf/Simple/invoice.php:21
351
+ msgid "Invoice"
352
+ msgstr "Factură Proformă"
353
+
354
+ #@ wpo_wcpdf
355
+ #: templates/pdf/Simple/html-document-wrapper.php:6
356
+ #: templates/pdf/Simple/packing-slip.php:9
357
+ #: templates/pdf/Simple/packing-slip.php:21
358
+ msgid "Packing Slip"
359
+ msgstr "Ordin de comandă"
360
+
361
+ #@ wpo_wcpdf
362
+ #: templates/pdf/Simple/invoice.php:41
363
+ #: templates/pdf/Simple/packing-slip.php:31
364
+ msgid "Order Date:"
365
+ msgstr "Dată comandă:"
366
+
367
+ #@ wpo_wcpdf
368
+ #: templates/pdf/Simple/invoice.php:32
369
+ msgid "Invoice Number:"
370
+ msgstr "Număr factură:"
371
+
372
+ #@ wpo_wcpdf
373
+ #: templates/pdf/Simple/invoice.php:39
374
+ #: templates/pdf/Simple/packing-slip.php:33
375
+ msgid "Order Number:"
376
+ msgstr "Număr comandă:"
377
+
378
+ #@ wpo_wcpdf
379
+ #: templates/pdf/Simple/invoice.php:43
380
+ msgid "Payment Method:"
381
+ msgstr "Metodă de plată:"
382
+
383
+ #@ wpo_wcpdf
384
+ #: templates/pdf/Simple/invoice.php:59
385
+ #: templates/pdf/Simple/packing-slip.php:49
386
+ msgid "Product"
387
+ msgstr "Produs"
388
+
389
+ #@ wpo_wcpdf
390
+ #: templates/pdf/Simple/invoice.php:60
391
+ #: templates/pdf/Simple/packing-slip.php:50
392
+ msgid "Quantity"
393
+ msgstr "Cantitate"
394
+
395
+ #@ wpo_wcpdf
396
+ #: templates/pdf/Simple/invoice.php:61
397
+ msgid "Price"
398
+ msgstr "PreÈ›"
399
+
400
+ #@ wpo_wcpdf
401
+ #: templates/pdf/Simple/invoice.php:67
402
+ msgid "Description"
403
+ msgstr "Descriere"
404
+
405
+ #@ wpo_wcpdf
406
+ #: templates/pdf/Simple/invoice.php:70
407
+ msgid "SKU"
408
+ msgstr "Cod produs (SKU)"
409
+
410
+ #@ wpo_wcpdf
411
+ #: templates/pdf/Simple/invoice.php:71
412
+ #: templates/pdf/Simple/packing-slip.php:58
413
+ msgid "SKU:"
414
+ msgstr "Cod produs (SKU):"
415
+
416
+ #@ wpo_wcpdf
417
+ #: templates/pdf/Simple/invoice.php:72
418
+ #: templates/pdf/Simple/packing-slip.php:59
419
+ msgid "Weight:"
420
+ msgstr "Greutate:"
421
+
422
+ #@ wpo_wcpdf
423
+ #: templates/pdf/Simple/invoice.php:106
424
+ #: templates/pdf/Simple/packing-slip.php:74
425
+ msgid "Customer Notes"
426
+ msgstr "Notiță client"
427
+
428
+ #@ wpo_wcpdf
429
+ #: woocommerce-pdf-invoices-packingslips.php:98
430
+ #, php-format
431
+ msgid "WooCommerce PDF Invoices & Packing Slips requires %sWooCommerce%s to be installed & activated!"
432
+ msgstr "%sWooCommerce%s trebuie să fie instalat și activ pentru ca Factura PDF și Ordinul de comandă WooCommerce să funcționeze."
433
+
434
+ #@ wpo_wcpdf
435
+ #: woocommerce-pdf-invoices-packingslips.php:206
436
+ #: woocommerce-pdf-invoices-packingslips.php:269
437
+ msgid "N/A"
438
+ msgstr "Nu se aplică (N/A)"
439
+
440
+ #@ wpo_wcpdf
441
+ #: woocommerce-pdf-invoices-packingslips.php:358
442
+ msgid "Payment method"
443
+ msgstr "Metodă de plată"
444
+
445
+ #@ wpo_wcpdf
446
+ #: woocommerce-pdf-invoices-packingslips.php:369
447
+ msgid "Shipping method"
448
+ msgstr "Metodă de livrare"
449
+
450
+ #@ wpo_wcpdf
451
+ #: woocommerce-pdf-invoices-packingslips.php:484
452
+ msgid "Subtotal"
453
+ msgstr "Subtotal"
454
+
455
+ #@ wpo_wcpdf
456
+ #: woocommerce-pdf-invoices-packingslips.php:506
457
+ msgid "Shipping"
458
+ msgstr "Transport"
459
+
460
+ #@ wpo_wcpdf
461
+ #: woocommerce-pdf-invoices-packingslips.php:540
462
+ msgid "Discount"
463
+ msgstr "Reducere"
464
+
465
+ #@ wpo_wcpdf
466
+ #: woocommerce-pdf-invoices-packingslips.php:579
467
+ msgid "VAT"
468
+ msgstr "TVA"
469
+
470
+ #@ default
471
+ #: woocommerce-pdf-invoices-packingslips.php:616
472
+ msgid "Total ex. VAT"
473
+ msgstr "Total fara TVA"
474
+
475
+ #@ default
476
+ #: woocommerce-pdf-invoices-packingslips.php:619
477
+ msgid "Total"
478
+ msgstr "Total"
479
+
480
+ #@ wpo_wcpdf
481
+ #: includes/class-wcpdf-settings.php:288
482
+ #, php-format
483
+ msgid "Want to use your own template? Copy all the files from <code>%s</code> to your (child) theme in <code>%s</code> to customize them"
484
+ msgstr "Doriți să utilizați propriul șablon? Copiați toate fișierele din <code>%s</code> in folderul temei dvs. în <code>%s</code> pentru a le personaliza"
485
+
486
+ #@ wpo_wcpdf
487
+ #: includes/class-wcpdf-settings.php:386
488
+ msgid "Display invoice date"
489
+ msgstr "Afișează data facturii"
490
+
491
+ #@ wpo_wcpdf
492
+ #: includes/class-wcpdf-settings.php:399
493
+ msgid "Display built-in sequential invoice number"
494
+ msgstr "Afișează numărul de factură secvenţial standard"
495
+
496
+ #@ wpo_wcpdf
497
+ #: includes/class-wcpdf-writepanels.php:91
498
+ #: includes/class-wcpdf-writepanels.php:183
499
+ #: includes/class-wcpdf-writepanels.php:184
500
+ msgid "PDF Invoice"
501
+ msgstr "Factură PDF"
502
+
 
 
 
 
readme.txt CHANGED
@@ -1,614 +1,618 @@
1
- === Plugin Name ===
2
- 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.5
6
- Stable tag: 1.5.32
7
- License: GPLv2 or later
8
- License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
-
10
- Create, print & automatically email PDF invoices & packing slips for WooCommerce orders.
11
-
12
- == Description ==
13
-
14
- This WooCommerce extension automatically adds a PDF invoice to the order confirmation emails sent out to your customers. Includes a basic template (additional templates are available from [WP Overnight](https://wpovernight.com/downloads/woocommerce-pdf-invoices-packing-slips-premium-templates/)) as well as the possibility to modify/create your own templates. In addition, you can choose to download or print invoices and packing slips from the WooCommerce order admin.
15
-
16
- = Main features =
17
- * Automatically attach invoice PDF to WooCommerce emails of your choice
18
- * Download the PDF invoice / packing slip from the order admin page
19
- * Generate PDF invoices / packings slips in bulk
20
- * **Fully customizable** HTML/CSS invoice templates
21
- * Download invoices from the My Account page
22
- * Sequential invoice numbers - with custom formatting
23
- * **Available in: Czech, Dutch, English, Finnish, French, German, Hungarian, Italian, Japanese (see FAQ for adding custom fonts!), Norwegian, Polish, Romanian, Russian, Slovak, Slovenian, Spanish, Swedish & Ukrainian**
24
-
25
- In addition to this, we offer several premium extensions:
26
-
27
- * 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/)
28
- * Upload all invoices automatically to Dropbox with [WooCommerce PDF Invoices & Packing Slips to Dropbox](https://wpovernight.com/downloads/woocommerce-pdf-invoices-packing-slips-dropbox/)
29
- * 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)
30
- * More advanced & stylish templates with [WooCommerce PDF Invoices & Packing Slips Premium Templates](https://wpovernight.com/downloads/woocommerce-pdf-invoices-packing-slips-premium-templates/)
31
-
32
- = Fully customizable =
33
- In addition to a number of default settings (including a custom header/logo) and several layout fields that you can use out of the box, the plugin contains HTML/CSS based templates that allow for customization & full control over the PDF output. Copy the templates to your theme folder and you don't have to worry that your customizations will be overwritten when you update the plugin.
34
-
35
- * Insert customer header image/logo
36
- * Modify shop data / footer / disclaimer etc. on the invoices & packing slips
37
- * Select paper size (Letter or A4)
38
- * Translation ready
39
-
40
- == Installation ==
41
-
42
- = Minimum Requirements =
43
-
44
- * WooCommerce 2.0 or later
45
- * WordPress 3.5 or later
46
-
47
- = Automatic installation =
48
- Automatic installation is the easiest option as WordPress handles the file transfers itself and you don't even need to leave your web browser. To do an automatic install of WooCommerce PDF Invoices & Packing Slips, log in to your WordPress admin panel, navigate to the Plugins menu and click Add New.
49
-
50
- In the search field type "WooCommerce PDF Invoices & Packing Slips" and click Search Plugins. You can install it by simply clicking Install Now. After clicking that link you will be asked if you're sure you want to install the plugin. Click yes and WordPress will automatically complete the installation. After installation has finished, click the 'activate plugin' link.
51
-
52
- = Manual installation via the WordPress interface =
53
- 1. Download the plugin zip file to your computer
54
- 2. Go to the WordPress admin panel menu Plugins > Add New
55
- 3. Choose upload
56
- 4. Upload the plugin zip file, the plugin will now be installed
57
- 5. After installation has finished, click the 'activate plugin' link
58
-
59
- = Manual installation via FTP =
60
- 1. Download the plugin file to your computer and unzip it
61
- 2. Using an FTP program, or your hosting control panel, upload the unzipped plugin folder to your WordPress installation's wp-content/plugins/ directory.
62
- 3. Activate the plugin from the Plugins menu within the WordPress admin.
63
-
64
- == Frequently Asked Questions ==
65
-
66
- Make sure to check out [WooCommerce PDF Invoices & Packing Slips documentation](http://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/) on our site - it covers most of the questions below (and more!) in more detail!
67
-
68
- = How do I create my own custom template? =
69
-
70
- Copy the files from `wp-content/plugins/woocommerce-pdf-invoices-packing-slips/templates/pdf/Simple/` to your (child) theme in `wp-content/themes/yourtheme/woocommerce/pdf/yourtemplate` and customize them there. The new template will show up as 'yourtemplate' (the folder name) in the settings panel.
71
-
72
- = Where can I find more templates? =
73
-
74
- Go to [wpovernight.com](https://wpovernight.com/downloads/woocommerce-pdf-invoices-packing-slips-premium-templates/) to checkout more templates! These include templates with more tax details and product thumbnails. Need a custom templates? Contact us at support@wpovernight.com for more information.
75
-
76
- = Can I create/send a proforma invoice or a credit note? =
77
- This is a feature of our Professional extension, which can be found at [wpovernight.com](https://wpovernight.com/downloads/woocommerce-pdf-invoices-packing-slips-professional/)
78
-
79
- = Can I contribute to the code? =
80
- You're more than welcome! This plugin is hosted on github, where you can post issues or make pull requests.
81
- https://github.com/wpovernight/woocommerce-pdf-invoices-packing-slips
82
-
83
- = My language is not included, how can I contribute? =
84
-
85
- This plugin is translation ready, which means that you can translate it using standard WordPress methods.
86
-
87
- 1. Download POEdit at (http://www.poedit.net/download.php)
88
- 2. Open POEdit
89
- 3. File > New from POT
90
- 4. Open wpo_wcpdf.pot (from `woocommerce-pdf-invoices-packing-slips/languages/`)
91
- 5. A popup will ask you for your language
92
- 6. This step is a bit tricky, configuring the plurals. Somehow the settings can't be copied from the pot. Go to Catalogue > Preferences. Then enter nplurals=2; plural=n != 1; in the custom expression field
93
- 7. Enter the translations. invoice and packing-slip now have two translation fields, single & plural. Note that this is a filename, so replace spaces with a - just to be sure!
94
- 8. Save as `wpo_wcpdf-xx_XX.po`, where you replace xx_XX with your language code & country code suffix (da_DK, pl_PL, de_DE etc.)
95
-
96
- = How can I use my own font? =
97
- Although the plugin supports webfonts, this is somewhat limited and has a lot of caveats, read [this thread](https://wordpress.org/support/topic/webfonts-within-a-custom-template-not-rendering-in-pdf?replies=4#post-5395442) on the forum.
98
- Some languages (Japanese, Chinese, etc.) are not supported by the default font included with the plugin, in this case a custom font is required.
99
- The best method is to create a custom template first (see above), then add a `fonts/` folder to that template and use the following code (replace the font names/filenames) to load the font in the style.css from the pdf template:
100
- `
101
- <?php global $wpo_wcpdf;?>
102
- /* Load font */
103
- @font-face {
104
- font-family: 'MyFont';
105
- font-style: normal;
106
- font-weight: normal;
107
- src: local('MyFont'), local('MyFont'), url(<?php echo $wpo_wcpdf->export->template_path; ?>/fonts/myfont.ttf) format('truetype');
108
- }
109
- @font-face {
110
- font-family: 'MyFont';
111
- font-style: normal;
112
- font-weight: bold;
113
- src: local('MyFont Bold'), local('MyFont-Bold'), url(<?php echo $wpo_wcpdf->export->template_path; ?>/fonts/myfont-bold.ttf) format('truetype');
114
- }
115
- @font-face {
116
- font-family: 'MyFont';
117
- font-style: italic;
118
- font-weight: normal;
119
- src: local('MyFont Italic'), local('MyFont-Italic'), url(<?php echo $wpo_wcpdf->export->template_path; ?>/fonts/myfont-italic.ttf) format('truetype');
120
- }
121
- @font-face {
122
- font-family: 'MyFont';
123
- font-style: italic;
124
- font-weight: bold;
125
- src: local('MyFont Bold Italic'), local('MyFont-BoldItalic'), url(<?php echo $wpo_wcpdf->export->template_path; ?>/fonts/myfont-bolditalic.ttf) format('truetype');
126
- }
127
- `
128
- then make sure you assign that font family to the body or other elements of the template:
129
- `
130
- font-family: 'MyFont';
131
- `
132
-
133
- Some notes:
134
-
135
- * Only TTF fonts are supported.
136
- * You can't use numeric font weights (like 700 instead of bold)!
137
- * Avoid spaces or special characters in the font filenames.
138
- * I have found that not all servers cope well with the font paths. If this is the case with your font, try to put the font in the root of your site and put that in the font url (i.e. `url(http://yoursite.com/fonts/myfont-italic.ttf)` )
139
-
140
- Some font links:
141
-
142
- * Japanese - http://ipafont.ipa.go.jp/index.html
143
- * Chinese - http://www.study-area.org/apt/firefly-font/
144
-
145
- = How can I display the HTML/CSS source for debugging/developing templates? =
146
- There's a setting on the Status tab of the settings page that allows you to toggle HTML output. Don't forget to turn if off after you're done testing!
147
-
148
- = How can I display custom fields in the invoice or packing slip? =
149
- First, you need to create a custom template following instructions from the first item in this FAQ.
150
- Then place the following snippet where you would like the custom field to appear:
151
-
152
- `
153
- <?php $wpo_wcpdf->custom_field('custom_fieldname', 'Custom field:'); ?>
154
- `
155
-
156
- Where you replace 'custom_fieldname' with the name of the field you want to display, and 'Custom field' with the label. The plugin only displays the field when it contains data. If you also want to display the label when the field is empty, you can pass a third parameter (true), like this:
157
-
158
- `
159
- <?php $wpo_wcpdf->custom_field('custom_fieldname', 'Custom field:', true); ?>
160
- `
161
-
162
- = How can I display order notes in the invoice or packing slip? =
163
- First, you need to create a custom template following instructions from the first item in this FAQ.
164
- Then place the following snippet where you would like the order notes to appear:
165
-
166
- `
167
- <?php $wpo_wcpdf->order_notes(); ?>
168
- `
169
-
170
- if you want to display all order notes, including the (private) admin notes, use:
171
- `
172
- <?php $wpo_wcpdf->order_notes('all'); ?>
173
- `
174
-
175
- = How do can I modify the pdf filename? =
176
- You can do this via a filter in your theme's `functions.php` (Some themes have a "custom functions" area in the settings).
177
-
178
- Here's a simple example for putting your shop name in front of the filname.
179
- `
180
- add_filter( 'wpo_wcpdf_filename', 'wpo_wcpdf_custom_filename', 10, 4 );
181
- function wpo_wcpdf_custom_filename( $filename, $template_type, $order_ids, $context ) {
182
- // prepend your shopname to the file
183
- $new_filename = 'myshopname_' . $filename;
184
-
185
- return $new_filename;
186
- }
187
- `
188
- You can also use the $template_type ('invoice' or 'packing-slip'), $order_ids (single array) or $context ('download' or 'attachment') variables to make more complex rules for the filename.
189
-
190
- = How can I add a download link to the invoice on the Thank you page? =
191
- You can do this with an action in your theme's `functions.php` (Some themes have a "custom functions" area in the settings). Note that due to security restrictions, this will only work for registered/logged in users!
192
-
193
- `
194
- add_filter('woocommerce_thankyou_order_received_text', 'wpo_wcpdf_thank_you_link', 10, 2);
195
- function wpo_wcpdf_thank_you_link( $text, $order ) {
196
- if ( is_user_logged_in() ) {
197
- $pdf_url = wp_nonce_url( admin_url( 'admin-ajax.php?action=generate_wpo_wcpdf&template_type=invoice&order_ids=' . $order->id . '&my-account'), 'generate_wpo_wcpdf' );
198
- $text .= '<p><a href="'.esc_attr($pdf_url).'">Download a printable invoice / payment confirmation (PDF format)</a></p>';
199
- }
200
- return $text;
201
- }
202
- `
203
-
204
- alternatively, you can hook this text to the `woocommerce_thankyou` action, see [this thread](https://wordpress.org/support/topic/suggestion-for-the-faq?replies=5#post-6298810) on the support forum.
205
-
206
- = How can I get a copy of the invoice emailed to the shop manager? =
207
- The easiest way to do this is to just tick the 'new order' box. However, this also means that an invoice will be created for all new orders, also the ones that are never completed.
208
-
209
- Alternatively you can get a (BCC) copy of the completed order email by placing the following filter in your theme's `functions.php` (Some themes have a "custom functions" area in the settings)
210
- Modify the name & email address to your own preferences,
211
-
212
- `
213
- add_filter( 'woocommerce_email_headers', 'mycustom_headers_filter_function', 10, 2);
214
-
215
- function mycustom_headers_filter_function( $headers, $object ) {
216
- if ($object == 'customer_completed_order') {
217
- $headers .= 'BCC: Your name <your@email.com>' . "\r\n"; //just repeat this line again to insert another email address in BCC
218
- }
219
-
220
- return $headers;
221
- }
222
- `
223
-
224
-
225
- = Fatal error: Allowed memory size of ######## bytes exhausted (tried to allocate ### bytes) =
226
-
227
- This usually only happens on batch actions. PDF creation is a memory intensive job, especially if it includes several pages with images. Go to WooCommerce > System Status to check your WP Memory Limit. We recommend setting it to 128mb or more.
228
-
229
- == Screenshots ==
230
-
231
- 1. General settings page
232
- 2. Template settings page
233
- 3. Simple invoice PDF
234
- 4. Simple packing slip PDF
235
-
236
- == Changelog ==
237
-
238
- = 1.5.32 =
239
- * Fix: Updated currency font with Indian Rupee symbol
240
- * Translations: added Formal German (currently a copy of informal German)
241
-
242
- = 1.5.31 =
243
- * Feature: [invoice_day] or [order_day] in invoice number format
244
- * Fix: Link to hide all ads when premium extensions active
245
-
246
- = 1.5.30 =
247
- * Feature: Enable currency font for extended currency support
248
- * Fix: Font sync on plugin update
249
-
250
- = 1.5.29 =
251
- * Translations: Added Croation (Thanks Neven/Spine ICT!), updated French (Thanks Sabra!)
252
- * Tweak: filter shop address before checking if it's empty
253
- * Dev: added $order to `wpo_wcpdf_template_file` filter
254
-
255
- = 1.5.28 =
256
- * Tweak: the 'Next invoice number' is now stored separately in the database for faster and more reliable retrieval. Circumventing any caching, this should prevent duplicate invoice numbers.
257
- * Fix: Bulk actions plugin conflicts
258
- * Experimental: page numbers (use {{PAGE_NUM}} / {{PAGE_COUNT}} in your template)
259
-
260
- = 1.5.27 =
261
- * Feature: Use [invoice_year] and [invoice_month] placeholders in invoice number prefix/suffix
262
- * Feature: WooCommerce Order Status & Actions Manager emails compatibility
263
- * Feature: Add invoice number to WC REST API
264
- * Fix: Allow positive 'discounts' (price corrections)
265
- * Fix: Discounts rounding
266
- * Translations: Updated Finnish & Portugese & POT
267
-
268
- = 1.5.26 =
269
- * Feature: Automatically list all emails registered in WooCommerce
270
- * Feature: Reset invoice number yearly
271
- * Feature: WooCommerce Chained Products compatibility
272
- * Feature: WooCommerce Product Bundles visibility settings taken into account in invoice
273
- * Fix: Disable PDF creation from trashed order_ids
274
- * Tweak: Alert when no orders selected for bulk export (Props to Dartui!)
275
- * Tweak: PDF invoice settings always under WooCommerce menu (also for premium users)
276
- * Tweak: extra $item_id passed in row class filter
277
- * Translations: Updated Slovenian, Spanish, Dutch & POT file
278
-
279
- = 1.5.24 =
280
- * Hotfix: Subscriptions renewal filter arguments
281
-
282
- = 1.5.23 =
283
- * Fix: WooCommerce Subscriptons 2.0 deprecation notice.
284
- * Tweak: better qTranslate-X support
285
- * Tweak: filter for user privileges check (wpo_wcpdf_check_privs)
286
- * Translations: French translations fix
287
-
288
- = 1.5.22 =
289
- * Fix: Workaround for bug in WPML (which cleared all settings)
290
- * Translation: fixed Polish translation for invoice
291
-
292
- = 1.5.21 =
293
- * Translations: Added Estionan (thanks Tanel!)
294
- * Tweak: WC2.4 compatibility
295
-
296
- = 1.5.20 =
297
- * Feature: Option to 'never' display My Account invoice link
298
- * Fix: Order total for refunds in WC2.4
299
- * Fix: notice when no custom statuses selected for My Account display
300
- * Tweak: Product bundles styles
301
-
302
- = 1.5.19 =
303
- * Fix: Invoice number search (broke other custom searches)
304
-
305
- = 1.5.18 =
306
- * Fix: wpo_wcpdf_item_row_class packing slip filter arguments
307
-
308
- = 1.5.17 =
309
- * Feature: WooCommerce Product Bundles compatibility styles
310
- * Tweak: wpo_wcpdf_item_row_class as filter instead of action
311
-
312
- = 1.5.16 =
313
- * Feature: Search orders by invoice number (note: search on formatted invoice number only works for new orders)
314
- * Feature: Formatted invoice number stored in order
315
- * Tweak: Function parameters added to some of the filters
316
- * Tweak: WooCommerce 2.4 compatibility
317
- * Dev feature: action to add class to items table row (wpo_wcpdf_item_row_class)
318
- * Translations: Swedish updated (thanks Conney!)
319
- * Translations: Norwegian updated
320
-
321
- = 1.5.15 =
322
- * Fix: invoice number padding didn't work for values lower than 3
323
- * Tweak: WPML compatibility filter
324
- * Translations: Updated French (Thanks Nicolas!)
325
-
326
- = 1.5.14 =
327
- * Tweak: Invoice number & date edit fields moved to separate box on order edit page
328
- * Translations: Updated POT & Dutch
329
-
330
- = 1.5.13 =
331
- * Fix: Better address comparison to determine when to display alternate address
332
- * Tweak: Filter N/A addresses
333
- * Tweak: Use WooCommerce function for 2.3 discounts
334
- * Translations: Czech Updated (Thanks Ivo!)
335
- * Translations: French (minor fixes)
336
-
337
- = 1.5.12 =
338
- * Translations: added Danish, Updated POT & Italian
339
-
340
- = 1.5.11 =
341
- * Fix: Product text attributes (now checks key too)
342
- * Fix: Status page upload explanation typos
343
-
344
- = 1.5.10 =
345
- * Fix: Double check to make sure plugin doesn't attach to user emails
346
-
347
- = 1.5.9 =
348
- * Feature: Shorthand function to display product attributes: `$wpo_wcpdf->get_product_attribute( $attribute_name, $product )`
349
-
350
- = 1.5.8 =
351
- * Feature: disable invoice for free orders
352
- * Feature: action to insert data before & after item meta
353
- * Tweak: Added classes to sku & weight
354
- * Tweak: Hide payment method from totals (already shown in template)
355
- * Translations: Updated POT & Dutch
356
-
357
- = 1.5.7 =
358
- * Feature: Setting to show email address & phone number on invoice or packing slip (does not work on custom templates based on previous versions!)
359
-
360
- = 1.5.6 =
361
- * Feature: Setting to show shipping address on invoice (does not work on custom templates based on previous versions!)
362
- * Feature: My Account invoice download setting
363
- * Feature: several new template actions
364
- * Tweak: WooCommerce Bookings compatibility
365
- * Tweak: Gerenal stylesheet cleanup
366
- * Fix: temp path check/error on settings page
367
- * Fix: Document titles for credit notes and proforma (Pro)
368
- * Fix: Discount including tax
369
- * Fix: Special characters on item meta (requires WooCommerce 2.3.6)
370
- * Translations: Missing text domain on several strings
371
- * Translations: Updated POT & Dutch
372
-
373
- = 1.5.5 =
374
- * Fix: Check for incomplete line tax data (Subscriptions compatibility)
375
- * Fix: More precise template path instructions
376
- * Fix: duplicate stylesheet filter
377
- * Fix: Always prefer original order's billing address for refunds (WooCommerce EU VAT Number compatibility)
378
- * Translations: Updated German (MwSt. instead of formal Ust.)
379
- * Translations: Updated Dutch
380
-
381
- = 1.5.4 =
382
- * Tweak: include plugin version in style/script includes
383
- * Tweak: upload code cleanup
384
- * Fix: Parent invoice number (for Credit Notes in professional extension)
385
-
386
- = 1.5.3 =
387
- * Feature: add original order date value to order date filter
388
- * Feature: Work with line_tax_data when available
389
- * Feature: pass item_id to items
390
- * Tweak: later check for woocommerce active
391
- * Fix: do not try to validate empty settings (Status page settings)
392
- * Translations: Fixed Dutch typo
393
-
394
- = 1.5.2 =
395
- * Fix: fatal error when trying to activate with WooCommerce not installed yet.
396
- * Tweak: indentation fix on the Simple template
397
-
398
- = 1.5.1 =
399
- * Fix: prevent errors when upgrading
400
-
401
- = 1.5.0 =
402
- * Feature: All temporary files are now stored centrally in the WP uploads folder.
403
- * Feature: Debug settings in status panel (output errors & output to HTML)
404
- * Feature: Compatibility filter for WooCommerce Subscriptions (prevents duplicate invoice numbers)
405
- * Tweak: Pass order to totals filters
406
- * Translations: Updated POT
407
- * Translations: Updated Italian (Thanks Astrid!)
408
- * Translations: Updated Dutch
409
- * FAQ: instructions for placing a link on the thank you page
410
-
411
- = 1.4.14 =
412
- * Fix: fatal error when user registers at checkout (applies to credit notes only)
413
- * Translations: Updated German (Thanks Dietmar!)
414
- * Translations: Place your custom translations in wp-content/languages/woocommerce-pdf-invoices-packing-slips/wpo_wcpdf-LOCALE.mo to protect them from being overwritten by plugin updates.
415
-
416
- = 1.4.13 =
417
- * Feature: use separate file for all your template specific functions (template-functions.php)
418
- * Translations: Added Slovenian (thanks gregy1403!)
419
- * Translations: Updated Norwegian & Dutch.
420
- * Translations: Added Japanese - needs custom font!
421
- * FAQ: instructions on how to use custom fonts
422
-
423
- = 1.4.12 =
424
- * Fix: issues with post parent objects (WC2.1 and older)
425
-
426
- = 1.4.11 =
427
- * Small fix: bulk actions for specific i18n configurations
428
- * Tweak: total row key used as class in Simple template
429
-
430
- = 1.4.10 =
431
- * Fix: Invoice not attaching
432
- * Translations: Updated POT file
433
- * Translations: Updated Dutch, Norwegian, Polish, Brazilian Portugese, Romanian, Russian, Slovak, Spanish & Ukrainian (Many thanks to all the translators!)
434
- * Templates: added action hooks for easier customizations (`wpo_wcpdf_before_order_details`, `wpo_wcpdf_after_order_details`, `wpo_wcpdf_invoice_title` & `wpo_wcpdf_packing_slip_title`)
435
-
436
- = 1.4.9 =
437
- * Feature: Order number and date are now displayed by default in the Simple template (invoice number and date still optional)
438
- * Feature: Display Customer/Order notes with a simple shorthand (see FAQ)
439
- * Translations: Added Brazilian Portugese (thanks Victor Debone!)
440
- * Tweak: Fail more gracefully when there are errors during PDF generation
441
- * Tweak: added template type class to template output body
442
- * Tweak: cleaned up Simple template style.css
443
-
444
- = 1.4.8 =
445
- * Translations: Added Finnish (Thanks Sami Mäkelä/Contrast.fi!)
446
-
447
- = 1.4.7 =
448
- * Fix: check if image file exists locally, fallback to url if not (CDN compatibility)
449
- * Fix: make deleting invoice date possible
450
- * Fix: correct tmp folder check on status page
451
- * Translations: updated po/mo files
452
- * Tweak: changed settings capability requirement to `manage_woocommerce` (was: `manage_options`)
453
- * Tweak: better email attachment function
454
- * Tweak: prevent footer overlap (Simple template)
455
- * Tweak: fallback if `glob()` is not allowed on the server
456
- * Tweak: better custom template instructions (reflects path to actual (child-)theme)
457
-
458
- = 1.4.6 =
459
- * HOTFIX: WooCommerce 2.2 compatibility fix
460
- * Filter for PDF temp folder (wpo_wcpdf_tmp_path)
461
-
462
- = 1.4.5 =
463
- * Fix: Double date conversion for order date on invoice number filter (to avoid i18n date issues)
464
- * Fix: Template selector reset after update
465
- * Translations: added Norwegian (Thanks Aleksander!)
466
-
467
- = 1.4.4 =
468
- * Feature: Editable invoice date per order/invoice.
469
- * Feature: HTML is now allowed in footer and other settings fields.
470
- * Translations: Updated German (Thanks Nadine!)
471
- * Fix: template paths are now saved relative to the site base path (ABSPATH) to prevent errors when moving to another server
472
- * Tweak: Changed bulk action hook for better theme compatibility
473
- * Tweak: Newlines in custom checkout fields
474
-
475
- = 1.4.3 =
476
- * Feature: Added function to call custom fields more easily (see FAQ)
477
- * Feature: Change the my account button text via a filter (wpo_wcpdf_myaccount_button_text)
478
- * Translations: Added Danish (Thanks Mads!)
479
- * Tweak: only load PDF engine if it's not already loaded by another plugin
480
-
481
- = 1.4.2 =
482
- * Fix: Don't create invoice number when exporting packing slips
483
- * Fix: Division by zero for 0 quantity items
484
-
485
- = 1.4.1 =
486
- * Translations: Added Polish (Thanks Mike!)
487
- * Fix: Invoice number formatting notices in debug mode
488
-
489
- = 1.4.0 =
490
- * Feature: Invoice numbers can now be given a prefix, suffix or padding on the settings page!
491
- * Filter: `wpo_wcpdf_email_allowed_statuses` to attach pdf to custom order status emails
492
- * Tweak: Sequential Order Numbers Pro compatibility
493
- * Tweak: Filenames are now automatically sanitized to prevent issues with illegal characters
494
-
495
- = 1.3.2 =
496
- * Fix: error on wpo_wcpdf_email_attachment filter when $pdf_path not set
497
-
498
- = 1.3.1 =
499
- * Fix: invoice number was cleared when Order Actions were being used when an invoice number was not set
500
- * Translations: Updated Slovak (Thanks Jozef!)
501
- * Translations: Added Czech (Thanks CubiQ!)
502
-
503
- = 1.3.0 =
504
- * Feature: Added 'status' panel for better problem diagnosis
505
- * Tweak: split create & get invoice number calls to prevent slow database calls from causing number skipping
506
- * Translations: Added Romanian (Thanks Leonardo!)
507
- * Translations: Added Slovak (Thanks Oleg!)
508
-
509
- = 1.2.13 =
510
- * Feature: added filter for custom email attachment condition (wpo_wcpdf_custom_email_condition)
511
- * Fix: warning for tax implode
512
-
513
- = 1.2.12 =
514
- * Fix: hyperlink underline (was more like a strikethrough)
515
-
516
- = 1.2.11 =
517
- * Translations: Fixed German spelling error
518
- * Translations: Updated Swedish (Thanks Fredrik!)
519
-
520
- = 1.2.10 =
521
- * Translations: Added Swedish (Thanks Jonathan!)
522
- * Fix: Line-height issue (on some systems, the space between lines was very high)
523
-
524
- = 1.2.9 =
525
- * Fix: bug where 'standard' tax class would not display in some cases
526
- * Fix: bug that caused the totals to jump for some font sizes
527
- * Fix: WC2.1 deprecated totals function
528
- * Fix: If multiple taxes were set up with the same name, only one would display (Simple template was not affected)
529
-
530
- = 1.2.8 =
531
- * Template: Body line-height defined to prevent character jumping with italic texts
532
- * Fix: Open Sans now included in plugin package (fixes font issues for servers with allow_url_fopen disabled)
533
-
534
- = 1.2.7 =
535
- * Translations: POT, DE & NL updated
536
- * Fix: Removed stray span tag in totals table
537
-
538
- = 1.2.6 =
539
- * Translations: Spanish update (thanks prepu!)
540
- * Fix: More advanced checks to determine if a customer can download the invoice (including a status filter)
541
-
542
- = 1.2.5 =
543
- * Feature: Optional Invoice Number column for the orders listing
544
- * Feature: Better support for international characters
545
- * Translations: Added Russian & Ukrainian translation (thanks Oleg!)
546
- * Translations: Updated Spanish (Thanks Manuel!) and Dutch translations & POT file
547
- * Tweak: Memory limit notice
548
- * Tweak: Filename name now includes invoice number (when configured in the settings)
549
-
550
- = 1.2.4 =
551
- * Feature: Set which type of emails you want to attach the invoice to
552
-
553
- = 1.2.3 =
554
- * Feature: Manually edit invoice number on the edit order screen
555
- * Feature: Set the first (/next) invoice number on the settings screen
556
- * Fix: Bug where invoice number would be generated twice due to slow database calls
557
- * Fix: php strict warnings
558
-
559
- = 1.2.2 =
560
- * Feature: Simple template now uses Open Sans to include more international special characters
561
- * Feature: Implemented filters for paper size & orientation ([read here](http://wordpress.org/support/topic/select-a5-paper-size-for-packing-slips?replies=5#post-5211129))
562
- * Tweak: PDF engine updated (dompdf 0.6.0)
563
- * Tweak: Download PDF link on the my account page is now only shown when an invoice is already created by the admin or automatically, to prevent unwanted invoice created (creating problems with european laws).
564
-
565
- = 1.2.1 =
566
- * Fix: shipping & fees functions didn't output correctly with the tax set to 'incl'
567
-
568
- = 1.2.0 =
569
- * Feature: Sequential invoice numbers (set upon invoice creation).
570
- * Feature: Invoice date (set upon invoice creation).
571
-
572
- = 1.1.6 =
573
- * Feature: Hungarian translations added - thanks Joseph!
574
- * Tweak: Better debug code.
575
- * Tweak: Error reporting when templates not found.
576
- * Fix: tax rate calculation for free items.
577
-
578
- = 1.1.5 =
579
- * Feature: German translations added - thanks Christian!
580
- * Fix: dompdf 0.6.0 proved to be less stable, so switching back to beta3 for now.
581
-
582
- = 1.1.4 =
583
- * Fix: Template paths on windows servers were not properly saved (stripslashes), resulting in an empty output.
584
-
585
- = 1.1.3 =
586
- * Feature: PDF engine (dompdf) updated to 0.6.0 for better stability and utf-8 support.
587
- * Tweak: Local server path is used for header image for better compatibility with server settings.
588
- * Fix: several small bugs.
589
-
590
- = 1.1.2 =
591
- * Feature: Totals can now be called with simpler template functions
592
- * Feature: Italian translations - thanks max66max!
593
- * Tweak: improved memory performance
594
-
595
- = 1.1.1 =
596
- * Feature: French translations - thanks Guillaume!
597
-
598
- = 1.1.0 =
599
- * Feature: Fees can now also be called ex. VAT
600
- * Feature: Invoices can now be downloaded from the My Account page
601
- * Feature: Spanish translation & POT file included
602
- * Fix: ternary statements that caused an error
603
-
604
- = 1.0.1 =
605
- * Tweak: Packing slip now displays shipping address instead of billing address
606
- * Tweak: Variation data is now displayed by default
607
-
608
- = 1.0.0 =
609
- * First release
610
-
611
- == Upgrade Notice ==
612
-
613
- = 1.5 =
614
- Version 1.5 changes where temporary files are stored - everything is now stored centrally in the WP uploads folder. For backwards compatibility, this feature is turned off by default, but we recommend to use the new folders. Check the plugin Status panel for more information!
 
 
 
 
1
+ === Plugin Name ===
2
+ 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.5
6
+ Stable tag: 1.5.33
7
+ License: GPLv2 or later
8
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
+
10
+ Create, print & automatically email PDF invoices & packing slips for WooCommerce orders.
11
+
12
+ == Description ==
13
+
14
+ This WooCommerce extension automatically adds a PDF invoice to the order confirmation emails sent out to your customers. Includes a basic template (additional templates are available from [WP Overnight](https://wpovernight.com/downloads/woocommerce-pdf-invoices-packing-slips-premium-templates/)) as well as the possibility to modify/create your own templates. In addition, you can choose to download or print invoices and packing slips from the WooCommerce order admin.
15
+
16
+ = Main features =
17
+ * Automatically attach invoice PDF to WooCommerce emails of your choice
18
+ * Download the PDF invoice / packing slip from the order admin page
19
+ * Generate PDF invoices / packings slips in bulk
20
+ * **Fully customizable** HTML/CSS invoice templates
21
+ * Download invoices from the My Account page
22
+ * Sequential invoice numbers - with custom formatting
23
+ * **Available in: Czech, Dutch, English, Finnish, French, German, Hungarian, Italian, Japanese (see FAQ for adding custom fonts!), Norwegian, Polish, Romanian, Russian, Slovak, Slovenian, Spanish, Swedish & Ukrainian**
24
+
25
+ In addition to this, we offer several premium extensions:
26
+
27
+ * 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/)
28
+ * Upload all invoices automatically to Dropbox with [WooCommerce PDF Invoices & Packing Slips to Dropbox](https://wpovernight.com/downloads/woocommerce-pdf-invoices-packing-slips-dropbox/)
29
+ * 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)
30
+ * More advanced & stylish templates with [WooCommerce PDF Invoices & Packing Slips Premium Templates](https://wpovernight.com/downloads/woocommerce-pdf-invoices-packing-slips-premium-templates/)
31
+
32
+ = Fully customizable =
33
+ In addition to a number of default settings (including a custom header/logo) and several layout fields that you can use out of the box, the plugin contains HTML/CSS based templates that allow for customization & full control over the PDF output. Copy the templates to your theme folder and you don't have to worry that your customizations will be overwritten when you update the plugin.
34
+
35
+ * Insert customer header image/logo
36
+ * Modify shop data / footer / disclaimer etc. on the invoices & packing slips
37
+ * Select paper size (Letter or A4)
38
+ * Translation ready
39
+
40
+ == Installation ==
41
+
42
+ = Minimum Requirements =
43
+
44
+ * WooCommerce 2.0 or later
45
+ * WordPress 3.5 or later
46
+
47
+ = Automatic installation =
48
+ Automatic installation is the easiest option as WordPress handles the file transfers itself and you don't even need to leave your web browser. To do an automatic install of WooCommerce PDF Invoices & Packing Slips, log in to your WordPress admin panel, navigate to the Plugins menu and click Add New.
49
+
50
+ In the search field type "WooCommerce PDF Invoices & Packing Slips" and click Search Plugins. You can install it by simply clicking Install Now. After clicking that link you will be asked if you're sure you want to install the plugin. Click yes and WordPress will automatically complete the installation. After installation has finished, click the 'activate plugin' link.
51
+
52
+ = Manual installation via the WordPress interface =
53
+ 1. Download the plugin zip file to your computer
54
+ 2. Go to the WordPress admin panel menu Plugins > Add New
55
+ 3. Choose upload
56
+ 4. Upload the plugin zip file, the plugin will now be installed
57
+ 5. After installation has finished, click the 'activate plugin' link
58
+
59
+ = Manual installation via FTP =
60
+ 1. Download the plugin file to your computer and unzip it
61
+ 2. Using an FTP program, or your hosting control panel, upload the unzipped plugin folder to your WordPress installation's wp-content/plugins/ directory.
62
+ 3. Activate the plugin from the Plugins menu within the WordPress admin.
63
+
64
+ == Frequently Asked Questions ==
65
+
66
+ Make sure to check out [WooCommerce PDF Invoices & Packing Slips documentation](http://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/) on our site - it covers most of the questions below (and more!) in more detail!
67
+
68
+ = How do I create my own custom template? =
69
+
70
+ Copy the files from `wp-content/plugins/woocommerce-pdf-invoices-packing-slips/templates/pdf/Simple/` to your (child) theme in `wp-content/themes/yourtheme/woocommerce/pdf/yourtemplate` and customize them there. The new template will show up as 'yourtemplate' (the folder name) in the settings panel.
71
+
72
+ = Where can I find more templates? =
73
+
74
+ Go to [wpovernight.com](https://wpovernight.com/downloads/woocommerce-pdf-invoices-packing-slips-premium-templates/) to checkout more templates! These include templates with more tax details and product thumbnails. Need a custom templates? Contact us at support@wpovernight.com for more information.
75
+
76
+ = Can I create/send a proforma invoice or a credit note? =
77
+ This is a feature of our Professional extension, which can be found at [wpovernight.com](https://wpovernight.com/downloads/woocommerce-pdf-invoices-packing-slips-professional/)
78
+
79
+ = Can I contribute to the code? =
80
+ You're more than welcome! This plugin is hosted on github, where you can post issues or make pull requests.
81
+ https://github.com/wpovernight/woocommerce-pdf-invoices-packing-slips
82
+
83
+ = My language is not included, how can I contribute? =
84
+
85
+ This plugin is translation ready, which means that you can translate it using standard WordPress methods.
86
+
87
+ 1. Download POEdit at (http://www.poedit.net/download.php)
88
+ 2. Open POEdit
89
+ 3. File > New from POT
90
+ 4. Open wpo_wcpdf.pot (from `woocommerce-pdf-invoices-packing-slips/languages/`)
91
+ 5. A popup will ask you for your language
92
+ 6. This step is a bit tricky, configuring the plurals. Somehow the settings can't be copied from the pot. Go to Catalogue > Preferences. Then enter nplurals=2; plural=n != 1; in the custom expression field
93
+ 7. Enter the translations. invoice and packing-slip now have two translation fields, single & plural. Note that this is a filename, so replace spaces with a - just to be sure!
94
+ 8. Save as `wpo_wcpdf-xx_XX.po`, where you replace xx_XX with your language code & country code suffix (da_DK, pl_PL, de_DE etc.)
95
+
96
+ = How can I use my own font? =
97
+ Although the plugin supports webfonts, this is somewhat limited and has a lot of caveats, read [this thread](https://wordpress.org/support/topic/webfonts-within-a-custom-template-not-rendering-in-pdf?replies=4#post-5395442) on the forum.
98
+ Some languages (Japanese, Chinese, etc.) are not supported by the default font included with the plugin, in this case a custom font is required.
99
+ The best method is to create a custom template first (see above), then add a `fonts/` folder to that template and use the following code (replace the font names/filenames) to load the font in the style.css from the pdf template:
100
+ `
101
+ <?php global $wpo_wcpdf;?>
102
+ /* Load font */
103
+ @font-face {
104
+ font-family: 'MyFont';
105
+ font-style: normal;
106
+ font-weight: normal;
107
+ src: local('MyFont'), local('MyFont'), url(<?php echo $wpo_wcpdf->export->template_path; ?>/fonts/myfont.ttf) format('truetype');
108
+ }
109
+ @font-face {
110
+ font-family: 'MyFont';
111
+ font-style: normal;
112
+ font-weight: bold;
113
+ src: local('MyFont Bold'), local('MyFont-Bold'), url(<?php echo $wpo_wcpdf->export->template_path; ?>/fonts/myfont-bold.ttf) format('truetype');
114
+ }
115
+ @font-face {
116
+ font-family: 'MyFont';
117
+ font-style: italic;
118
+ font-weight: normal;
119
+ src: local('MyFont Italic'), local('MyFont-Italic'), url(<?php echo $wpo_wcpdf->export->template_path; ?>/fonts/myfont-italic.ttf) format('truetype');
120
+ }
121
+ @font-face {
122
+ font-family: 'MyFont';
123
+ font-style: italic;
124
+ font-weight: bold;
125
+ src: local('MyFont Bold Italic'), local('MyFont-BoldItalic'), url(<?php echo $wpo_wcpdf->export->template_path; ?>/fonts/myfont-bolditalic.ttf) format('truetype');
126
+ }
127
+ `
128
+ then make sure you assign that font family to the body or other elements of the template:
129
+ `
130
+ font-family: 'MyFont';
131
+ `
132
+
133
+ Some notes:
134
+
135
+ * Only TTF fonts are supported.
136
+ * You can't use numeric font weights (like 700 instead of bold)!
137
+ * Avoid spaces or special characters in the font filenames.
138
+ * I have found that not all servers cope well with the font paths. If this is the case with your font, try to put the font in the root of your site and put that in the font url (i.e. `url(http://yoursite.com/fonts/myfont-italic.ttf)` )
139
+
140
+ Some font links:
141
+
142
+ * Japanese - http://ipafont.ipa.go.jp/index.html
143
+ * Chinese - http://www.study-area.org/apt/firefly-font/
144
+
145
+ = How can I display the HTML/CSS source for debugging/developing templates? =
146
+ There's a setting on the Status tab of the settings page that allows you to toggle HTML output. Don't forget to turn if off after you're done testing!
147
+
148
+ = How can I display custom fields in the invoice or packing slip? =
149
+ First, you need to create a custom template following instructions from the first item in this FAQ.
150
+ Then place the following snippet where you would like the custom field to appear:
151
+
152
+ `
153
+ <?php $wpo_wcpdf->custom_field('custom_fieldname', 'Custom field:'); ?>
154
+ `
155
+
156
+ Where you replace 'custom_fieldname' with the name of the field you want to display, and 'Custom field' with the label. The plugin only displays the field when it contains data. If you also want to display the label when the field is empty, you can pass a third parameter (true), like this:
157
+
158
+ `
159
+ <?php $wpo_wcpdf->custom_field('custom_fieldname', 'Custom field:', true); ?>
160
+ `
161
+
162
+ = How can I display order notes in the invoice or packing slip? =
163
+ First, you need to create a custom template following instructions from the first item in this FAQ.
164
+ Then place the following snippet where you would like the order notes to appear:
165
+
166
+ `
167
+ <?php $wpo_wcpdf->order_notes(); ?>
168
+ `
169
+
170
+ if you want to display all order notes, including the (private) admin notes, use:
171
+ `
172
+ <?php $wpo_wcpdf->order_notes('all'); ?>
173
+ `
174
+
175
+ = How do can I modify the pdf filename? =
176
+ You can do this via a filter in your theme's `functions.php` (Some themes have a "custom functions" area in the settings).
177
+
178
+ Here's a simple example for putting your shop name in front of the filname.
179
+ `
180
+ add_filter( 'wpo_wcpdf_filename', 'wpo_wcpdf_custom_filename', 10, 4 );
181
+ function wpo_wcpdf_custom_filename( $filename, $template_type, $order_ids, $context ) {
182
+ // prepend your shopname to the file
183
+ $new_filename = 'myshopname_' . $filename;
184
+
185
+ return $new_filename;
186
+ }
187
+ `
188
+ You can also use the $template_type ('invoice' or 'packing-slip'), $order_ids (single array) or $context ('download' or 'attachment') variables to make more complex rules for the filename.
189
+
190
+ = How can I add a download link to the invoice on the Thank you page? =
191
+ You can do this with an action in your theme's `functions.php` (Some themes have a "custom functions" area in the settings). Note that due to security restrictions, this will only work for registered/logged in users!
192
+
193
+ `
194
+ add_filter('woocommerce_thankyou_order_received_text', 'wpo_wcpdf_thank_you_link', 10, 2);
195
+ function wpo_wcpdf_thank_you_link( $text, $order ) {
196
+ if ( is_user_logged_in() ) {
197
+ $pdf_url = wp_nonce_url( admin_url( 'admin-ajax.php?action=generate_wpo_wcpdf&template_type=invoice&order_ids=' . $order->id . '&my-account'), 'generate_wpo_wcpdf' );
198
+ $text .= '<p><a href="'.esc_attr($pdf_url).'">Download a printable invoice / payment confirmation (PDF format)</a></p>';
199
+ }
200
+ return $text;
201
+ }
202
+ `
203
+
204
+ alternatively, you can hook this text to the `woocommerce_thankyou` action, see [this thread](https://wordpress.org/support/topic/suggestion-for-the-faq?replies=5#post-6298810) on the support forum.
205
+
206
+ = How can I get a copy of the invoice emailed to the shop manager? =
207
+ The easiest way to do this is to just tick the 'new order' box. However, this also means that an invoice will be created for all new orders, also the ones that are never completed.
208
+
209
+ Alternatively you can get a (BCC) copy of the completed order email by placing the following filter in your theme's `functions.php` (Some themes have a "custom functions" area in the settings)
210
+ Modify the name & email address to your own preferences,
211
+
212
+ `
213
+ add_filter( 'woocommerce_email_headers', 'mycustom_headers_filter_function', 10, 2);
214
+
215
+ function mycustom_headers_filter_function( $headers, $object ) {
216
+ if ($object == 'customer_completed_order') {
217
+ $headers .= 'BCC: Your name <your@email.com>' . "\r\n"; //just repeat this line again to insert another email address in BCC
218
+ }
219
+
220
+ return $headers;
221
+ }
222
+ `
223
+
224
+
225
+ = Fatal error: Allowed memory size of ######## bytes exhausted (tried to allocate ### bytes) =
226
+
227
+ This usually only happens on batch actions. PDF creation is a memory intensive job, especially if it includes several pages with images. Go to WooCommerce > System Status to check your WP Memory Limit. We recommend setting it to 128mb or more.
228
+
229
+ == Screenshots ==
230
+
231
+ 1. General settings page
232
+ 2. Template settings page
233
+ 3. Simple invoice PDF
234
+ 4. Simple packing slip PDF
235
+
236
+ == Changelog ==
237
+
238
+ = 1.5.33 =
239
+ * Tweak: Don't apply 'disable free' setting to packing slip attachment
240
+ * Translations: Updated Romanian
241
+
242
+ = 1.5.32 =
243
+ * Fix: Updated currency font with Indian Rupee symbol
244
+ * Translations: added Formal German (currently a copy of informal German)
245
+
246
+ = 1.5.31 =
247
+ * Feature: [invoice_day] or [order_day] in invoice number format
248
+ * Fix: Link to hide all ads when premium extensions active
249
+
250
+ = 1.5.30 =
251
+ * Feature: Enable currency font for extended currency support
252
+ * Fix: Font sync on plugin update
253
+
254
+ = 1.5.29 =
255
+ * Translations: Added Croation (Thanks Neven/Spine ICT!), updated French (Thanks Sabra!)
256
+ * Tweak: filter shop address before checking if it's empty
257
+ * Dev: added $order to `wpo_wcpdf_template_file` filter
258
+
259
+ = 1.5.28 =
260
+ * Tweak: the 'Next invoice number' is now stored separately in the database for faster and more reliable retrieval. Circumventing any caching, this should prevent duplicate invoice numbers.
261
+ * Fix: Bulk actions plugin conflicts
262
+ * Experimental: page numbers (use {{PAGE_NUM}} / {{PAGE_COUNT}} in your template)
263
+
264
+ = 1.5.27 =
265
+ * Feature: Use [invoice_year] and [invoice_month] placeholders in invoice number prefix/suffix
266
+ * Feature: WooCommerce Order Status & Actions Manager emails compatibility
267
+ * Feature: Add invoice number to WC REST API
268
+ * Fix: Allow positive 'discounts' (price corrections)
269
+ * Fix: Discounts rounding
270
+ * Translations: Updated Finnish & Portugese & POT
271
+
272
+ = 1.5.26 =
273
+ * Feature: Automatically list all emails registered in WooCommerce
274
+ * Feature: Reset invoice number yearly
275
+ * Feature: WooCommerce Chained Products compatibility
276
+ * Feature: WooCommerce Product Bundles visibility settings taken into account in invoice
277
+ * Fix: Disable PDF creation from trashed order_ids
278
+ * Tweak: Alert when no orders selected for bulk export (Props to Dartui!)
279
+ * Tweak: PDF invoice settings always under WooCommerce menu (also for premium users)
280
+ * Tweak: extra $item_id passed in row class filter
281
+ * Translations: Updated Slovenian, Spanish, Dutch & POT file
282
+
283
+ = 1.5.24 =
284
+ * Hotfix: Subscriptions renewal filter arguments
285
+
286
+ = 1.5.23 =
287
+ * Fix: WooCommerce Subscriptons 2.0 deprecation notice.
288
+ * Tweak: better qTranslate-X support
289
+ * Tweak: filter for user privileges check (wpo_wcpdf_check_privs)
290
+ * Translations: French translations fix
291
+
292
+ = 1.5.22 =
293
+ * Fix: Workaround for bug in WPML (which cleared all settings)
294
+ * Translation: fixed Polish translation for invoice
295
+
296
+ = 1.5.21 =
297
+ * Translations: Added Estionan (thanks Tanel!)
298
+ * Tweak: WC2.4 compatibility
299
+
300
+ = 1.5.20 =
301
+ * Feature: Option to 'never' display My Account invoice link
302
+ * Fix: Order total for refunds in WC2.4
303
+ * Fix: notice when no custom statuses selected for My Account display
304
+ * Tweak: Product bundles styles
305
+
306
+ = 1.5.19 =
307
+ * Fix: Invoice number search (broke other custom searches)
308
+
309
+ = 1.5.18 =
310
+ * Fix: wpo_wcpdf_item_row_class packing slip filter arguments
311
+
312
+ = 1.5.17 =
313
+ * Feature: WooCommerce Product Bundles compatibility styles
314
+ * Tweak: wpo_wcpdf_item_row_class as filter instead of action
315
+
316
+ = 1.5.16 =
317
+ * Feature: Search orders by invoice number (note: search on formatted invoice number only works for new orders)
318
+ * Feature: Formatted invoice number stored in order
319
+ * Tweak: Function parameters added to some of the filters
320
+ * Tweak: WooCommerce 2.4 compatibility
321
+ * Dev feature: action to add class to items table row (wpo_wcpdf_item_row_class)
322
+ * Translations: Swedish updated (thanks Conney!)
323
+ * Translations: Norwegian updated
324
+
325
+ = 1.5.15 =
326
+ * Fix: invoice number padding didn't work for values lower than 3
327
+ * Tweak: WPML compatibility filter
328
+ * Translations: Updated French (Thanks Nicolas!)
329
+
330
+ = 1.5.14 =
331
+ * Tweak: Invoice number & date edit fields moved to separate box on order edit page
332
+ * Translations: Updated POT & Dutch
333
+
334
+ = 1.5.13 =
335
+ * Fix: Better address comparison to determine when to display alternate address
336
+ * Tweak: Filter N/A addresses
337
+ * Tweak: Use WooCommerce function for 2.3 discounts
338
+ * Translations: Czech Updated (Thanks Ivo!)
339
+ * Translations: French (minor fixes)
340
+
341
+ = 1.5.12 =
342
+ * Translations: added Danish, Updated POT & Italian
343
+
344
+ = 1.5.11 =
345
+ * Fix: Product text attributes (now checks key too)
346
+ * Fix: Status page upload explanation typos
347
+
348
+ = 1.5.10 =
349
+ * Fix: Double check to make sure plugin doesn't attach to user emails
350
+
351
+ = 1.5.9 =
352
+ * Feature: Shorthand function to display product attributes: `$wpo_wcpdf->get_product_attribute( $attribute_name, $product )`
353
+
354
+ = 1.5.8 =
355
+ * Feature: disable invoice for free orders
356
+ * Feature: action to insert data before & after item meta
357
+ * Tweak: Added classes to sku & weight
358
+ * Tweak: Hide payment method from totals (already shown in template)
359
+ * Translations: Updated POT & Dutch
360
+
361
+ = 1.5.7 =
362
+ * Feature: Setting to show email address & phone number on invoice or packing slip (does not work on custom templates based on previous versions!)
363
+
364
+ = 1.5.6 =
365
+ * Feature: Setting to show shipping address on invoice (does not work on custom templates based on previous versions!)
366
+ * Feature: My Account invoice download setting
367
+ * Feature: several new template actions
368
+ * Tweak: WooCommerce Bookings compatibility
369
+ * Tweak: Gerenal stylesheet cleanup
370
+ * Fix: temp path check/error on settings page
371
+ * Fix: Document titles for credit notes and proforma (Pro)
372
+ * Fix: Discount including tax
373
+ * Fix: Special characters on item meta (requires WooCommerce 2.3.6)
374
+ * Translations: Missing text domain on several strings
375
+ * Translations: Updated POT & Dutch
376
+
377
+ = 1.5.5 =
378
+ * Fix: Check for incomplete line tax data (Subscriptions compatibility)
379
+ * Fix: More precise template path instructions
380
+ * Fix: duplicate stylesheet filter
381
+ * Fix: Always prefer original order's billing address for refunds (WooCommerce EU VAT Number compatibility)
382
+ * Translations: Updated German (MwSt. instead of formal Ust.)
383
+ * Translations: Updated Dutch
384
+
385
+ = 1.5.4 =
386
+ * Tweak: include plugin version in style/script includes
387
+ * Tweak: upload code cleanup
388
+ * Fix: Parent invoice number (for Credit Notes in professional extension)
389
+
390
+ = 1.5.3 =
391
+ * Feature: add original order date value to order date filter
392
+ * Feature: Work with line_tax_data when available
393
+ * Feature: pass item_id to items
394
+ * Tweak: later check for woocommerce active
395
+ * Fix: do not try to validate empty settings (Status page settings)
396
+ * Translations: Fixed Dutch typo
397
+
398
+ = 1.5.2 =
399
+ * Fix: fatal error when trying to activate with WooCommerce not installed yet.
400
+ * Tweak: indentation fix on the Simple template
401
+
402
+ = 1.5.1 =
403
+ * Fix: prevent errors when upgrading
404
+
405
+ = 1.5.0 =
406
+ * Feature: All temporary files are now stored centrally in the WP uploads folder.
407
+ * Feature: Debug settings in status panel (output errors & output to HTML)
408
+ * Feature: Compatibility filter for WooCommerce Subscriptions (prevents duplicate invoice numbers)
409
+ * Tweak: Pass order to totals filters
410
+ * Translations: Updated POT
411
+ * Translations: Updated Italian (Thanks Astrid!)
412
+ * Translations: Updated Dutch
413
+ * FAQ: instructions for placing a link on the thank you page
414
+
415
+ = 1.4.14 =
416
+ * Fix: fatal error when user registers at checkout (applies to credit notes only)
417
+ * Translations: Updated German (Thanks Dietmar!)
418
+ * Translations: Place your custom translations in wp-content/languages/woocommerce-pdf-invoices-packing-slips/wpo_wcpdf-LOCALE.mo to protect them from being overwritten by plugin updates.
419
+
420
+ = 1.4.13 =
421
+ * Feature: use separate file for all your template specific functions (template-functions.php)
422
+ * Translations: Added Slovenian (thanks gregy1403!)
423
+ * Translations: Updated Norwegian & Dutch.
424
+ * Translations: Added Japanese - needs custom font!
425
+ * FAQ: instructions on how to use custom fonts
426
+
427
+ = 1.4.12 =
428
+ * Fix: issues with post parent objects (WC2.1 and older)
429
+
430
+ = 1.4.11 =
431
+ * Small fix: bulk actions for specific i18n configurations
432
+ * Tweak: total row key used as class in Simple template
433
+
434
+ = 1.4.10 =
435
+ * Fix: Invoice not attaching
436
+ * Translations: Updated POT file
437
+ * Translations: Updated Dutch, Norwegian, Polish, Brazilian Portugese, Romanian, Russian, Slovak, Spanish & Ukrainian (Many thanks to all the translators!)
438
+ * Templates: added action hooks for easier customizations (`wpo_wcpdf_before_order_details`, `wpo_wcpdf_after_order_details`, `wpo_wcpdf_invoice_title` & `wpo_wcpdf_packing_slip_title`)
439
+
440
+ = 1.4.9 =
441
+ * Feature: Order number and date are now displayed by default in the Simple template (invoice number and date still optional)
442
+ * Feature: Display Customer/Order notes with a simple shorthand (see FAQ)
443
+ * Translations: Added Brazilian Portugese (thanks Victor Debone!)
444
+ * Tweak: Fail more gracefully when there are errors during PDF generation
445
+ * Tweak: added template type class to template output body
446
+ * Tweak: cleaned up Simple template style.css
447
+
448
+ = 1.4.8 =
449
+ * Translations: Added Finnish (Thanks Sami Mäkelä/Contrast.fi!)
450
+
451
+ = 1.4.7 =
452
+ * Fix: check if image file exists locally, fallback to url if not (CDN compatibility)
453
+ * Fix: make deleting invoice date possible
454
+ * Fix: correct tmp folder check on status page
455
+ * Translations: updated po/mo files
456
+ * Tweak: changed settings capability requirement to `manage_woocommerce` (was: `manage_options`)
457
+ * Tweak: better email attachment function
458
+ * Tweak: prevent footer overlap (Simple template)
459
+ * Tweak: fallback if `glob()` is not allowed on the server
460
+ * Tweak: better custom template instructions (reflects path to actual (child-)theme)
461
+
462
+ = 1.4.6 =
463
+ * HOTFIX: WooCommerce 2.2 compatibility fix
464
+ * Filter for PDF temp folder (wpo_wcpdf_tmp_path)
465
+
466
+ = 1.4.5 =
467
+ * Fix: Double date conversion for order date on invoice number filter (to avoid i18n date issues)
468
+ * Fix: Template selector reset after update
469
+ * Translations: added Norwegian (Thanks Aleksander!)
470
+
471
+ = 1.4.4 =
472
+ * Feature: Editable invoice date per order/invoice.
473
+ * Feature: HTML is now allowed in footer and other settings fields.
474
+ * Translations: Updated German (Thanks Nadine!)
475
+ * Fix: template paths are now saved relative to the site base path (ABSPATH) to prevent errors when moving to another server
476
+ * Tweak: Changed bulk action hook for better theme compatibility
477
+ * Tweak: Newlines in custom checkout fields
478
+
479
+ = 1.4.3 =
480
+ * Feature: Added function to call custom fields more easily (see FAQ)
481
+ * Feature: Change the my account button text via a filter (wpo_wcpdf_myaccount_button_text)
482
+ * Translations: Added Danish (Thanks Mads!)
483
+ * Tweak: only load PDF engine if it's not already loaded by another plugin
484
+
485
+ = 1.4.2 =
486
+ * Fix: Don't create invoice number when exporting packing slips
487
+ * Fix: Division by zero for 0 quantity items
488
+
489
+ = 1.4.1 =
490
+ * Translations: Added Polish (Thanks Mike!)
491
+ * Fix: Invoice number formatting notices in debug mode
492
+
493
+ = 1.4.0 =
494
+ * Feature: Invoice numbers can now be given a prefix, suffix or padding on the settings page!
495
+ * Filter: `wpo_wcpdf_email_allowed_statuses` to attach pdf to custom order status emails
496
+ * Tweak: Sequential Order Numbers Pro compatibility
497
+ * Tweak: Filenames are now automatically sanitized to prevent issues with illegal characters
498
+
499
+ = 1.3.2 =
500
+ * Fix: error on wpo_wcpdf_email_attachment filter when $pdf_path not set
501
+
502
+ = 1.3.1 =
503
+ * Fix: invoice number was cleared when Order Actions were being used when an invoice number was not set
504
+ * Translations: Updated Slovak (Thanks Jozef!)
505
+ * Translations: Added Czech (Thanks CubiQ!)
506
+
507
+ = 1.3.0 =
508
+ * Feature: Added 'status' panel for better problem diagnosis
509
+ * Tweak: split create & get invoice number calls to prevent slow database calls from causing number skipping
510
+ * Translations: Added Romanian (Thanks Leonardo!)
511
+ * Translations: Added Slovak (Thanks Oleg!)
512
+
513
+ = 1.2.13 =
514
+ * Feature: added filter for custom email attachment condition (wpo_wcpdf_custom_email_condition)
515
+ * Fix: warning for tax implode
516
+
517
+ = 1.2.12 =
518
+ * Fix: hyperlink underline (was more like a strikethrough)
519
+
520
+ = 1.2.11 =
521
+ * Translations: Fixed German spelling error
522
+ * Translations: Updated Swedish (Thanks Fredrik!)
523
+
524
+ = 1.2.10 =
525
+ * Translations: Added Swedish (Thanks Jonathan!)
526
+ * Fix: Line-height issue (on some systems, the space between lines was very high)
527
+
528
+ = 1.2.9 =
529
+ * Fix: bug where 'standard' tax class would not display in some cases
530
+ * Fix: bug that caused the totals to jump for some font sizes
531
+ * Fix: WC2.1 deprecated totals function
532
+ * Fix: If multiple taxes were set up with the same name, only one would display (Simple template was not affected)
533
+
534
+ = 1.2.8 =
535
+ * Template: Body line-height defined to prevent character jumping with italic texts
536
+ * Fix: Open Sans now included in plugin package (fixes font issues for servers with allow_url_fopen disabled)
537
+
538
+ = 1.2.7 =
539
+ * Translations: POT, DE & NL updated
540
+ * Fix: Removed stray span tag in totals table
541
+
542
+ = 1.2.6 =
543
+ * Translations: Spanish update (thanks prepu!)
544
+ * Fix: More advanced checks to determine if a customer can download the invoice (including a status filter)
545
+
546
+ = 1.2.5 =
547
+ * Feature: Optional Invoice Number column for the orders listing
548
+ * Feature: Better support for international characters
549
+ * Translations: Added Russian & Ukrainian translation (thanks Oleg!)
550
+ * Translations: Updated Spanish (Thanks Manuel!) and Dutch translations & POT file
551
+ * Tweak: Memory limit notice
552
+ * Tweak: Filename name now includes invoice number (when configured in the settings)
553
+
554
+ = 1.2.4 =
555
+ * Feature: Set which type of emails you want to attach the invoice to
556
+
557
+ = 1.2.3 =
558
+ * Feature: Manually edit invoice number on the edit order screen
559
+ * Feature: Set the first (/next) invoice number on the settings screen
560
+ * Fix: Bug where invoice number would be generated twice due to slow database calls
561
+ * Fix: php strict warnings
562
+
563
+ = 1.2.2 =
564
+ * Feature: Simple template now uses Open Sans to include more international special characters
565
+ * Feature: Implemented filters for paper size & orientation ([read here](http://wordpress.org/support/topic/select-a5-paper-size-for-packing-slips?replies=5#post-5211129))
566
+ * Tweak: PDF engine updated (dompdf 0.6.0)
567
+ * Tweak: Download PDF link on the my account page is now only shown when an invoice is already created by the admin or automatically, to prevent unwanted invoice created (creating problems with european laws).
568
+
569
+ = 1.2.1 =
570
+ * Fix: shipping & fees functions didn't output correctly with the tax set to 'incl'
571
+
572
+ = 1.2.0 =
573
+ * Feature: Sequential invoice numbers (set upon invoice creation).
574
+ * Feature: Invoice date (set upon invoice creation).
575
+
576
+ = 1.1.6 =
577
+ * Feature: Hungarian translations added - thanks Joseph!
578
+ * Tweak: Better debug code.
579
+ * Tweak: Error reporting when templates not found.
580
+ * Fix: tax rate calculation for free items.
581
+
582
+ = 1.1.5 =
583
+ * Feature: German translations added - thanks Christian!
584
+ * Fix: dompdf 0.6.0 proved to be less stable, so switching back to beta3 for now.
585
+
586
+ = 1.1.4 =
587
+ * Fix: Template paths on windows servers were not properly saved (stripslashes), resulting in an empty output.
588
+
589
+ = 1.1.3 =
590
+ * Feature: PDF engine (dompdf) updated to 0.6.0 for better stability and utf-8 support.
591
+ * Tweak: Local server path is used for header image for better compatibility with server settings.
592
+ * Fix: several small bugs.
593
+
594
+ = 1.1.2 =
595
+ * Feature: Totals can now be called with simpler template functions
596
+ * Feature: Italian translations - thanks max66max!
597
+ * Tweak: improved memory performance
598
+
599
+ = 1.1.1 =
600
+ * Feature: French translations - thanks Guillaume!
601
+
602
+ = 1.1.0 =
603
+ * Feature: Fees can now also be called ex. VAT
604
+ * Feature: Invoices can now be downloaded from the My Account page
605
+ * Feature: Spanish translation & POT file included
606
+ * Fix: ternary statements that caused an error
607
+
608
+ = 1.0.1 =
609
+ * Tweak: Packing slip now displays shipping address instead of billing address
610
+ * Tweak: Variation data is now displayed by default
611
+
612
+ = 1.0.0 =
613
+ * First release
614
+
615
+ == Upgrade Notice ==
616
+
617
+ = 1.5 =
618
+ Version 1.5 changes where temporary files are stored - everything is now stored centrally in the WP uploads folder. For backwards compatibility, this feature is turned off by default, but we recommend to use the new folders. Check the plugin Status panel for more information!
woocommerce-pdf-invoices-packingslips.php CHANGED
@@ -1,989 +1,989 @@
1
- <?php
2
- /**
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.5.32
7
- * Author: Ewout Fernhout
8
- * Author URI: http://www.wpovernight.com
9
- * License: GPLv2 or later
10
- * License URI: http://www.opensource.org/licenses/gpl-license.php
11
- * Text Domain: wpo_wcpdf
12
- */
13
-
14
- if ( !class_exists( 'WooCommerce_PDF_Invoices' ) ) {
15
-
16
- class WooCommerce_PDF_Invoices {
17
-
18
- public static $plugin_prefix;
19
- public static $plugin_url;
20
- public static $plugin_path;
21
- public static $plugin_basename;
22
- public static $version;
23
-
24
- public $writepanels;
25
- public $settings;
26
- public $export;
27
-
28
- /**
29
- * Constructor
30
- */
31
- public function __construct() {
32
- self::$plugin_prefix = 'wpo_wcpdf_';
33
- self::$plugin_basename = plugin_basename(__FILE__);
34
- self::$plugin_url = plugin_dir_url(self::$plugin_basename);
35
- self::$plugin_path = trailingslashit(dirname(__FILE__));
36
- self::$version = '1.5.32';
37
-
38
- // load the localisation & classes
39
- add_action( 'plugins_loaded', array( $this, 'translations' ) ); // or use init?
40
- add_action( 'init', array( $this, 'load_classes' ) );
41
-
42
- // run lifecycle methods
43
- if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
44
- // check if upgrading from versionless (1.4.14 and older)
45
- if ( get_option('wpo_wcpdf_general_settings') && get_option('wpo_wcpdf_version') === false ) {
46
- // tag 'versionless', so that we can apply necessary upgrade settings
47
- add_option( 'wpo_wcpdf_version', 'versionless' );
48
- }
49
-
50
- add_action( 'wp_loaded', array( $this, 'do_install' ) );
51
- }
52
- }
53
-
54
- /**
55
- * Load the translation / textdomain files
56
- *
57
- * Note: the first-loaded translation file overrides any following ones if the same translation is present
58
- */
59
- public function translations() {
60
- $locale = apply_filters( 'plugin_locale', get_locale(), 'wpo_wcpdf' );
61
- $dir = trailingslashit( WP_LANG_DIR );
62
-
63
- /**
64
- * Frontend/global Locale. Looks in:
65
- *
66
- * - WP_LANG_DIR/woocommerce-pdf-invoices-packing-slips/wpo_wcpdf-LOCALE.mo
67
- * - WP_LANG_DIR/plugins/wpo_wcpdf-LOCALE.mo
68
- * - woocommerce-pdf-invoices-packing-slips/languages/wpo_wcpdf-LOCALE.mo (which if not found falls back to:)
69
- * - WP_LANG_DIR/plugins/wpo_wcpdf-LOCALE.mo
70
- */
71
- load_textdomain( 'wpo_wcpdf', $dir . 'woocommerce-pdf-invoices-packing-slips/wpo_wcpdf-' . $locale . '.mo' );
72
- load_textdomain( 'wpo_wcpdf', $dir . 'plugins/wpo_wcpdf-' . $locale . '.mo' );
73
- load_plugin_textdomain( 'wpo_wcpdf', false, dirname( self::$plugin_basename ) . '/languages' );
74
- }
75
-
76
- /**
77
- * Load the main plugin classes and functions
78
- */
79
- public function includes() {
80
- include_once( 'includes/class-wcpdf-settings.php' );
81
- include_once( 'includes/class-wcpdf-writepanels.php' );
82
- include_once( 'includes/class-wcpdf-export.php' );
83
- }
84
-
85
-
86
- /**
87
- * Instantiate classes when woocommerce is activated
88
- */
89
- public function load_classes() {
90
- if ( $this->is_woocommerce_activated() ) {
91
- $this->includes();
92
- $this->settings = new WooCommerce_PDF_Invoices_Settings();
93
- $this->writepanels = new WooCommerce_PDF_Invoices_Writepanels();
94
- $this->export = new WooCommerce_PDF_Invoices_Export();
95
- } else {
96
- // display notice instead
97
- add_action( 'admin_notices', array ( $this, 'need_woocommerce' ) );
98
- }
99
-
100
- }
101
-
102
- /**
103
- * Check if woocommerce is activated
104
- */
105
- public function is_woocommerce_activated() {
106
- $blog_plugins = get_option( 'active_plugins', array() );
107
- $site_plugins = get_site_option( 'active_sitewide_plugins', array() );
108
-
109
- if ( in_array( 'woocommerce/woocommerce.php', $blog_plugins ) || isset( $site_plugins['woocommerce/woocommerce.php'] ) ) {
110
- return true;
111
- } else {
112
- return false;
113
- }
114
- }
115
-
116
- /**
117
- * WooCommerce not active notice.
118
- *
119
- * @return string Fallack notice.
120
- */
121
-
122
- public function need_woocommerce() {
123
- $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>' );
124
-
125
- $message = '<div class="error"><p>' . $error . '</p></div>';
126
-
127
- echo $message;
128
- }
129
-
130
- /** Lifecycle methods *******************************************************
131
- * Because register_activation_hook only runs when the plugin is manually
132
- * activated by the user, we're checking the current version against the
133
- * version stored in the database
134
- ****************************************************************************/
135
-
136
- /**
137
- * Handles version checking
138
- */
139
- public function do_install() {
140
- // only install when woocommerce is active
141
- if ( !$this->is_woocommerce_activated() ) {
142
- return;
143
- }
144
-
145
- $version_setting = 'wpo_wcpdf_version';
146
- $installed_version = get_option( $version_setting );
147
-
148
- // installed version lower than plugin version?
149
- if ( version_compare( $installed_version, self::$version, '<' ) ) {
150
-
151
- if ( ! $installed_version ) {
152
- $this->install();
153
- } else {
154
- $this->upgrade( $installed_version );
155
- }
156
-
157
- // new version number
158
- update_option( $version_setting, self::$version );
159
- }
160
- }
161
-
162
-
163
- /**
164
- * Plugin install method. Perform any installation tasks here
165
- */
166
- protected function install() {
167
- // Create temp folders
168
- $tmp_base = $this->export->get_tmp_base();
169
-
170
- // check if tmp folder exists => if not, initialize
171
- if ( !@is_dir( $tmp_base ) ) {
172
- $this->export->init_tmp( $tmp_base );
173
- }
174
-
175
- }
176
-
177
-
178
- /**
179
- * Plugin upgrade method. Perform any required upgrades here
180
- *
181
- * @param string $installed_version the currently installed version
182
- */
183
- protected function upgrade( $installed_version ) {
184
- if ( $installed_version == 'versionless') { // versionless = 1.4.14 and older
185
- // We're upgrading from an old version, so we're enabling the option to use the plugin tmp folder.
186
- // This is not per se the 'best' solution, but the good thing is that nothing is changed
187
- // and nothing will be broken (that wasn't broken before)
188
- $default = array( 'old_tmp' => 1 );
189
- update_option( 'wpo_wcpdf_debug_settings', $default );
190
- }
191
-
192
- // sync fonts on every upgrade!
193
- $debug_settings = get_option( 'wpo_wcpdf_debug_settings' ); // get temp setting
194
-
195
- // do not copy if old_tmp function active! (double check for slow databases)
196
- if ( !( isset($debug_settings['old_tmp']) || $installed_version == 'versionless' ) ) {
197
- $tmp_base = $this->export->get_tmp_base();
198
-
199
- // check if tmp folder exists => if not, initialize
200
- if ( !@is_dir( $tmp_base ) ) {
201
- $this->export->init_tmp( $tmp_base );
202
- }
203
-
204
- $font_path = $tmp_base . 'fonts/';
205
- $this->export->copy_fonts( $font_path );
206
- }
207
-
208
- // 1.5.28 update: copy next invoice number to separate setting
209
- if ( $installed_version == 'versionless' || version_compare( $installed_version, '1.5.28', '<' ) ) {
210
- $template_settings = get_option( 'wpo_wcpdf_template_settings' );
211
- $next_invoice_number = isset($template_settings['next_invoice_number'])?$template_settings['next_invoice_number']:'';
212
- update_option( 'wpo_wcpdf_next_invoice_number', $next_invoice_number );
213
- }
214
- }
215
-
216
- /***********************************************************************/
217
- /********************** GENERAL TEMPLATE FUNCTIONS *********************/
218
- /***********************************************************************/
219
-
220
- /**
221
- * Get template name from slug
222
- */
223
- public function get_template_name ( $template_type ) {
224
- switch ( $template_type ) {
225
- case 'invoice':
226
- $template_name = apply_filters( 'wpo_wcpdf_invoice_title', __( 'Invoice', 'wpo_wcpdf' ) );
227
- break;
228
- case 'packing-slip':
229
- $template_name = apply_filters( 'wpo_wcpdf_packing_slip_title', __( 'Packing Slip', 'wpo_wcpdf' ) );
230
- break;
231
- default:
232
- // try to 'unslug' the name
233
- $template_name = ucwords( str_replace( array( '_', '-' ), ' ', $template_type ) );
234
- break;
235
- }
236
-
237
- return apply_filters( 'wpo_wcpdf_template_name', $template_name, $template_type );
238
- }
239
-
240
- /**
241
- * Output template styles
242
- */
243
- public function template_styles() {
244
- $css = apply_filters( 'wpo_wcpdf_template_styles_file', $this->export->template_path. '/' .'style.css' );
245
-
246
- ob_start();
247
- if (file_exists($css)) {
248
- include($css);
249
- }
250
- $html = ob_get_clean();
251
- $html = apply_filters( 'wpo_wcpdf_template_styles', $html );
252
-
253
- echo $html;
254
- }
255
-
256
- /**
257
- * Return logo id
258
- */
259
- public function get_header_logo_id() {
260
- if (isset($this->settings->template_settings['header_logo'])) {
261
- return apply_filters( 'wpo_wcpdf_header_logo_id', $this->settings->template_settings['header_logo'] );
262
- }
263
- }
264
-
265
- /**
266
- * Show logo html
267
- */
268
- public function header_logo() {
269
- if ($this->get_header_logo_id()) {
270
- $attachment_id = $this->get_header_logo_id();
271
- $company = isset($this->settings->template_settings['shop_name'])? $this->settings->template_settings['shop_name'] : '';
272
- if( $attachment_id ) {
273
- $attachment = wp_get_attachment_image_src( $attachment_id, 'full', false );
274
-
275
- $attachment_src = $attachment[0];
276
- $attachment_width = $attachment[1];
277
- $attachment_height = $attachment[2];
278
-
279
- $attachment_path = get_attached_file( $attachment_id );
280
-
281
- if ( apply_filters('wpo_wcpdf_use_path', true) && file_exists($attachment_path) ) {
282
- $src = $attachment_path;
283
- } else {
284
- $src = $attachment_src;
285
- }
286
-
287
- printf('<img src="%1$s" width="%2$d" height="%3$d" alt="%4$s" />', $src, $attachment_width, $attachment_height, esc_attr( $company ) );
288
- }
289
- }
290
- }
291
-
292
- /**
293
- * Return/Show custom company name or default to blog name
294
- */
295
- public function get_shop_name() {
296
- if (!empty($this->settings->template_settings['shop_name'])) {
297
- $name = trim( $this->settings->template_settings['shop_name'] );
298
- return apply_filters( 'wpo_wcpdf_shop_name', wptexturize( $name ) );
299
- } else {
300
- return apply_filters( 'wpo_wcpdf_shop_name', get_bloginfo( 'name' ) );
301
- }
302
- }
303
- public function shop_name() {
304
- echo $this->get_shop_name();
305
- }
306
-
307
- /**
308
- * Return/Show shop/company address if provided
309
- */
310
- public function get_shop_address() {
311
- $shop_address = apply_filters( 'wpo_wcpdf_shop_address', wpautop( wptexturize( $this->settings->template_settings['shop_address'] ) ) );
312
- if (!empty($shop_address)) {
313
- return $shop_address;
314
- } else {
315
- return false;
316
- }
317
- }
318
- public function shop_address() {
319
- echo $this->get_shop_address();
320
- }
321
-
322
- /**
323
- * Check if billing address and shipping address are equal
324
- */
325
- public function ships_to_different_address() {
326
- // always prefer parent address for refunds
327
- if ( get_post_type( $this->export->order->id ) == 'shop_order_refund' && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
328
- // temporarily switch order to make all filters / order calls work correctly
329
- $order_meta = get_post_meta( $parent_order_id );
330
- } else {
331
- $order_meta = get_post_meta( $this->export->order->id );
332
- }
333
-
334
- $address_comparison_fields = apply_filters( 'wpo_wcpdf_address_comparison_fields', array(
335
- 'first_name',
336
- 'last_name',
337
- 'company',
338
- 'address_1',
339
- 'address_2',
340
- 'city',
341
- 'state',
342
- 'postcode',
343
- 'country'
344
- ) );
345
-
346
- foreach ($address_comparison_fields as $address_field) {
347
- $billing_field = isset( $order_meta['_billing_'.$address_field] ) ? $order_meta['_billing_'.$address_field] : '';
348
- $shipping_field = isset( $order_meta['_shipping_'.$address_field] ) ? $order_meta['_shipping_'.$address_field] : '';
349
- if ( $shipping_field != $billing_field ) {
350
- // this address field is different -> ships to different address!
351
- return true;
352
- }
353
- }
354
-
355
- //if we got here, it means the addresses are equal -> doesn't ship to different address!
356
- return apply_filters( 'wpo_wcpdf_ships_to_different_address', false, $order_meta );
357
- }
358
-
359
- /**
360
- * Return/Show billing address
361
- */
362
- public function get_billing_address() {
363
- // always prefer parent billing address for refunds
364
- if ( get_post_type( $this->export->order->id ) == 'shop_order_refund' && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
365
- // temporarily switch order to make all filters / order calls work correctly
366
- $current_order = $this->export->order;
367
- $this->export->order = new WC_Order( $parent_order_id );
368
- $address = apply_filters( 'wpo_wcpdf_billing_address', $this->export->order->get_formatted_billing_address() );
369
- // switch back & unset
370
- $this->export->order = $current_order;
371
- unset($current_order);
372
- } elseif ( $address = $this->export->order->get_formatted_billing_address() ) {
373
- // regular shop_order
374
- $address = apply_filters( 'wpo_wcpdf_billing_address', $address );
375
- } else {
376
- // no address
377
- $address = apply_filters( 'wpo_wcpdf_billing_address', __('N/A', 'wpo_wcpdf') );
378
- }
379
-
380
- return $address;
381
- }
382
- public function billing_address() {
383
- echo $this->get_billing_address();
384
- }
385
-
386
- /**
387
- * Return/Show billing email
388
- */
389
- public function get_billing_email() {
390
- $billing_email = $this->export->order->billing_email;
391
-
392
- if ( !$billing_email && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
393
- // try parent
394
- $billing_email = get_post_meta( $parent_order_id, '_billing_email', true );
395
- }
396
-
397
- return apply_filters( 'wpo_wcpdf_billing_email', $billing_email );
398
- }
399
- public function billing_email() {
400
- echo $this->get_billing_email();
401
- }
402
-
403
- /**
404
- * Return/Show billing phone
405
- */
406
- public function get_billing_phone() {
407
- $billing_phone = $this->export->order->billing_phone;
408
-
409
- if ( !$billing_phone && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
410
- // try parent
411
- $billing_phone = get_post_meta( $parent_order_id, '_billing_phone', true );
412
- }
413
-
414
- return apply_filters( 'wpo_wcpdf_billing_phone', $billing_phone );
415
- }
416
- public function billing_phone() {
417
- echo $this->get_billing_phone();
418
- }
419
-
420
- /**
421
- * Return/Show shipping address
422
- */
423
- public function get_shipping_address() {
424
- // always prefer parent shipping address for refunds
425
- if ( get_post_type( $this->export->order->id ) == 'shop_order_refund' && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
426
- // temporarily switch order to make all filters / order calls work correctly
427
- $current_order = $this->export->order;
428
- $this->export->order = new WC_Order( $parent_order_id );
429
- $address = apply_filters( 'wpo_wcpdf_shipping_address', $this->export->order->get_formatted_shipping_address() );
430
- // switch back & unset
431
- $this->export->order = $current_order;
432
- unset($current_order);
433
- } elseif ( $address = $this->export->order->get_formatted_shipping_address() ) {
434
- // regular shop_order
435
- $address = apply_filters( 'wpo_wcpdf_shipping_address', $address );
436
- } else {
437
- // no address
438
- $address = apply_filters( 'wpo_wcpdf_shipping_address', __('N/A', 'wpo_wcpdf') );
439
- }
440
-
441
- return $address;
442
- }
443
- public function shipping_address() {
444
- echo $this->get_shipping_address();
445
- }
446
-
447
- /**
448
- * Return/Show a custom field
449
- */
450
- public function get_custom_field( $field_name ) {
451
- $custom_field = get_post_meta($this->export->order->id,$field_name,true);
452
-
453
- if ( !$custom_field && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
454
- // try parent
455
- $custom_field = get_post_meta( $parent_order_id, $field_name, true );
456
- }
457
-
458
- return apply_filters( 'wpo_wcpdf_billing_custom_field', $custom_field );
459
- }
460
- public function custom_field( $field_name, $field_label = '', $display_empty = false ) {
461
- $custom_field = $this->get_custom_field( $field_name );
462
- if (!empty($field_label)){
463
- // add a a trailing space to the label
464
- $field_label .= ' ';
465
- }
466
-
467
- if (!empty($custom_field) || $display_empty) {
468
- echo $field_label . nl2br ($custom_field);
469
- }
470
- }
471
-
472
- /**
473
- * Return/Show order notes
474
- */
475
- public function get_order_notes( $filter = 'customer' ) {
476
- if ( get_post_type( $this->export->order->id ) == 'shop_order_refund' && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
477
- $post_id = $parent_order_id;
478
- } else {
479
- $post_id = $this->export->order->id;
480
- }
481
-
482
- $args = array(
483
- 'post_id' => $post_id,
484
- 'approve' => 'approve',
485
- 'type' => 'order_note'
486
- );
487
-
488
- remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 );
489
-
490
- $notes = get_comments( $args );
491
-
492
- add_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 );
493
-
494
- if ( $notes ) {
495
- foreach( $notes as $key => $note ) {
496
- if ( $filter == 'customer' && !get_comment_meta( $note->comment_ID, 'is_customer_note', true ) ) {
497
- unset($notes[$key]);
498
- }
499
- if ( $filter == 'private' && get_comment_meta( $note->comment_ID, 'is_customer_note', true ) ) {
500
- unset($notes[$key]);
501
- }
502
- }
503
- return $notes;
504
- }
505
- }
506
- public function order_notes( $filter = 'customer' ) {
507
- $notes = $this->get_order_notes( $filter );
508
- if ( $notes ) {
509
- foreach( $notes as $note ) {
510
- ?>
511
- <div class="note_content">
512
- <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?>
513
- </div>
514
- <?php
515
- }
516
- }
517
- }
518
-
519
- /**
520
- * Return/Show the current date
521
- */
522
- public function get_current_date() {
523
- return apply_filters( 'wpo_wcpdf_date', date_i18n( get_option( 'date_format' ) ) );
524
- }
525
- public function current_date() {
526
- echo $this->get_current_date();
527
- }
528
-
529
- /**
530
- * Return/Show payment method
531
- */
532
- public function get_payment_method() {
533
- $payment_method_label = __( 'Payment method', 'wpo_wcpdf' );
534
-
535
- $payment_method = __( $this->export->order->payment_method_title, 'woocommerce' );
536
- if ( !$payment_method && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
537
- // try parent
538
- $payment_method = get_post_meta( $parent_order_id, '_payment_method_title', true );
539
- $payment_method = __( $payment_method, 'woocommerce' );
540
- }
541
-
542
- return apply_filters( 'wpo_wcpdf_payment_method', $payment_method );
543
- }
544
- public function payment_method() {
545
- echo $this->get_payment_method();
546
- }
547
-
548
- /**
549
- * Return/Show shipping method
550
- */
551
- public function get_shipping_method() {
552
- $shipping_method_label = __( 'Shipping method', 'wpo_wcpdf' );
553
- return apply_filters( 'wpo_wcpdf_shipping_method', __( $this->export->order->get_shipping_method(), 'woocommerce' ) );
554
- }
555
- public function shipping_method() {
556
- echo $this->get_shipping_method();
557
- }
558
-
559
- /**
560
- * Return/Show order number
561
- */
562
- public function get_order_number() {
563
- // try parent first
564
- if ( get_post_type( $this->export->order->id ) == 'shop_order_refund' && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
565
- $parent_order = new WC_Order( $parent_order_id );
566
- $order_number = $parent_order->get_order_number();
567
- } else {
568
- $order_number = $this->export->order->get_order_number();
569
- }
570
-
571
- // Trim the hash to have a clean number but still
572
- // support any filters that were applied before.
573
- $order_number = ltrim($order_number, '#');
574
- return apply_filters( 'wpo_wcpdf_order_number', $order_number);
575
- }
576
- public function order_number() {
577
- echo $this->get_order_number();
578
- }
579
-
580
- /**
581
- * Return/Show invoice number
582
- */
583
- public function get_invoice_number() {
584
- // try parent first
585
- if ( get_post_type( $this->export->order->id ) == 'shop_order_refund' && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
586
- $invoice_number = $this->export->get_invoice_number( $parent_order_id );
587
- } else {
588
- $invoice_number = $this->export->get_invoice_number( $this->export->order->id );
589
- }
590
-
591
- return $invoice_number;
592
- }
593
- public function invoice_number() {
594
- echo $this->get_invoice_number();
595
- }
596
-
597
- /**
598
- * Return/Show the order date
599
- */
600
- public function get_order_date() {
601
- if ( get_post_type( $this->export->order->id ) == 'shop_order_refund' && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
602
- $parent_order = new WC_Order( $parent_order_id );
603
- $order_date = $parent_order->order_date;
604
- } else {
605
- $order_date = $this->export->order->order_date;
606
- }
607
-
608
- $date = date_i18n( get_option( 'date_format' ), strtotime( $order_date ) );
609
- return apply_filters( 'wpo_wcpdf_order_date', $date, $order_date );
610
- }
611
- public function order_date() {
612
- echo $this->get_order_date();
613
- }
614
-
615
- /**
616
- * Return/Show the invoice date
617
- */
618
- public function get_invoice_date() {
619
- $invoice_date = get_post_meta($this->export->order->id,'_wcpdf_invoice_date',true);
620
-
621
- // add invoice date if it doesn't exist
622
- if ( empty($invoice_date) || !isset($invoice_date) ) {
623
- $invoice_date = current_time('mysql');
624
- update_post_meta( $this->export->order->id, '_wcpdf_invoice_date', $invoice_date );
625
- }
626
-
627
- $formatted_invoice_date = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) );
628
-
629
- return apply_filters( 'wpo_wcpdf_invoice_date', $formatted_invoice_date, $invoice_date );
630
- }
631
- public function invoice_date() {
632
- echo $this->get_invoice_date();
633
- }
634
-
635
- /**
636
- * Return the order items
637
- */
638
- public function get_order_items() {
639
- return apply_filters( 'wpo_wcpdf_order_items', $this->export->get_order_items() );
640
- }
641
-
642
- /**
643
- * Return/show product attribute
644
- */
645
- public function get_product_attribute( $attribute_name, $product ) {
646
- // first, check the text attributes
647
- $attributes = $product->get_attributes();
648
- $attribute_key = @wc_attribute_taxonomy_name( $attribute_name );
649
- if (array_key_exists( sanitize_title( $attribute_name ), $attributes) ) {
650
- $attribute = $product->get_attribute ( $attribute_name );
651
- return $attribute;
652
- } elseif (array_key_exists( sanitize_title( $attribute_key ), $attributes) ) {
653
- $attribute = $product->get_attribute ( $attribute_key );
654
- return $attribute;
655
- }
656
-
657
- // not a text attribute, try attribute taxonomy
658
- $attribute_key = @wc_attribute_taxonomy_name( $attribute_name );
659
- $product_terms = @wc_get_product_terms( $product->id, $attribute_key, array( 'fields' => 'names' ) );
660
- // check if not empty, then display
661
- if ( !empty($product_terms) ) {
662
- $attribute = array_shift( $product_terms );
663
- return $attribute;
664
- } else {
665
- // no attribute under this name
666
- return false;
667
- }
668
- }
669
- public function product_attribute( $attribute_name, $product ) {
670
- echo $this->get_product_attribute( $attribute_name, $product );
671
- }
672
-
673
-
674
- /**
675
- * Return the order totals listing
676
- */
677
- public function get_woocommerce_totals() {
678
- // get totals and remove the semicolon
679
- $totals = apply_filters( 'wpo_wcpdf_raw_order_totals', $this->export->order->get_order_item_totals(), $this->export->order );
680
-
681
- // remove the colon for every label
682
- foreach ( $totals as $key => $total ) {
683
- $label = $total['label'];
684
- $colon = strrpos( $label, ':' );
685
- if( $colon !== false ) {
686
- $label = substr_replace( $label, '', $colon, 1 );
687
- }
688
- $totals[$key]['label'] = $label;
689
- }
690
-
691
- // WC2.4 fix order_total for refunded orders
692
- if ( version_compare( WOOCOMMERCE_VERSION, '2.4', '>=' ) && isset($totals['order_total']) ) {
693
- $tax_display = $this->export->order->tax_display_cart;
694
- $totals['order_total']['value'] = wc_price( $this->export->order->get_total(), array( 'currency' => $this->export->order->get_order_currency() ) );
695
- $order_total = $this->export->order->get_total();
696
- $tax_string = '';
697
-
698
- // Tax for inclusive prices
699
- if ( wc_tax_enabled() && 'incl' == $tax_display ) {
700
- $tax_string_array = array();
701
-
702
- if ( 'itemized' == get_option( 'woocommerce_tax_total_display' ) ) {
703
- foreach ( $this->export->order->get_tax_totals() as $code => $tax ) {
704
- $tax_amount = $tax->formatted_amount;
705
- $tax_string_array[] = sprintf( '%s %s', $tax_amount, $tax->label );
706
- }
707
- } else {
708
- $tax_string_array[] = sprintf( '%s %s', wc_price( $this->export->order->get_total_tax() - $this->export->order->get_total_tax_refunded(), array( 'currency' => $this->export->order->get_order_currency() ) ), WC()->countries->tax_or_vat() );
709
- }
710
- if ( ! empty( $tax_string_array ) ) {
711
- $tax_string = ' ' . sprintf( __( '(Includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) );
712
- }
713
- }
714
-
715
- $totals['order_total']['value'] .= $tax_string;
716
- }
717
-
718
- // remove refund lines (shouldn't be in invoice)
719
- foreach ( $totals as $key => $total ) {
720
- if ( strpos($key, 'refund_') !== false ) {
721
- unset( $totals[$key] );
722
- }
723
- }
724
-
725
- return apply_filters( 'wpo_wcpdf_woocommerce_totals', $totals, $this->export->order );
726
- }
727
-
728
- /**
729
- * Return/show the order subtotal
730
- */
731
- public function get_order_subtotal( $tax = 'excl', $discount = 'incl' ) { // set $tax to 'incl' to include tax, same for $discount
732
- //$compound = ($discount == 'incl')?true:false;
733
-
734
- $subtotal = $this->export->order->get_subtotal_to_display( false, $tax );
735
-
736
- $subtotal = ($pos = strpos($subtotal, ' <small>')) ? substr($subtotal, 0, $pos) : $subtotal; //removing the 'excluding tax' text
737
-
738
- $subtotal = array (
739
- 'label' => __('Subtotal', 'wpo_wcpdf'),
740
- 'value' => $subtotal,
741
- );
742
-
743
- return apply_filters( 'wpo_wcpdf_order_subtotal', $subtotal, $tax, $discount );
744
- }
745
- public function order_subtotal( $tax = 'excl', $discount = 'incl' ) {
746
- $subtotal = $this->get_order_subtotal( $tax, $discount );
747
- echo $subtotal['value'];
748
- }
749
-
750
- /**
751
- * Return/show the order shipping costs
752
- */
753
- public function get_order_shipping( $tax = 'excl' ) { // set $tax to 'incl' to include tax
754
- if ($tax == 'excl' ) {
755
- $shipping_costs = $this->export->wc_price( $this->export->order->order_shipping );
756
- } else {
757
- $shipping_costs = $this->export->wc_price( $this->export->order->order_shipping + $this->export->order->order_shipping_tax );
758
- }
759
-
760
- $shipping = array (
761
- 'label' => __('Shipping', 'wpo_wcpdf'),
762
- 'value' => $shipping_costs,
763
- 'tax' => $this->export->wc_price( $this->export->order->order_shipping_tax ),
764
- );
765
- return apply_filters( 'wpo_wcpdf_order_shipping', $shipping, $tax );
766
- }
767
- public function order_shipping( $tax = 'excl' ) {
768
- $shipping = $this->get_order_shipping( $tax );
769
- echo $shipping['value'];
770
- }
771
-
772
- /**
773
- * Return/show the total discount
774
- */
775
- public function get_order_discount( $type = 'total', $tax = 'incl' ) {
776
- if ( $tax == 'incl' ) {
777
- switch ($type) {
778
- case 'cart':
779
- // Cart Discount - pre-tax discounts. (deprecated in WC2.3)
780
- $discount_value = $this->export->order->get_cart_discount();
781
- break;
782
- case 'order':
783
- // Order Discount - post-tax discounts. (deprecated in WC2.3)
784
- $discount_value = $this->export->order->get_order_discount();
785
- break;
786
- case 'total':
787
- // Total Discount
788
- if ( version_compare( WOOCOMMERCE_VERSION, '2.3' ) >= 0 ) {
789
- $discount_value = $this->export->order->get_total_discount( false ); // $ex_tax = false
790
- } else {
791
- // WC2.2 and older: recalculate to include tax
792
- $discount_value = 0;
793
- $items = $this->export->order->get_items();;
794
- if( sizeof( $items ) > 0 ) {
795
- foreach( $items as $item ) {
796
- $discount_value += ($item['line_subtotal'] + $item['line_subtotal_tax']) - ($item['line_total'] + $item['line_tax']);
797
- }
798
- }
799
- }
800
-
801
- break;
802
- default:
803
- // Total Discount - Cart & Order Discounts combined
804
- $discount_value = $this->export->order->get_total_discount();
805
- break;
806
- }
807
- } else { // calculate discount excluding tax
808
- if ( version_compare( WOOCOMMERCE_VERSION, '2.3' ) >= 0 ) {
809
- $discount_value = $this->export->order->get_total_discount( true ); // $ex_tax = true
810
- } else {
811
- // WC2.2 and older: recalculate to exclude tax
812
- $discount_value = 0;
813
-
814
- $items = $this->export->order->get_items();;
815
- if( sizeof( $items ) > 0 ) {
816
- foreach( $items as $item ) {
817
- $discount_value += ($item['line_subtotal'] - $item['line_total']);
818
- }
819
- }
820
- }
821
- }
822
-
823
- $discount = array (
824
- 'label' => __('Discount', 'wpo_wcpdf'),
825
- 'value' => $this->export->wc_price($discount_value),
826
- 'raw_value' => $discount_value,
827
- );
828
-
829
- if ( round( $discount_value, 3 ) != 0 ) {
830
- return apply_filters( 'wpo_wcpdf_order_discount', $discount, $type, $tax );
831
- }
832
- }
833
- public function order_discount( $type = 'total', $tax = 'incl' ) {
834
- $discount = $this->get_order_discount( $type, $tax );
835
- echo $discount['value'];
836
- }
837
-
838
- /**
839
- * Return the order fees
840
- */
841
- public function get_order_fees( $tax = 'excl' ) {
842
- if ( $wcfees = $this->export->order->get_fees() ) {
843
- foreach( $wcfees as $id => $fee ) {
844
- if ($tax == 'excl' ) {
845
- $fee_price = $this->export->wc_price( $fee['line_total'] );
846
- } else {
847
- $fee_price = $this->export->wc_price( $fee['line_total'] + $fee['line_tax'] );
848
- }
849
-
850
- $fees[ $id ] = array(
851
- 'label' => $fee['name'],
852
- 'value' => $fee_price,
853
- 'line_total' => $this->export->wc_price($fee['line_total']),
854
- 'line_tax' => $this->export->wc_price($fee['line_tax'])
855
- );
856
- }
857
- return $fees;
858
- }
859
- }
860
-
861
- /**
862
- * Return the order taxes
863
- */
864
- public function get_order_taxes() {
865
- $tax_label = __( 'VAT', 'wpo_wcpdf' ); // register alternate label translation
866
- $tax_label = __( 'Tax rate', 'wpo_wcpdf' );
867
- $tax_rate_ids = $this->export->get_tax_rate_ids();
868
- if ($this->export->order->get_taxes()) {
869
- foreach ( $this->export->order->get_taxes() as $key => $tax ) {
870
- $taxes[ $key ] = array(
871
- 'label' => isset( $tax[ 'label' ] ) ? $tax[ 'label' ] : $tax[ 'name' ],
872
- 'value' => $this->export->wc_price( ( $tax[ 'tax_amount' ] + $tax[ 'shipping_tax_amount' ] ) ),
873
- 'rate_id' => $tax['rate_id'],
874
- 'tax_amount' => $tax['tax_amount'],
875
- 'shipping_tax_amount' => $tax['shipping_tax_amount'],
876
- 'rate' => isset( $tax_rate_ids[ $tax['rate_id'] ] ) ? ( (float) $tax_rate_ids[$tax['rate_id']]['tax_rate'] ) . ' %': '',
877
- );
878
- }
879
-
880
- return apply_filters( 'wpo_wcpdf_order_taxes', $taxes );
881
- }
882
- }
883
-
884
- /**
885
- * Return/show the order grand total
886
- */
887
- public function get_order_grand_total( $tax = 'incl' ) {
888
- if ( version_compare( WOOCOMMERCE_VERSION, '2.1' ) >= 0 ) {
889
- // WC 2.1 or newer is used
890
- $total_unformatted = $this->export->order->get_total();
891
- } else {
892
- // Backwards compatibility
893
- $total_unformatted = $this->export->order->get_order_total();
894
- }
895
-
896
- if ($tax == 'excl' ) {
897
- $total_tax = 0;
898
- foreach ( $this->export->order->get_taxes() as $tax ) {
899
- $total_tax += ( $tax[ 'tax_amount' ] + $tax[ 'shipping_tax_amount' ] );
900
- }
901
-
902
- $total = $this->export->wc_price( ( $total_unformatted - $total_tax ) );
903
- $label = __( 'Total ex. VAT', 'wpo_wcpdf' );
904
- } else {
905
- $total = $this->export->wc_price( ( $total_unformatted ) );
906
- $label = __( 'Total', 'wpo_wcpdf' );
907
- }
908
-
909
- $grand_total = array(
910
- 'label' => $label,
911
- 'value' => $total,
912
- );
913
-
914
- return apply_filters( 'wpo_wcpdf_order_grand_total', $grand_total, $tax );
915
- }
916
- public function order_grand_total( $tax = 'incl' ) {
917
- $grand_total = $this->get_order_grand_total( $tax );
918
- echo $grand_total['value'];
919
- }
920
-
921
-
922
- /**
923
- * Return/Show shipping notes
924
- */
925
- public function get_shipping_notes() {
926
- $shipping_notes = wpautop( wptexturize( $this->export->order->customer_note ) );
927
- return apply_filters( 'wpo_wcpdf_shipping_notes', $shipping_notes );
928
- }
929
- public function shipping_notes() {
930
- echo $this->get_shipping_notes();
931
- }
932
-
933
-
934
- /**
935
- * Return/Show shop/company footer imprint, copyright etc.
936
- */
937
- public function get_footer() {
938
- if (isset($this->settings->template_settings['footer'])) {
939
- $footer = wpautop( wptexturize( $this->settings->template_settings[ 'footer' ] ) );
940
- return apply_filters( 'wpo_wcpdf_footer', $footer );
941
- }
942
- }
943
- public function footer() {
944
- echo $this->get_footer();
945
- }
946
-
947
- /**
948
- * Return/Show Extra field 1
949
- */
950
- public function get_extra_1() {
951
- if (isset($this->settings->template_settings['extra_1'])) {
952
- $extra_1 = nl2br( wptexturize( $this->settings->template_settings[ 'extra_1' ] ) );
953
- return apply_filters( 'wpo_wcpdf_extra_1', $extra_1 );
954
- }
955
- }
956
- public function extra_1() {
957
- echo $this->get_extra_1();
958
- }
959
-
960
- /**
961
- * Return/Show Extra field 2
962
- */
963
- public function get_extra_2() {
964
- if (isset($this->settings->template_settings['extra_2'])) {
965
- $extra_2 = nl2br( wptexturize( $this->settings->template_settings[ 'extra_2' ] ) );
966
- return apply_filters( 'wpo_wcpdf_extra_2', $extra_2 );
967
- }
968
- }
969
- public function extra_2() {
970
- echo $this->get_extra_2();
971
- }
972
-
973
- /**
974
- * Return/Show Extra field 3
975
- */
976
- public function get_extra_3() {
977
- if (isset($this->settings->template_settings['extra_3'])) {
978
- $extra_3 = nl2br( wptexturize( $this->settings->template_settings[ 'extra_3' ] ) );
979
- return apply_filters( 'wpo_wcpdf_extra_3', $extra_3 );
980
- }
981
- }
982
- public function extra_3() {
983
- echo $this->get_extra_3();
984
- }
985
- }
986
- }
987
-
988
- // Load main plugin class
989
- $wpo_wcpdf = new WooCommerce_PDF_Invoices();
1
+ <?php
2
+ /**
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.5.33
7
+ * Author: Ewout Fernhout
8
+ * Author URI: http://www.wpovernight.com
9
+ * License: GPLv2 or later
10
+ * License URI: http://www.opensource.org/licenses/gpl-license.php
11
+ * Text Domain: wpo_wcpdf
12
+ */
13
+
14
+ if ( !class_exists( 'WooCommerce_PDF_Invoices' ) ) {
15
+
16
+ class WooCommerce_PDF_Invoices {
17
+
18
+ public static $plugin_prefix;
19
+ public static $plugin_url;
20
+ public static $plugin_path;
21
+ public static $plugin_basename;
22
+ public static $version;
23
+
24
+ public $writepanels;
25
+ public $settings;
26
+ public $export;
27
+
28
+ /**
29
+ * Constructor
30
+ */
31
+ public function __construct() {
32
+ self::$plugin_prefix = 'wpo_wcpdf_';
33
+ self::$plugin_basename = plugin_basename(__FILE__);
34
+ self::$plugin_url = plugin_dir_url(self::$plugin_basename);
35
+ self::$plugin_path = trailingslashit(dirname(__FILE__));
36
+ self::$version = '1.5.33';
37
+
38
+ // load the localisation & classes
39
+ add_action( 'plugins_loaded', array( $this, 'translations' ) ); // or use init?
40
+ add_action( 'init', array( $this, 'load_classes' ) );
41
+
42
+ // run lifecycle methods
43
+ if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
44
+ // check if upgrading from versionless (1.4.14 and older)
45
+ if ( get_option('wpo_wcpdf_general_settings') && get_option('wpo_wcpdf_version') === false ) {
46
+ // tag 'versionless', so that we can apply necessary upgrade settings
47
+ add_option( 'wpo_wcpdf_version', 'versionless' );
48
+ }
49
+
50
+ add_action( 'wp_loaded', array( $this, 'do_install' ) );
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Load the translation / textdomain files
56
+ *
57
+ * Note: the first-loaded translation file overrides any following ones if the same translation is present
58
+ */
59
+ public function translations() {
60
+ $locale = apply_filters( 'plugin_locale', get_locale(), 'wpo_wcpdf' );
61
+ $dir = trailingslashit( WP_LANG_DIR );
62
+
63
+ /**
64
+ * Frontend/global Locale. Looks in:
65
+ *
66
+ * - WP_LANG_DIR/woocommerce-pdf-invoices-packing-slips/wpo_wcpdf-LOCALE.mo
67
+ * - WP_LANG_DIR/plugins/wpo_wcpdf-LOCALE.mo
68
+ * - woocommerce-pdf-invoices-packing-slips/languages/wpo_wcpdf-LOCALE.mo (which if not found falls back to:)
69
+ * - WP_LANG_DIR/plugins/wpo_wcpdf-LOCALE.mo
70
+ */
71
+ load_textdomain( 'wpo_wcpdf', $dir . 'woocommerce-pdf-invoices-packing-slips/wpo_wcpdf-' . $locale . '.mo' );
72
+ load_textdomain( 'wpo_wcpdf', $dir . 'plugins/wpo_wcpdf-' . $locale . '.mo' );
73
+ load_plugin_textdomain( 'wpo_wcpdf', false, dirname( self::$plugin_basename ) . '/languages' );
74
+ }
75
+
76
+ /**
77
+ * Load the main plugin classes and functions
78
+ */
79
+ public function includes() {
80
+ include_once( 'includes/class-wcpdf-settings.php' );
81
+ include_once( 'includes/class-wcpdf-writepanels.php' );
82
+ include_once( 'includes/class-wcpdf-export.php' );
83
+ }
84
+
85
+
86
+ /**
87
+ * Instantiate classes when woocommerce is activated
88
+ */
89
+ public function load_classes() {
90
+ if ( $this->is_woocommerce_activated() ) {
91
+ $this->includes();
92
+ $this->settings = new WooCommerce_PDF_Invoices_Settings();
93
+ $this->writepanels = new WooCommerce_PDF_Invoices_Writepanels();
94
+ $this->export = new WooCommerce_PDF_Invoices_Export();
95
+ } else {
96
+ // display notice instead
97
+ add_action( 'admin_notices', array ( $this, 'need_woocommerce' ) );
98
+ }
99
+
100
+ }
101
+
102
+ /**
103
+ * Check if woocommerce is activated
104
+ */
105
+ public function is_woocommerce_activated() {
106
+ $blog_plugins = get_option( 'active_plugins', array() );
107
+ $site_plugins = get_site_option( 'active_sitewide_plugins', array() );
108
+
109
+ if ( in_array( 'woocommerce/woocommerce.php', $blog_plugins ) || isset( $site_plugins['woocommerce/woocommerce.php'] ) ) {
110
+ return true;
111
+ } else {
112
+ return false;
113
+ }
114
+ }
115
+
116
+ /**
117
+ * WooCommerce not active notice.
118
+ *
119
+ * @return string Fallack notice.
120
+ */
121
+
122
+ public function need_woocommerce() {
123
+ $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>' );
124
+
125
+ $message = '<div class="error"><p>' . $error . '</p></div>';
126
+
127
+ echo $message;
128
+ }
129
+
130
+ /** Lifecycle methods *******************************************************
131
+ * Because register_activation_hook only runs when the plugin is manually
132
+ * activated by the user, we're checking the current version against the
133
+ * version stored in the database
134
+ ****************************************************************************/
135
+
136
+ /**
137
+ * Handles version checking
138
+ */
139
+ public function do_install() {
140
+ // only install when woocommerce is active
141
+ if ( !$this->is_woocommerce_activated() ) {
142
+ return;
143
+ }
144
+
145
+ $version_setting = 'wpo_wcpdf_version';
146
+ $installed_version = get_option( $version_setting );
147
+
148
+ // installed version lower than plugin version?
149
+ if ( version_compare( $installed_version, self::$version, '<' ) ) {
150
+
151
+ if ( ! $installed_version ) {
152
+ $this->install();
153
+ } else {
154
+ $this->upgrade( $installed_version );
155
+ }
156
+
157
+ // new version number
158
+ update_option( $version_setting, self::$version );
159
+ }
160
+ }
161
+
162
+
163
+ /**
164
+ * Plugin install method. Perform any installation tasks here
165
+ */
166
+ protected function install() {
167
+ // Create temp folders
168
+ $tmp_base = $this->export->get_tmp_base();
169
+
170
+ // check if tmp folder exists => if not, initialize
171
+ if ( !@is_dir( $tmp_base ) ) {
172
+ $this->export->init_tmp( $tmp_base );
173
+ }
174
+
175
+ }
176
+
177
+
178
+ /**
179
+ * Plugin upgrade method. Perform any required upgrades here
180
+ *
181
+ * @param string $installed_version the currently installed version
182
+ */
183
+ protected function upgrade( $installed_version ) {
184
+ if ( $installed_version == 'versionless') { // versionless = 1.4.14 and older
185
+ // We're upgrading from an old version, so we're enabling the option to use the plugin tmp folder.
186
+ // This is not per se the 'best' solution, but the good thing is that nothing is changed
187
+ // and nothing will be broken (that wasn't broken before)
188
+ $default = array( 'old_tmp' => 1 );
189
+ update_option( 'wpo_wcpdf_debug_settings', $default );
190
+ }
191
+
192
+ // sync fonts on every upgrade!
193
+ $debug_settings = get_option( 'wpo_wcpdf_debug_settings' ); // get temp setting
194
+
195
+ // do not copy if old_tmp function active! (double check for slow databases)
196
+ if ( !( isset($debug_settings['old_tmp']) || $installed_version == 'versionless' ) ) {
197
+ $tmp_base = $this->export->get_tmp_base();
198
+
199
+ // check if tmp folder exists => if not, initialize
200
+ if ( !@is_dir( $tmp_base ) ) {
201
+ $this->export->init_tmp( $tmp_base );
202
+ }
203
+
204
+ $font_path = $tmp_base . 'fonts/';
205
+ $this->export->copy_fonts( $font_path );
206
+ }
207
+
208
+ // 1.5.28 update: copy next invoice number to separate setting
209
+ if ( $installed_version == 'versionless' || version_compare( $installed_version, '1.5.28', '<' ) ) {
210
+ $template_settings = get_option( 'wpo_wcpdf_template_settings' );
211
+ $next_invoice_number = isset($template_settings['next_invoice_number'])?$template_settings['next_invoice_number']:'';
212
+ update_option( 'wpo_wcpdf_next_invoice_number', $next_invoice_number );
213
+ }
214
+ }
215
+
216
+ /***********************************************************************/
217
+ /********************** GENERAL TEMPLATE FUNCTIONS *********************/
218
+ /***********************************************************************/
219
+
220
+ /**
221
+ * Get template name from slug
222
+ */
223
+ public function get_template_name ( $template_type ) {
224
+ switch ( $template_type ) {
225
+ case 'invoice':
226
+ $template_name = apply_filters( 'wpo_wcpdf_invoice_title', __( 'Invoice', 'wpo_wcpdf' ) );
227
+ break;
228
+ case 'packing-slip':
229
+ $template_name = apply_filters( 'wpo_wcpdf_packing_slip_title', __( 'Packing Slip', 'wpo_wcpdf' ) );
230
+ break;
231
+ default:
232
+ // try to 'unslug' the name
233
+ $template_name = ucwords( str_replace( array( '_', '-' ), ' ', $template_type ) );
234
+ break;
235
+ }
236
+
237
+ return apply_filters( 'wpo_wcpdf_template_name', $template_name, $template_type );
238
+ }
239
+
240
+ /**
241
+ * Output template styles
242
+ */
243
+ public function template_styles() {
244
+ $css = apply_filters( 'wpo_wcpdf_template_styles_file', $this->export->template_path. '/' .'style.css' );
245
+
246
+ ob_start();
247
+ if (file_exists($css)) {
248
+ include($css);
249
+ }
250
+ $html = ob_get_clean();
251
+ $html = apply_filters( 'wpo_wcpdf_template_styles', $html );
252
+
253
+ echo $html;
254
+ }
255
+
256
+ /**
257
+ * Return logo id
258
+ */
259
+ public function get_header_logo_id() {
260
+ if (isset($this->settings->template_settings['header_logo'])) {
261
+ return apply_filters( 'wpo_wcpdf_header_logo_id', $this->settings->template_settings['header_logo'] );
262
+ }
263
+ }
264
+
265
+ /**
266
+ * Show logo html
267
+ */
268
+ public function header_logo() {
269
+ if ($this->get_header_logo_id()) {
270
+ $attachment_id = $this->get_header_logo_id();
271
+ $company = isset($this->settings->template_settings['shop_name'])? $this->settings->template_settings['shop_name'] : '';
272
+ if( $attachment_id ) {
273
+ $attachment = wp_get_attachment_image_src( $attachment_id, 'full', false );
274
+
275
+ $attachment_src = $attachment[0];
276
+ $attachment_width = $attachment[1];
277
+ $attachment_height = $attachment[2];
278
+
279
+ $attachment_path = get_attached_file( $attachment_id );
280
+
281
+ if ( apply_filters('wpo_wcpdf_use_path', true) && file_exists($attachment_path) ) {
282
+ $src = $attachment_path;
283
+ } else {
284
+ $src = $attachment_src;
285
+ }
286
+
287
+ printf('<img src="%1$s" width="%2$d" height="%3$d" alt="%4$s" />', $src, $attachment_width, $attachment_height, esc_attr( $company ) );
288
+ }
289
+ }
290
+ }
291
+
292
+ /**
293
+ * Return/Show custom company name or default to blog name
294
+ */
295
+ public function get_shop_name() {
296
+ if (!empty($this->settings->template_settings['shop_name'])) {
297
+ $name = trim( $this->settings->template_settings['shop_name'] );
298
+ return apply_filters( 'wpo_wcpdf_shop_name', wptexturize( $name ) );
299
+ } else {
300
+ return apply_filters( 'wpo_wcpdf_shop_name', get_bloginfo( 'name' ) );
301
+ }
302
+ }
303
+ public function shop_name() {
304
+ echo $this->get_shop_name();
305
+ }
306
+
307
+ /**
308
+ * Return/Show shop/company address if provided
309
+ */
310
+ public function get_shop_address() {
311
+ $shop_address = apply_filters( 'wpo_wcpdf_shop_address', wpautop( wptexturize( $this->settings->template_settings['shop_address'] ) ) );
312
+ if (!empty($shop_address)) {
313
+ return $shop_address;
314
+ } else {
315
+ return false;
316
+ }
317
+ }
318
+ public function shop_address() {
319
+ echo $this->get_shop_address();
320
+ }
321
+
322
+ /**
323
+ * Check if billing address and shipping address are equal
324
+ */
325
+ public function ships_to_different_address() {
326
+ // always prefer parent address for refunds
327
+ if ( get_post_type( $this->export->order->id ) == 'shop_order_refund' && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
328
+ // temporarily switch order to make all filters / order calls work correctly
329
+ $order_meta = get_post_meta( $parent_order_id );
330
+ } else {
331
+ $order_meta = get_post_meta( $this->export->order->id );
332
+ }
333
+
334
+ $address_comparison_fields = apply_filters( 'wpo_wcpdf_address_comparison_fields', array(
335
+ 'first_name',
336
+ 'last_name',
337
+ 'company',
338
+ 'address_1',
339
+ 'address_2',
340
+ 'city',
341
+ 'state',
342
+ 'postcode',
343
+ 'country'
344
+ ) );
345
+
346
+ foreach ($address_comparison_fields as $address_field) {
347
+ $billing_field = isset( $order_meta['_billing_'.$address_field] ) ? $order_meta['_billing_'.$address_field] : '';
348
+ $shipping_field = isset( $order_meta['_shipping_'.$address_field] ) ? $order_meta['_shipping_'.$address_field] : '';
349
+ if ( $shipping_field != $billing_field ) {
350
+ // this address field is different -> ships to different address!
351
+ return true;
352
+ }
353
+ }
354
+
355
+ //if we got here, it means the addresses are equal -> doesn't ship to different address!
356
+ return apply_filters( 'wpo_wcpdf_ships_to_different_address', false, $order_meta );
357
+ }
358
+
359
+ /**
360
+ * Return/Show billing address
361
+ */
362
+ public function get_billing_address() {
363
+ // always prefer parent billing address for refunds
364
+ if ( get_post_type( $this->export->order->id ) == 'shop_order_refund' && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
365
+ // temporarily switch order to make all filters / order calls work correctly
366
+ $current_order = $this->export->order;
367
+ $this->export->order = new WC_Order( $parent_order_id );
368
+ $address = apply_filters( 'wpo_wcpdf_billing_address', $this->export->order->get_formatted_billing_address() );
369
+ // switch back & unset
370
+ $this->export->order = $current_order;
371
+ unset($current_order);
372
+ } elseif ( $address = $this->export->order->get_formatted_billing_address() ) {
373
+ // regular shop_order
374
+ $address = apply_filters( 'wpo_wcpdf_billing_address', $address );
375
+ } else {
376
+ // no address
377
+ $address = apply_filters( 'wpo_wcpdf_billing_address', __('N/A', 'wpo_wcpdf') );
378
+ }
379
+
380
+ return $address;
381
+ }
382
+ public function billing_address() {
383
+ echo $this->get_billing_address();
384
+ }
385
+
386
+ /**
387
+ * Return/Show billing email
388
+ */
389
+ public function get_billing_email() {
390
+ $billing_email = $this->export->order->billing_email;
391
+
392
+ if ( !$billing_email && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
393
+ // try parent
394
+ $billing_email = get_post_meta( $parent_order_id, '_billing_email', true );
395
+ }
396
+
397
+ return apply_filters( 'wpo_wcpdf_billing_email', $billing_email );
398
+ }
399
+ public function billing_email() {
400
+ echo $this->get_billing_email();
401
+ }
402
+
403
+ /**
404
+ * Return/Show billing phone
405
+ */
406
+ public function get_billing_phone() {
407
+ $billing_phone = $this->export->order->billing_phone;
408
+
409
+ if ( !$billing_phone && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
410
+ // try parent
411
+ $billing_phone = get_post_meta( $parent_order_id, '_billing_phone', true );
412
+ }
413
+
414
+ return apply_filters( 'wpo_wcpdf_billing_phone', $billing_phone );
415
+ }
416
+ public function billing_phone() {
417
+ echo $this->get_billing_phone();
418
+ }
419
+
420
+ /**
421
+ * Return/Show shipping address
422
+ */
423
+ public function get_shipping_address() {
424
+ // always prefer parent shipping address for refunds
425
+ if ( get_post_type( $this->export->order->id ) == 'shop_order_refund' && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
426
+ // temporarily switch order to make all filters / order calls work correctly
427
+ $current_order = $this->export->order;
428
+ $this->export->order = new WC_Order( $parent_order_id );
429
+ $address = apply_filters( 'wpo_wcpdf_shipping_address', $this->export->order->get_formatted_shipping_address() );
430
+ // switch back & unset
431
+ $this->export->order = $current_order;
432
+ unset($current_order);
433
+ } elseif ( $address = $this->export->order->get_formatted_shipping_address() ) {
434
+ // regular shop_order
435
+ $address = apply_filters( 'wpo_wcpdf_shipping_address', $address );
436
+ } else {
437
+ // no address
438
+ $address = apply_filters( 'wpo_wcpdf_shipping_address', __('N/A', 'wpo_wcpdf') );
439
+ }
440
+
441
+ return $address;
442
+ }
443
+ public function shipping_address() {
444
+ echo $this->get_shipping_address();
445
+ }
446
+
447
+ /**
448
+ * Return/Show a custom field
449
+ */
450
+ public function get_custom_field( $field_name ) {
451
+ $custom_field = get_post_meta($this->export->order->id,$field_name,true);
452
+
453
+ if ( !$custom_field && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
454
+ // try parent
455
+ $custom_field = get_post_meta( $parent_order_id, $field_name, true );
456
+ }
457
+
458
+ return apply_filters( 'wpo_wcpdf_billing_custom_field', $custom_field );
459
+ }
460
+ public function custom_field( $field_name, $field_label = '', $display_empty = false ) {
461
+ $custom_field = $this->get_custom_field( $field_name );
462
+ if (!empty($field_label)){
463
+ // add a a trailing space to the label
464
+ $field_label .= ' ';
465
+ }
466
+
467
+ if (!empty($custom_field) || $display_empty) {
468
+ echo $field_label . nl2br ($custom_field);
469
+ }
470
+ }
471
+
472
+ /**
473
+ * Return/Show order notes
474
+ */
475
+ public function get_order_notes( $filter = 'customer' ) {
476
+ if ( get_post_type( $this->export->order->id ) == 'shop_order_refund' && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
477
+ $post_id = $parent_order_id;
478
+ } else {
479
+ $post_id = $this->export->order->id;
480
+ }
481
+
482
+ $args = array(
483
+ 'post_id' => $post_id,
484
+ 'approve' => 'approve',
485
+ 'type' => 'order_note'
486
+ );
487
+
488
+ remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 );
489
+
490
+ $notes = get_comments( $args );
491
+
492
+ add_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 );
493
+
494
+ if ( $notes ) {
495
+ foreach( $notes as $key => $note ) {
496
+ if ( $filter == 'customer' && !get_comment_meta( $note->comment_ID, 'is_customer_note', true ) ) {
497
+ unset($notes[$key]);
498
+ }
499
+ if ( $filter == 'private' && get_comment_meta( $note->comment_ID, 'is_customer_note', true ) ) {
500
+ unset($notes[$key]);
501
+ }
502
+ }
503
+ return $notes;
504
+ }
505
+ }
506
+ public function order_notes( $filter = 'customer' ) {
507
+ $notes = $this->get_order_notes( $filter );
508
+ if ( $notes ) {
509
+ foreach( $notes as $note ) {
510
+ ?>
511
+ <div class="note_content">
512
+ <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?>
513
+ </div>
514
+ <?php
515
+ }
516
+ }
517
+ }
518
+
519
+ /**
520
+ * Return/Show the current date
521
+ */
522
+ public function get_current_date() {
523
+ return apply_filters( 'wpo_wcpdf_date', date_i18n( get_option( 'date_format' ) ) );
524
+ }
525
+ public function current_date() {
526
+ echo $this->get_current_date();
527
+ }
528
+
529
+ /**
530
+ * Return/Show payment method
531
+ */
532
+ public function get_payment_method() {
533
+ $payment_method_label = __( 'Payment method', 'wpo_wcpdf' );
534
+
535
+ $payment_method = __( $this->export->order->payment_method_title, 'woocommerce' );
536
+ if ( !$payment_method && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
537
+ // try parent
538
+ $payment_method = get_post_meta( $parent_order_id, '_payment_method_title', true );
539
+ $payment_method = __( $payment_method, 'woocommerce' );
540
+ }
541
+
542
+ return apply_filters( 'wpo_wcpdf_payment_method', $payment_method );
543
+ }
544
+ public function payment_method() {
545
+ echo $this->get_payment_method();
546
+ }
547
+
548
+ /**
549
+ * Return/Show shipping method
550
+ */
551
+ public function get_shipping_method() {
552
+ $shipping_method_label = __( 'Shipping method', 'wpo_wcpdf' );
553
+ return apply_filters( 'wpo_wcpdf_shipping_method', __( $this->export->order->get_shipping_method(), 'woocommerce' ) );
554
+ }
555
+ public function shipping_method() {
556
+ echo $this->get_shipping_method();
557
+ }
558
+
559
+ /**
560
+ * Return/Show order number
561
+ */
562
+ public function get_order_number() {
563
+ // try parent first
564
+ if ( get_post_type( $this->export->order->id ) == 'shop_order_refund' && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
565
+ $parent_order = new WC_Order( $parent_order_id );
566
+ $order_number = $parent_order->get_order_number();
567
+ } else {
568
+ $order_number = $this->export->order->get_order_number();
569
+ }
570
+
571
+ // Trim the hash to have a clean number but still
572
+ // support any filters that were applied before.
573
+ $order_number = ltrim($order_number, '#');
574
+ return apply_filters( 'wpo_wcpdf_order_number', $order_number);
575
+ }
576
+ public function order_number() {
577
+ echo $this->get_order_number();
578
+ }
579
+
580
+ /**
581
+ * Return/Show invoice number
582
+ */
583
+ public function get_invoice_number() {
584
+ // try parent first
585
+ if ( get_post_type( $this->export->order->id ) == 'shop_order_refund' && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
586
+ $invoice_number = $this->export->get_invoice_number( $parent_order_id );
587
+ } else {
588
+ $invoice_number = $this->export->get_invoice_number( $this->export->order->id );
589
+ }
590
+
591
+ return $invoice_number;
592
+ }
593
+ public function invoice_number() {
594
+ echo $this->get_invoice_number();
595
+ }
596
+
597
+ /**
598
+ * Return/Show the order date
599
+ */
600
+ public function get_order_date() {
601
+ if ( get_post_type( $this->export->order->id ) == 'shop_order_refund' && $parent_order_id = wp_get_post_parent_id( $this->export->order->id ) ) {
602
+ $parent_order = new WC_Order( $parent_order_id );
603
+ $order_date = $parent_order->order_date;
604
+ } else {
605
+ $order_date = $this->export->order->order_date;
606
+ }
607
+
608
+ $date = date_i18n( get_option( 'date_format' ), strtotime( $order_date ) );
609
+ return apply_filters( 'wpo_wcpdf_order_date', $date, $order_date );
610
+ }
611
+ public function order_date() {
612
+ echo $this->get_order_date();
613
+ }
614
+
615
+ /**
616
+ * Return/Show the invoice date
617
+ */
618
+ public function get_invoice_date() {
619
+ $invoice_date = get_post_meta($this->export->order->id,'_wcpdf_invoice_date',true);
620
+
621
+ // add invoice date if it doesn't exist
622
+ if ( empty($invoice_date) || !isset($invoice_date) ) {
623
+ $invoice_date = current_time('mysql');
624
+ update_post_meta( $this->export->order->id, '_wcpdf_invoice_date', $invoice_date );
625
+ }
626
+
627
+ $formatted_invoice_date = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) );
628
+
629
+ return apply_filters( 'wpo_wcpdf_invoice_date', $formatted_invoice_date, $invoice_date );
630
+ }
631
+ public function invoice_date() {
632
+ echo $this->get_invoice_date();
633
+ }
634
+
635
+ /**
636
+ * Return the order items
637
+ */
638
+ public function get_order_items() {
639
+ return apply_filters( 'wpo_wcpdf_order_items', $this->export->get_order_items() );
640
+ }
641
+
642
+ /**
643
+ * Return/show product attribute
644
+ */
645
+ public function get_product_attribute( $attribute_name, $product ) {
646
+ // first, check the text attributes
647
+ $attributes = $product->get_attributes();
648
+ $attribute_key = @wc_attribute_taxonomy_name( $attribute_name );
649
+ if (array_key_exists( sanitize_title( $attribute_name ), $attributes) ) {
650
+ $attribute = $product->get_attribute ( $attribute_name );
651
+ return $attribute;
652
+ } elseif (array_key_exists( sanitize_title( $attribute_key ), $attributes) ) {
653
+ $attribute = $product->get_attribute ( $attribute_key );
654
+ return $attribute;
655
+ }
656
+
657
+ // not a text attribute, try attribute taxonomy
658
+ $attribute_key = @wc_attribute_taxonomy_name( $attribute_name );
659
+ $product_terms = @wc_get_product_terms( $product->id, $attribute_key, array( 'fields' => 'names' ) );
660
+ // check if not empty, then display
661
+ if ( !empty($product_terms) ) {
662
+ $attribute = array_shift( $product_terms );
663
+ return $attribute;
664
+ } else {
665
+ // no attribute under this name
666
+ return false;
667
+ }
668
+ }
669
+ public function product_attribute( $attribute_name, $product ) {
670
+ echo $this->get_product_attribute( $attribute_name, $product );
671
+ }
672
+
673
+
674
+ /**
675
+ * Return the order totals listing
676
+ */
677
+ public function get_woocommerce_totals() {
678
+ // get totals and remove the semicolon
679
+ $totals = apply_filters( 'wpo_wcpdf_raw_order_totals', $this->export->order->get_order_item_totals(), $this->export->order );
680
+
681
+ // remove the colon for every label
682
+ foreach ( $totals as $key => $total ) {
683
+ $label = $total['label'];
684
+ $colon = strrpos( $label, ':' );
685
+ if( $colon !== false ) {
686
+ $label = substr_replace( $label, '', $colon, 1 );
687
+ }
688
+ $totals[$key]['label'] = $label;
689
+ }
690
+
691
+ // WC2.4 fix order_total for refunded orders
692
+ if ( version_compare( WOOCOMMERCE_VERSION, '2.4', '>=' ) && isset($totals['order_total']) ) {
693
+ $tax_display = $this->export->order->tax_display_cart;
694
+ $totals['order_total']['value'] = wc_price( $this->export->order->get_total(), array( 'currency' => $this->export->order->get_order_currency() ) );
695
+ $order_total = $this->export->order->get_total();
696
+ $tax_string = '';
697
+
698
+ // Tax for inclusive prices
699
+ if ( wc_tax_enabled() && 'incl' == $tax_display ) {
700
+ $tax_string_array = array();
701
+
702
+ if ( 'itemized' == get_option( 'woocommerce_tax_total_display' ) ) {
703
+ foreach ( $this->export->order->get_tax_totals() as $code => $tax ) {
704
+ $tax_amount = $tax->formatted_amount;
705
+ $tax_string_array[] = sprintf( '%s %s', $tax_amount, $tax->label );
706
+ }
707
+ } else {
708
+ $tax_string_array[] = sprintf( '%s %s', wc_price( $this->export->order->get_total_tax() - $this->export->order->get_total_tax_refunded(), array( 'currency' => $this->export->order->get_order_currency() ) ), WC()->countries->tax_or_vat() );
709
+ }
710
+ if ( ! empty( $tax_string_array ) ) {
711
+ $tax_string = ' ' . sprintf( __( '(Includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) );
712
+ }
713
+ }
714
+
715
+ $totals['order_total']['value'] .= $tax_string;
716
+ }
717
+
718
+ // remove refund lines (shouldn't be in invoice)
719
+ foreach ( $totals as $key => $total ) {
720
+ if ( strpos($key, 'refund_') !== false ) {
721
+ unset( $totals[$key] );
722
+ }
723
+ }
724
+
725
+ return apply_filters( 'wpo_wcpdf_woocommerce_totals', $totals, $this->export->order );
726
+ }
727
+
728
+ /**
729
+ * Return/show the order subtotal
730
+ */
731
+ public function get_order_subtotal( $tax = 'excl', $discount = 'incl' ) { // set $tax to 'incl' to include tax, same for $discount
732
+ //$compound = ($discount == 'incl')?true:false;
733
+
734
+ $subtotal = $this->export->order->get_subtotal_to_display( false, $tax );
735
+
736
+ $subtotal = ($pos = strpos($subtotal, ' <small')) ? substr($subtotal, 0, $pos) : $subtotal; //removing the 'excluding tax' text
737
+
738
+ $subtotal = array (
739
+ 'label' => __('Subtotal', 'wpo_wcpdf'),
740
+ 'value' => $subtotal,
741
+ );
742
+
743
+ return apply_filters( 'wpo_wcpdf_order_subtotal', $subtotal, $tax, $discount );
744
+ }
745
+ public function order_subtotal( $tax = 'excl', $discount = 'incl' ) {
746
+ $subtotal = $this->get_order_subtotal( $tax, $discount );
747
+ echo $subtotal['value'];
748
+ }
749
+
750
+ /**
751
+ * Return/show the order shipping costs
752
+ */
753
+ public function get_order_shipping( $tax = 'excl' ) { // set $tax to 'incl' to include tax
754
+ if ($tax == 'excl' ) {
755
+ $shipping_costs = $this->export->wc_price( $this->export->order->order_shipping );
756
+ } else {
757
+ $shipping_costs = $this->export->wc_price( $this->export->order->order_shipping + $this->export->order->order_shipping_tax );
758
+ }
759
+
760
+ $shipping = array (
761
+ 'label' => __('Shipping', 'wpo_wcpdf'),
762
+ 'value' => $shipping_costs,
763
+ 'tax' => $this->export->wc_price( $this->export->order->order_shipping_tax ),
764
+ );
765
+ return apply_filters( 'wpo_wcpdf_order_shipping', $shipping, $tax );
766
+ }
767
+ public function order_shipping( $tax = 'excl' ) {
768
+ $shipping = $this->get_order_shipping( $tax );
769
+ echo $shipping['value'];
770
+ }
771
+
772
+ /**
773
+ * Return/show the total discount
774
+ */
775
+ public function get_order_discount( $type = 'total', $tax = 'incl' ) {
776
+ if ( $tax == 'incl' ) {
777
+ switch ($type) {
778
+ case 'cart':
779
+ // Cart Discount - pre-tax discounts. (deprecated in WC2.3)
780
+ $discount_value = $this->export->order->get_cart_discount();
781
+ break;
782
+ case 'order':
783
+ // Order Discount - post-tax discounts. (deprecated in WC2.3)
784
+ $discount_value = $this->export->order->get_order_discount();
785
+ break;
786
+ case 'total':
787
+ // Total Discount
788
+ if ( version_compare( WOOCOMMERCE_VERSION, '2.3' ) >= 0 ) {
789
+ $discount_value = $this->export->order->get_total_discount( false ); // $ex_tax = false
790
+ } else {
791
+ // WC2.2 and older: recalculate to include tax
792
+ $discount_value = 0;
793
+ $items = $this->export->order->get_items();;
794
+ if( sizeof( $items ) > 0 ) {
795
+ foreach( $items as $item ) {
796
+ $discount_value += ($item['line_subtotal'] + $item['line_subtotal_tax']) - ($item['line_total'] + $item['line_tax']);
797
+ }
798
+ }
799
+ }
800
+
801
+ break;
802
+ default:
803
+ // Total Discount - Cart & Order Discounts combined
804
+ $discount_value = $this->export->order->get_total_discount();
805
+ break;
806
+ }
807
+ } else { // calculate discount excluding tax
808
+ if ( version_compare( WOOCOMMERCE_VERSION, '2.3' ) >= 0 ) {
809
+ $discount_value = $this->export->order->get_total_discount( true ); // $ex_tax = true
810
+ } else {
811
+ // WC2.2 and older: recalculate to exclude tax
812
+ $discount_value = 0;
813
+
814
+ $items = $this->export->order->get_items();;
815
+ if( sizeof( $items ) > 0 ) {
816
+ foreach( $items as $item ) {
817
+ $discount_value += ($item['line_subtotal'] - $item['line_total']);
818
+ }
819
+ }
820
+ }
821
+ }
822
+
823
+ $discount = array (
824
+ 'label' => __('Discount', 'wpo_wcpdf'),
825
+ 'value' => $this->export->wc_price($discount_value),
826
+ 'raw_value' => $discount_value,
827
+ );
828
+
829
+ if ( round( $discount_value, 3 ) != 0 ) {
830
+ return apply_filters( 'wpo_wcpdf_order_discount', $discount, $type, $tax );
831
+ }
832
+ }
833
+ public function order_discount( $type = 'total', $tax = 'incl' ) {
834
+ $discount = $this->get_order_discount( $type, $tax );
835
+ echo $discount['value'];
836
+ }
837
+
838
+ /**
839
+ * Return the order fees
840
+ */
841
+ public function get_order_fees( $tax = 'excl' ) {
842
+ if ( $wcfees = $this->export->order->get_fees() ) {
843
+ foreach( $wcfees as $id => $fee ) {
844
+ if ($tax == 'excl' ) {
845
+ $fee_price = $this->export->wc_price( $fee['line_total'] );
846
+ } else {
847
+ $fee_price = $this->export->wc_price( $fee['line_total'] + $fee['line_tax'] );
848
+ }
849
+
850
+ $fees[ $id ] = array(
851
+ 'label' => $fee['name'],
852
+ 'value' => $fee_price,
853
+ 'line_total' => $this->export->wc_price($fee['line_total']),
854
+ 'line_tax' => $this->export->wc_price($fee['line_tax'])
855
+ );
856
+ }
857
+ return $fees;
858
+ }
859
+ }
860
+
861
+ /**
862
+ * Return the order taxes
863
+ */
864
+ public function get_order_taxes() {
865
+ $tax_label = __( 'VAT', 'wpo_wcpdf' ); // register alternate label translation
866
+ $tax_label = __( 'Tax rate', 'wpo_wcpdf' );
867
+ $tax_rate_ids = $this->export->get_tax_rate_ids();
868
+ if ($this->export->order->get_taxes()) {
869
+ foreach ( $this->export->order->get_taxes() as $key => $tax ) {
870
+ $taxes[ $key ] = array(
871
+ 'label' => isset( $tax[ 'label' ] ) ? $tax[ 'label' ] : $tax[ 'name' ],
872
+ 'value' => $this->export->wc_price( ( $tax[ 'tax_amount' ] + $tax[ 'shipping_tax_amount' ] ) ),
873
+ 'rate_id' => $tax['rate_id'],
874
+ 'tax_amount' => $tax['tax_amount'],
875
+ 'shipping_tax_amount' => $tax['shipping_tax_amount'],
876
+ 'rate' => isset( $tax_rate_ids[ $tax['rate_id'] ] ) ? ( (float) $tax_rate_ids[$tax['rate_id']]['tax_rate'] ) . ' %': '',
877
+ );
878
+ }
879
+
880
+ return apply_filters( 'wpo_wcpdf_order_taxes', $taxes );
881
+ }
882
+ }
883
+
884
+ /**
885
+ * Return/show the order grand total
886
+ */
887
+ public function get_order_grand_total( $tax = 'incl' ) {
888
+ if ( version_compare( WOOCOMMERCE_VERSION, '2.1' ) >= 0 ) {
889
+ // WC 2.1 or newer is used
890
+ $total_unformatted = $this->export->order->get_total();
891
+ } else {
892
+ // Backwards compatibility
893
+ $total_unformatted = $this->export->order->get_order_total();
894
+ }
895
+
896
+ if ($tax == 'excl' ) {
897
+ $total_tax = 0;
898
+ foreach ( $this->export->order->get_taxes() as $tax ) {
899
+ $total_tax += ( $tax[ 'tax_amount' ] + $tax[ 'shipping_tax_amount' ] );
900
+ }
901
+
902
+ $total = $this->export->wc_price( ( $total_unformatted - $total_tax ) );
903
+ $label = __( 'Total ex. VAT', 'wpo_wcpdf' );
904
+ } else {
905
+ $total = $this->export->wc_price( ( $total_unformatted ) );
906
+ $label = __( 'Total', 'wpo_wcpdf' );
907
+ }
908
+
909
+ $grand_total = array(
910
+ 'label' => $label,
911
+ 'value' => $total,
912
+ );
913
+
914
+ return apply_filters( 'wpo_wcpdf_order_grand_total', $grand_total, $tax );
915
+ }
916
+ public function order_grand_total( $tax = 'incl' ) {
917
+ $grand_total = $this->get_order_grand_total( $tax );
918
+ echo $grand_total['value'];
919
+ }
920
+
921
+
922
+ /**
923
+ * Return/Show shipping notes
924
+ */
925
+ public function get_shipping_notes() {
926
+ $shipping_notes = wpautop( wptexturize( $this->export->order->customer_note ) );
927
+ return apply_filters( 'wpo_wcpdf_shipping_notes', $shipping_notes );
928
+ }
929
+ public function shipping_notes() {
930
+ echo $this->get_shipping_notes();
931
+ }
932
+
933
+
934
+ /**
935
+ * Return/Show shop/company footer imprint, copyright etc.
936
+ */
937
+ public function get_footer() {
938
+ if (isset($this->settings->template_settings['footer'])) {
939
+ $footer = wpautop( wptexturize( $this->settings->template_settings[ 'footer' ] ) );
940
+ return apply_filters( 'wpo_wcpdf_footer', $footer );
941
+ }
942
+ }
943
+ public function footer() {
944
+ echo $this->get_footer();
945
+ }
946
+
947
+ /**
948
+ * Return/Show Extra field 1
949
+ */
950
+ public function get_extra_1() {
951
+ if (isset($this->settings->template_settings['extra_1'])) {
952
+ $extra_1 = nl2br( wptexturize( $this->settings->template_settings[ 'extra_1' ] ) );
953
+ return apply_filters( 'wpo_wcpdf_extra_1', $extra_1 );
954
+ }
955
+ }
956
+ public function extra_1() {
957
+ echo $this->get_extra_1();
958
+ }
959
+
960
+ /**
961
+ * Return/Show Extra field 2
962
+ */
963
+ public function get_extra_2() {
964
+ if (isset($this->settings->template_settings['extra_2'])) {
965
+ $extra_2 = nl2br( wptexturize( $this->settings->template_settings[ 'extra_2' ] ) );
966
+ return apply_filters( 'wpo_wcpdf_extra_2', $extra_2 );
967
+ }
968
+ }
969
+ public function extra_2() {
970
+ echo $this->get_extra_2();
971
+ }
972
+
973
+ /**
974
+ * Return/Show Extra field 3
975
+ */
976
+ public function get_extra_3() {
977
+ if (isset($this->settings->template_settings['extra_3'])) {
978
+ $extra_3 = nl2br( wptexturize( $this->settings->template_settings[ 'extra_3' ] ) );
979
+ return apply_filters( 'wpo_wcpdf_extra_3', $extra_3 );
980
+ }
981
+ }
982
+ public function extra_3() {
983
+ echo $this->get_extra_3();
984
+ }
985
+ }
986
+ }
987
+
988
+ // Load main plugin class
989
+ $wpo_wcpdf = new WooCommerce_PDF_Invoices();