WooCommerce Print Invoice & Delivery Note - Version 4.5.2

Version Description

(23.08.2019) =

  • Fixed the issue of Print buttons not working on PHP versions below 7.0.
Download this release

Release Info

Developer ashokrane
Plugin Icon 128x128 WooCommerce Print Invoice & Delivery Note
Version 4.5.2
Comparing to
See all releases

Code changes from version 4.4.8 to 4.5.2

includes/class-wcdn-print.php CHANGED
@@ -1,155 +1,242 @@
1
  <?php
 
 
 
 
 
2
 
3
  /**
4
  * Exit if accessed directly
5
  */
6
- if ( !defined( 'ABSPATH' ) ) {
7
  exit;
8
  }
9
 
10
  /**
11
  * Print class
12
  */
13
- if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
14
 
15
- class WooCommerce_Delivery_Notes_Print {
 
 
 
16
 
 
 
 
 
 
17
  public static $template_registrations;
 
 
 
 
 
 
18
  public static $template_styles;
19
 
 
 
 
 
 
20
  public $template_locations;
 
 
 
 
 
 
21
  public $template;
22
 
 
 
 
 
 
23
  public $api_endpoints;
 
 
 
 
 
 
24
  public $query_vars;
25
 
 
 
 
 
 
26
  public $order_ids;
 
 
 
 
 
 
27
  public $order_email;
 
 
 
 
 
 
28
  public $orders;
29
 
30
  /**
31
  * Constructor
32
  */
33
  public function __construct() {
34
- // Define the templates
35
- self::$template_registrations = apply_filters( 'wcdn_template_registration', array(
36
- apply_filters( 'wcdn_template_registration_invoice', array(
37
- 'type' => 'invoice',
38
- 'labels' => array(
39
- 'name' => __( 'Invoice', 'woocommerce-delivery-notes' ),
40
- 'name_plural' => __( 'Invoices', 'woocommerce-delivery-notes' ),
41
- 'print' => __( 'Print Invoice', 'woocommerce-delivery-notes' ),
42
- 'print_plural' => __( 'Print Invoices', 'woocommerce-delivery-notes' ),
43
- 'message' => __( 'Invoice created.', 'woocommerce-delivery-notes' ),
44
- 'message_plural' => __( 'Invoices created.', 'woocommerce-delivery-notes' ),
45
- 'setting' => __( 'Show "Print Invoice" button', 'woocommerce-delivery-notes' )
46
- )
47
- ) ),
48
- apply_filters( 'wcdn_template_registration_delivery_note', array(
49
- 'type' => 'delivery-note',
50
- 'labels' => array(
51
- 'name' => __( 'Delivery Note', 'woocommerce-delivery-notes' ),
52
- 'name_plural' => __( 'Delivery Notes', 'woocommerce-delivery-notes' ),
53
- 'print' => __( 'Print Delivery Note', 'woocommerce-delivery-notes' ),
54
- 'print_plural' => __( 'Print Delivery Notes', 'woocommerce-delivery-notes' ),
55
- 'message' => __( 'Delivery Note created.', 'woocommerce-delivery-notes' ),
56
- 'message_plural' => __( 'Delivery Notes created.', 'woocommerce-delivery-notes' ),
57
- 'setting' => __( 'Show "Print Delivery Note" button', 'woocommerce-delivery-notes' )
58
- )
59
- ) ),
60
- apply_filters( 'wcdn_template_registration_receipt', array(
61
- 'type' => 'receipt',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  'labels' => array(
63
- 'name' => __( 'Receipt', 'woocommerce-delivery-notes' ),
64
- 'name_plural' => __( 'Receipts', 'woocommerce-delivery-notes' ),
65
- 'print' => __( 'Print Receipt', 'woocommerce-delivery-notes' ),
66
- 'print_plural' => __( 'Print Receipts', 'woocommerce-delivery-notes' ),
67
- 'message' => __( 'Receipt created.', 'woocommerce-delivery-notes' ),
68
- 'message_plural' => __( 'Receipts created.', 'woocommerce-delivery-notes' ),
69
- 'setting' => __( 'Show "Print Receipt" button', 'woocommerce-delivery-notes' )
70
- )
71
- ) )
72
- ) );
73
-
74
- // Add the default template as first item after filter hooks passed
75
- array_unshift( self::$template_registrations, array(
76
- 'type' => 'order',
77
- 'labels' => array(
78
- 'name' => __( 'Order', 'woocommerce-delivery-notes' ),
79
- 'name_plural' => __( 'Orders', 'woocommerce-delivery-notes' ),
80
- 'print' => __( 'Print Order', 'woocommerce-delivery-notes' ),
81
- 'print_plural' => __( 'Print Orders', 'woocommerce-delivery-notes' ),
82
- 'message' => null,
83
- 'message_plural' => null,
84
- 'setting' => null
85
  )
86
- ) );
87
 
88
- // Template styles
89
  self::$template_styles = apply_filters( 'wcdn_template_styles', array() );
90
 
91
- // Add the default style as first item after filter hooks passed
92
- array_unshift( self::$template_styles, array(
93
- 'name' => __( 'Default', 'woocommerce-delivery-notes' ),
94
- 'type' => 'default',
95
- 'path' => WooCommerce_Delivery_Notes::$plugin_path . 'templates/print-order/',
96
- 'url' => WooCommerce_Delivery_Notes::$plugin_url . 'templates/print-order/'
97
- ) );
 
 
 
98
 
99
- // Default template
100
  $this->template = self::$template_registrations[0];
101
 
102
- // Build all template locations
103
  $this->template_locations = $this->build_template_locations();
104
 
105
- // Add the endpoint for the frontend
106
  $this->api_endpoints = array(
107
- 'print-order' => get_option( 'wcdn_print_order_page_endpoint', 'print-order' )
108
  );
109
 
110
- // Insert the query vars
111
  $this->query_vars = array(
112
  'print-order-type',
113
- 'print-order-email'
114
  );
115
 
116
- // Load the hooks
117
  add_action( 'init', array( $this, 'load_hooks' ) );
118
  add_filter( 'query_vars', array( $this, 'add_query_vars' ) );
119
  add_action( 'parse_request', array( $this, 'parse_request' ) );
120
  add_action( 'template_redirect', array( $this, 'template_redirect_theme' ) );
121
  add_action( 'wp_ajax_print_order', array( $this, 'template_redirect_admin' ) );
122
- add_action( 'wcdn_after_items', array( $this, 'wdn_add_extra_data_after_items' ), 10 , 1 );
123
  }
124
 
125
- public function wdn_add_extra_data_after_items ( $order ) {
126
-
 
 
 
 
 
127
  /**
128
  * Local pickup plus plugin is active
129
  */
130
- if ( class_exists( "WC_Local_Pickup_Plus") ) {
131
-
132
  $cdn_local_pickup_plugin_plugins_version = wc_local_pickup_plus()->get_version();
133
 
134
- if( version_compare( $cdn_local_pickup_plugin_plugins_version, '2.0.0', ">=" ) ) {
135
- $cdn_local_pickup_object = new WC_Local_Pickup_Plus_Orders();
136
- $local_pickup = wc_local_pickup_plus();
137
  $cdn_local_pickup_locations = $cdn_local_pickup_object->get_order_pickup_data( $order );
138
  $cdn_local_pickup__shipping_object = $local_pickup->get_shipping_method_instance();
139
- WooCommerce_Delivery_Notes_Print::cdn_print_local_pickup_address( $cdn_local_pickup_locations, $cdn_local_pickup__shipping_object );
140
  }
141
  }
142
  }
143
 
 
 
 
 
 
 
144
  public function cdn_print_local_pickup_address( $cdn_local_pickup_locations, $shipping_method ) {
145
 
146
  $package_number = 1;
147
  $packages_count = count( $cdn_local_pickup_locations );
148
- foreach ( $cdn_local_pickup_locations as $pickup_meta ) :
149
- ?>
150
  <div>
151
  <?php if ( $packages_count > 1 ) : ?>
152
- <h5><?php echo sprintf( is_rtl() ? '#%2$s %1$s': '%1$s #%2$s', esc_html( $shipping_method->get_method_title() ), $package_number ); ?></h5>
153
  <?php endif; ?>
154
  <ul>
155
  <?php foreach ( $pickup_meta as $label => $value ) : ?>
@@ -164,14 +251,15 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
164
  </ul>
165
  <?php $package_number++; ?>
166
  </div>
167
- <?php
168
- endforeach;
169
  }
 
170
  /**
171
  * Load the init hooks
172
  */
173
  public function load_hooks() {
174
- // Add the endpoints
175
  $this->add_endpoints();
176
  }
177
 
@@ -181,13 +269,13 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
181
  * generate the print template and link.
182
  */
183
  public function add_endpoints() {
184
- foreach( $this->api_endpoints as $var ) {
185
  add_rewrite_endpoint( $var, EP_PAGES );
186
  }
187
 
188
  // Flush the rules when the transient is set.
189
  // This is important to make the endpoint work.
190
- if( get_transient( 'wcdn_flush_rewrite_rules' ) == true ) {
191
  delete_transient( 'wcdn_flush_rewrite_rules' );
192
  flush_rewrite_rules();
193
  }
@@ -195,26 +283,30 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
195
 
196
  /**
197
  * Add the query vars to the url
 
 
198
  */
199
  public function add_query_vars( $vars ) {
200
- foreach( $this->query_vars as $var ) {
201
  $vars[] = $var;
202
  }
203
- return $vars;
204
  }
205
 
206
  /**
207
  * Parse the query variables
 
 
208
  */
209
  public function parse_request( $wp ) {
210
  // Map endpoint keys to their query var keys, when another endpoint name was set.
211
- foreach( $this->api_endpoints as $key => $var ) {
212
- if( isset( $_GET[$var] ) ) {
213
- // changed
214
- $wdn_get_end_point_var = sanitize_text_field($_GET[$var]);
215
- $wp->query_vars[$key] = $wdn_get_end_point_var;
216
- } elseif ( isset( $wp->query_vars[$var] ) ) {
217
- $wp->query_vars[$key] = $wp->query_vars[$var];
218
  }
219
  }
220
  }
@@ -225,41 +317,41 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
225
  public function build_template_locations() {
226
  $wc_template_directory = WC_TEMPLATE_PATH . 'print-order/';
227
 
228
- // Get the paths for custom styles
229
  $settings_type = get_option( 'wcdn_template_style' );
230
  $settings_path = null;
231
- $settings_url = null;
232
- if( isset( $settings_type ) && $settings_type !== 'default' ) {
233
- foreach( self::$template_styles as $template_style ) {
234
- if( $settings_type === $template_style['type'] ) {
235
  $settings_path = $template_style['path'];
236
- $settings_url = $template_style['url'];
237
  break;
238
  }
239
  }
240
  }
241
 
242
- // Build the locations
243
  $locations = array(
244
  'child_theme' => array(
245
  'path' => trailingslashit( get_stylesheet_directory() ) . $wc_template_directory,
246
- 'url' => trailingslashit( get_stylesheet_directory_uri() ) . $wc_template_directory
247
  ),
248
 
249
- 'theme' => array(
250
  'path' => trailingslashit( get_template_directory() ) . $wc_template_directory,
251
- 'url' => trailingslashit( get_template_directory_uri() ) . $wc_template_directory
252
  ),
253
 
254
- 'settings' => array(
255
  'path' => $settings_path,
256
- 'url' => $settings_url
257
  ),
258
 
259
- 'plugin' => array(
260
  'path' => self::$template_styles[0]['path'],
261
- 'url' => self::$template_styles[0]['url']
262
- )
263
  );
264
 
265
  return $locations;
@@ -270,10 +362,10 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
270
  */
271
  public function template_redirect_theme() {
272
  global $wp;
273
- // Check the page url and display the template when on my-account page
274
- if( !empty( $wp->query_vars['print-order'] ) && is_account_page() ) {
275
- $type = !empty( $wp->query_vars['print-order-type'] ) ? $wp->query_vars['print-order-type'] : null;
276
- $email = !empty( $wp->query_vars['print-order-email'] ) ? $wp->query_vars['print-order-email'] : null;
277
  $this->generate_template( $wp->query_vars['print-order'], $type, $email );
278
  exit;
279
  }
@@ -283,13 +375,13 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
283
  * Template handling in the back-end
284
  */
285
  public function template_redirect_admin() {
286
- // Let the backend only access the page
287
- // changed
288
- if( is_admin() && current_user_can( 'edit_shop_orders' ) && !empty( $_REQUEST['print-order'] ) && !empty( $_REQUEST['action'] ) ) {
289
- $type = !empty( $_REQUEST['print-order-type'] ) ? sanitize_text_field ( $_REQUEST['print-order-type'] ) : null;
290
- $email = !empty( $_REQUEST['print-order-email'] ) ? sanitize_email ( $_REQUEST['print-order-email'] ) : null;
291
- // changed
292
- $wdn_get_print_order = sanitize_text_field ( $_GET['print-order'] );
293
  $this->generate_template( $wdn_get_print_order, $type, $email );
294
  exit;
295
  }
@@ -298,52 +390,59 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
298
 
299
  /**
300
  * Generate the template
 
 
 
 
301
  */
302
  public function generate_template( $order_ids, $template_type = 'order', $order_email = null ) {
303
  global $post, $wp;
304
 
305
- // Explode the ids when needed
306
- if( !is_array( $order_ids ) ) {
307
- $this->order_ids = array_filter( explode('-', $order_ids ) );
308
  }
309
 
310
- // Set the current template
311
- foreach( self::$template_registrations as $template_registration ) {
312
- if( $template_type == $template_registration['type'] ) {
313
  $this->template = $template_registration;
314
  break;
315
  }
316
  }
317
 
318
- // Set the email
319
- if( empty( $order_email ) ) {
320
  $this->order_email = null;
321
  } else {
322
  $this->order_email = strtolower( $order_email );
323
  }
324
 
325
- // Create the orders and check permissions
326
  $populated = $this->populate_orders();
327
 
328
- // Only continue if the orders are populated
329
- if( !$populated ) {
330
  die();
331
  }
332
 
333
- // Load the print template html
334
  $location = $this->get_template_file_location( 'print-order.php' );
335
  wc_get_template( 'print-order.php', null, $location, $location );
336
  exit;
337
  }
338
 
339
  /**
340
- * Find the location of a template file
 
 
 
341
  */
342
  public function get_template_file_location( $name, $url_mode = false ) {
343
  $found = '';
344
- foreach( $this->template_locations as $template_location ) {
345
- if( isset( $template_location['path'] ) && file_exists( trailingslashit( $template_location['path'] ) . $name ) ) {
346
- if( $url_mode ) {
347
  $found = $template_location['url'];
348
  } else {
349
  $found = $template_location['path'];
@@ -356,157 +455,164 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
356
 
357
  /**
358
  * Get print page url
 
 
 
 
 
359
  */
360
  public function get_print_page_url( $order_ids, $template_type = 'order', $order_email = null, $permalink = false ) {
361
- // Explode the ids when needed
362
- if( !is_array( $order_ids ) ) {
363
  $order_ids = array_filter( explode( '-', $order_ids ) );
364
  }
365
 
366
- // Build the args
367
  $args = array();
368
 
369
- // Set the template type arg
370
- foreach( self::$template_registrations as $template_registration ) {
371
- if( $template_type == $template_registration['type'] && $template_type != 'order' ) {
372
  $args = wp_parse_args( array( 'print-order-type' => $template_type ), $args );
373
  break;
374
  }
375
  }
376
 
377
- // Set the email arg
378
- if( !empty( $order_email ) ) {
379
  $args = wp_parse_args( array( 'print-order-email' => $order_email ), $args );
380
  }
381
 
382
- // Generate the url
383
  $order_ids_slug = implode( '-', $order_ids );
384
 
385
- // Create another url depending on where the user prints. This
386
- // prevents some issues with ssl when the my-account page is
387
- // secured with ssl but the admin isn't.
388
- if( is_admin() && current_user_can( 'edit_shop_orders' ) && $permalink == false ) {
389
- // For the admin we use the ajax.php for better security
390
- $args = wp_parse_args( array( 'action' => 'print_order' ), $args );
391
  $base_url = admin_url( 'admin-ajax.php' );
392
  $endpoint = 'print-order';
393
 
394
- // Add the order ids and create the url
395
  $url = add_query_arg( $endpoint, $order_ids_slug, $base_url );
396
  } else {
397
- // For the theme
398
  $base_url = wc_get_page_permalink( 'myaccount' );
399
  $endpoint = $this->api_endpoints['print-order'];
400
 
401
- // Add the order ids and create the url
402
- if( get_option( 'permalink_structure' ) ) {
403
  $url = trailingslashit( trailingslashit( $base_url ) . $endpoint . '/' . $order_ids_slug );
404
  } else {
405
  $url = add_query_arg( $endpoint, $order_ids_slug, $base_url );
406
  }
407
  }
408
 
409
- // Add all other args
410
  $url = add_query_arg( $args, $url );
411
 
412
  return esc_url( $url );
413
  }
414
 
415
  /**
416
- * Create the orders list and check the permissions
417
  */
418
  private function populate_orders() {
419
  $this->orders = array();
420
 
421
- // Get the orders
422
- $args = array(
423
  'posts_per_page' => -1,
424
- 'post_type' => 'shop_order',
425
- 'post_status' => 'any',
426
- 'post__in' => $this->order_ids,
427
- 'orderby' => 'post__in'
428
  );
429
  $posts = get_posts( $args );
430
 
431
- // All orders should exist
432
- if( count( $posts ) !== count( $this->order_ids ) ) {
433
  $this->orders = null;
434
  return false;
435
  }
436
 
437
- // Check permissons of the user to determine
438
- // if the orders should be populated.
439
- foreach( $posts as $post ) {
440
  $order = new WC_Order( $post->ID );
441
 
442
- $wdn_order_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_id() : $order->id;
443
- // Logged in users
444
- if( is_user_logged_in() && ( !current_user_can( 'edit_shop_orders' ) && !current_user_can( 'view_order', $wdn_order_id ) ) ) {
445
  $this->orders = null;
446
  return false;
447
  }
448
 
449
- $wdn_order_billing_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_billing_email() : $order->billing_email;
450
-
451
 
452
- // An email is required for not logged in users
453
- if( !is_user_logged_in() && ( empty( $this->order_email ) || strtolower( $wdn_order_billing_id ) != $this->order_email ) ) {
454
  $this->orders = null;
455
  return false;
456
  }
457
 
458
- // Save the order to get it without an additional database call
459
- $this->orders[$post->ID] = $order;
460
  }
461
  return true;
462
  }
463
 
464
  /**
465
- * Get the order
 
 
466
  */
467
  public function get_order( $order_id ) {
468
- if( isset( $this->orders[$order_id] ) ) {
469
- return $this->orders[$order_id];
470
  }
471
- return;
472
  }
473
 
474
  /**
475
- * Get the order invoice number
 
 
476
  */
477
  public function get_order_invoice_number( $order_id ) {
478
- $invoice_count = intval( get_option( 'wcdn_invoice_number_count', 1 ) );
479
  $invoice_prefix = get_option( 'wcdn_invoice_number_prefix' );
480
  $invoice_suffix = get_option( 'wcdn_invoice_number_suffix' );
481
 
482
- // Add the invoice number to the order when it doesn't yet exist
483
- $meta_key = '_wcdn_invoice_number';
484
  $meta_added = add_post_meta( $order_id, $meta_key, $invoice_prefix . $invoice_count . $invoice_suffix, true );
485
 
486
- // Update the total count
487
- if( $meta_added ) {
488
- update_option( 'wcdn_invoice_number_count', $invoice_count + 1 );
489
  }
490
 
491
- // Get the invoice number
492
  return apply_filters( 'wcdn_order_invoice_number', get_post_meta( $order_id, $meta_key, true ) );
493
  }
494
 
495
  /**
496
- * Get the order invoice date
 
 
497
  */
498
  public function get_order_invoice_date( $order_id ) {
499
- // Add the invoice date to the order when it doesn't yet exist
500
- $meta_key = '_wcdn_invoice_date';
501
  $meta_added = add_post_meta( $order_id, $meta_key, time(), true );
502
 
503
- // Get the invoice date
504
- $meta_date = get_post_meta( $order_id, $meta_key, true );
505
- $formatted_date = date_i18n( get_option('date_format'), $meta_date );
506
  return apply_filters( 'wcdn_order_invoice_date', $formatted_date, $meta_date );
507
  }
508
 
509
  }
510
 
511
  }
512
- ?>
1
  <?php
2
+ /**
3
+ * Print class
4
+ *
5
+ * @package woocommerce-print-invoice-delivery-notes
6
+ */
7
 
8
  /**
9
  * Exit if accessed directly
10
  */
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
  exit;
13
  }
14
 
15
  /**
16
  * Print class
17
  */
18
+ if ( ! class_exists( 'WCDN_Print' ) ) {
19
 
20
+ /**
21
+ * WooCommerce Delivery Notes Print class.
22
+ */
23
+ class WCDN_Print {
24
 
25
+ /**
26
+ * Template registrations
27
+ *
28
+ * @var array $template_registrations
29
+ */
30
  public static $template_registrations;
31
+
32
+ /**
33
+ * Template styles
34
+ *
35
+ * @var array $template_styles
36
+ */
37
  public static $template_styles;
38
 
39
+ /**
40
+ * Template locations
41
+ *
42
+ * @var array $template_locations
43
+ */
44
  public $template_locations;
45
+
46
+ /**
47
+ * Default Template
48
+ *
49
+ * @var array $template
50
+ */
51
  public $template;
52
 
53
+ /**
54
+ * API Endpoints
55
+ *
56
+ * @var array $api_endpoints
57
+ */
58
  public $api_endpoints;
59
+
60
+ /**
61
+ * Query vars
62
+ *
63
+ * @var array $query_vars
64
+ */
65
  public $query_vars;
66
 
67
+ /**
68
+ * Order IDs
69
+ *
70
+ * @var array $order_ids
71
+ */
72
  public $order_ids;
73
+
74
+ /**
75
+ * Order email
76
+ *
77
+ * @var array $order_email
78
+ */
79
  public $order_email;
80
+
81
+ /**
82
+ * Orders
83
+ *
84
+ * @var array $orders
85
+ */
86
  public $orders;
87
 
88
  /**
89
  * Constructor
90
  */
91
  public function __construct() {
92
+ // Define the templates.
93
+ self::$template_registrations = apply_filters(
94
+ 'wcdn_template_registration',
95
+ array(
96
+ apply_filters(
97
+ 'wcdn_template_registration_invoice',
98
+ array(
99
+ 'type' => 'invoice',
100
+ 'labels' => array(
101
+ 'name' => __( 'Invoice', 'woocommerce-delivery-notes' ),
102
+ 'name_plural' => __( 'Invoices', 'woocommerce-delivery-notes' ),
103
+ 'print' => __( 'Print Invoice', 'woocommerce-delivery-notes' ),
104
+ 'print_plural' => __( 'Print Invoices', 'woocommerce-delivery-notes' ),
105
+ 'message' => __( 'Invoice created.', 'woocommerce-delivery-notes' ),
106
+ 'message_plural' => __( 'Invoices created.', 'woocommerce-delivery-notes' ),
107
+ 'setting' => __( 'Show "Print Invoice" button', 'woocommerce-delivery-notes' ),
108
+ ),
109
+ )
110
+ ),
111
+ apply_filters(
112
+ 'wcdn_template_registration_delivery_note',
113
+ array(
114
+ 'type' => 'delivery-note',
115
+ 'labels' => array(
116
+ 'name' => __( 'Delivery Note', 'woocommerce-delivery-notes' ),
117
+ 'name_plural' => __( 'Delivery Notes', 'woocommerce-delivery-notes' ),
118
+ 'print' => __( 'Print Delivery Note', 'woocommerce-delivery-notes' ),
119
+ 'print_plural' => __( 'Print Delivery Notes', 'woocommerce-delivery-notes' ),
120
+ 'message' => __( 'Delivery Note created.', 'woocommerce-delivery-notes' ),
121
+ 'message_plural' => __( 'Delivery Notes created.', 'woocommerce-delivery-notes' ),
122
+ 'setting' => __( 'Show "Print Delivery Note" button', 'woocommerce-delivery-notes' ),
123
+ ),
124
+ )
125
+ ),
126
+ apply_filters(
127
+ 'wcdn_template_registration_receipt',
128
+ array(
129
+ 'type' => 'receipt',
130
+ 'labels' => array(
131
+ 'name' => __( 'Receipt', 'woocommerce-delivery-notes' ),
132
+ 'name_plural' => __( 'Receipts', 'woocommerce-delivery-notes' ),
133
+ 'print' => __( 'Print Receipt', 'woocommerce-delivery-notes' ),
134
+ 'print_plural' => __( 'Print Receipts', 'woocommerce-delivery-notes' ),
135
+ 'message' => __( 'Receipt created.', 'woocommerce-delivery-notes' ),
136
+ 'message_plural' => __( 'Receipts created.', 'woocommerce-delivery-notes' ),
137
+ 'setting' => __( 'Show "Print Receipt" button', 'woocommerce-delivery-notes' ),
138
+ ),
139
+ )
140
+ ),
141
+ )
142
+ );
143
+
144
+ // Add the default template as first item after filter hooks passed.
145
+ array_unshift(
146
+ self::$template_registrations,
147
+ array(
148
+ 'type' => 'order',
149
  'labels' => array(
150
+ 'name' => __( 'Order', 'woocommerce-delivery-notes' ),
151
+ 'name_plural' => __( 'Orders', 'woocommerce-delivery-notes' ),
152
+ 'print' => __( 'Print Order', 'woocommerce-delivery-notes' ),
153
+ 'print_plural' => __( 'Print Orders', 'woocommerce-delivery-notes' ),
154
+ 'message' => null,
155
+ 'message_plural' => null,
156
+ 'setting' => null,
157
+ ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  )
159
+ );
160
 
161
+ // Template styles.
162
  self::$template_styles = apply_filters( 'wcdn_template_styles', array() );
163
 
164
+ // Add the default style as first item after filter hooks passed.
165
+ array_unshift(
166
+ self::$template_styles,
167
+ array(
168
+ 'name' => __( 'Default', 'woocommerce-delivery-notes' ),
169
+ 'type' => 'default',
170
+ 'path' => WooCommerce_Delivery_Notes::$plugin_path . 'templates/print-order/',
171
+ 'url' => WooCommerce_Delivery_Notes::$plugin_url . 'templates/print-order/',
172
+ )
173
+ );
174
 
175
+ // Default template.
176
  $this->template = self::$template_registrations[0];
177
 
178
+ // Build all template locations.
179
  $this->template_locations = $this->build_template_locations();
180
 
181
+ // Add the endpoint for the frontend.
182
  $this->api_endpoints = array(
183
+ 'print-order' => get_option( 'wcdn_print_order_page_endpoint', 'print-order' ),
184
  );
185
 
186
+ // Insert the query vars.
187
  $this->query_vars = array(
188
  'print-order-type',
189
+ 'print-order-email',
190
  );
191
 
192
+ // Load the hooks.
193
  add_action( 'init', array( $this, 'load_hooks' ) );
194
  add_filter( 'query_vars', array( $this, 'add_query_vars' ) );
195
  add_action( 'parse_request', array( $this, 'parse_request' ) );
196
  add_action( 'template_redirect', array( $this, 'template_redirect_theme' ) );
197
  add_action( 'wp_ajax_print_order', array( $this, 'template_redirect_admin' ) );
198
+ add_action( 'wcdn_after_items', array( $this, 'wdn_add_extra_data_after_items' ), 10, 1 );
199
  }
200
 
201
+ /**
202
+ * Add extra data after items
203
+ *
204
+ * @param object $order Order.
205
+ */
206
+ public function wdn_add_extra_data_after_items( $order ) {
207
+
208
  /**
209
  * Local pickup plus plugin is active
210
  */
211
+ if ( class_exists( 'WC_Local_Pickup_Plus' ) ) {
212
+
213
  $cdn_local_pickup_plugin_plugins_version = wc_local_pickup_plus()->get_version();
214
 
215
+ if ( version_compare( $cdn_local_pickup_plugin_plugins_version, '2.0.0', '>=' ) ) {
216
+ $cdn_local_pickup_object = new WC_Local_Pickup_Plus_Orders();
217
+ $local_pickup = wc_local_pickup_plus();
218
  $cdn_local_pickup_locations = $cdn_local_pickup_object->get_order_pickup_data( $order );
219
  $cdn_local_pickup__shipping_object = $local_pickup->get_shipping_method_instance();
220
+ self::cdn_print_local_pickup_address( $cdn_local_pickup_locations, $cdn_local_pickup__shipping_object );
221
  }
222
  }
223
  }
224
 
225
+ /**
226
+ * Print Local Pickup Address
227
+ *
228
+ * @param array $cdn_local_pickup_locations Local pickup locations.
229
+ * @param object $shipping_method Shipping method.
230
+ */
231
  public function cdn_print_local_pickup_address( $cdn_local_pickup_locations, $shipping_method ) {
232
 
233
  $package_number = 1;
234
  $packages_count = count( $cdn_local_pickup_locations );
235
+ foreach ( $cdn_local_pickup_locations as $pickup_meta ) :
236
+ ?>
237
  <div>
238
  <?php if ( $packages_count > 1 ) : ?>
239
+ <h5><?php echo wp_kses_post( sprintf( is_rtl() ? '#%2$s %1$s' : '%1$s #%2$s', esc_html( $shipping_method->get_method_title() ), $package_number ) ); ?></h5>
240
  <?php endif; ?>
241
  <ul>
242
  <?php foreach ( $pickup_meta as $label => $value ) : ?>
251
  </ul>
252
  <?php $package_number++; ?>
253
  </div>
254
+ <?php
255
+ endforeach;
256
  }
257
+
258
  /**
259
  * Load the init hooks
260
  */
261
  public function load_hooks() {
262
+ // Add the endpoints.
263
  $this->add_endpoints();
264
  }
265
 
269
  * generate the print template and link.
270
  */
271
  public function add_endpoints() {
272
+ foreach ( $this->api_endpoints as $var ) {
273
  add_rewrite_endpoint( $var, EP_PAGES );
274
  }
275
 
276
  // Flush the rules when the transient is set.
277
  // This is important to make the endpoint work.
278
+ if ( '1' === get_transient( 'wcdn_flush_rewrite_rules' ) ) {
279
  delete_transient( 'wcdn_flush_rewrite_rules' );
280
  flush_rewrite_rules();
281
  }
283
 
284
  /**
285
  * Add the query vars to the url
286
+ *
287
+ * @param array $vars Query variables.
288
  */
289
  public function add_query_vars( $vars ) {
290
+ foreach ( $this->query_vars as $var ) {
291
  $vars[] = $var;
292
  }
293
+ return $vars;
294
  }
295
 
296
  /**
297
  * Parse the query variables
298
+ *
299
+ * @param object $wp WP Object.
300
  */
301
  public function parse_request( $wp ) {
302
  // Map endpoint keys to their query var keys, when another endpoint name was set.
303
+ foreach ( $this->api_endpoints as $key => $var ) {
304
+ if ( isset( $_GET[ $var ] ) ) {
305
+ // changed.
306
+ $wdn_get_end_point_var = sanitize_text_field( wp_unslash( $_GET[ $var ] ) );
307
+ $wp->query_vars[ $key ] = $wdn_get_end_point_var;
308
+ } elseif ( isset( $wp->query_vars[ $var ] ) ) {
309
+ $wp->query_vars[ $key ] = $wp->query_vars[ $var ];
310
  }
311
  }
312
  }
317
  public function build_template_locations() {
318
  $wc_template_directory = WC_TEMPLATE_PATH . 'print-order/';
319
 
320
+ // Get the paths for custom styles.
321
  $settings_type = get_option( 'wcdn_template_style' );
322
  $settings_path = null;
323
+ $settings_url = null;
324
+ if ( isset( $settings_type ) && 'default' !== $settings_type ) {
325
+ foreach ( self::$template_styles as $template_style ) {
326
+ if ( $settings_type === $template_style['type'] ) {
327
  $settings_path = $template_style['path'];
328
+ $settings_url = $template_style['url'];
329
  break;
330
  }
331
  }
332
  }
333
 
334
+ // Build the locations.
335
  $locations = array(
336
  'child_theme' => array(
337
  'path' => trailingslashit( get_stylesheet_directory() ) . $wc_template_directory,
338
+ 'url' => trailingslashit( get_stylesheet_directory_uri() ) . $wc_template_directory,
339
  ),
340
 
341
+ 'theme' => array(
342
  'path' => trailingslashit( get_template_directory() ) . $wc_template_directory,
343
+ 'url' => trailingslashit( get_template_directory_uri() ) . $wc_template_directory,
344
  ),
345
 
346
+ 'settings' => array(
347
  'path' => $settings_path,
348
+ 'url' => $settings_url,
349
  ),
350
 
351
+ 'plugin' => array(
352
  'path' => self::$template_styles[0]['path'],
353
+ 'url' => self::$template_styles[0]['url'],
354
+ ),
355
  );
356
 
357
  return $locations;
362
  */
363
  public function template_redirect_theme() {
364
  global $wp;
365
+ // Check the page url and display the template when on my-account page.
366
+ if ( ! empty( $wp->query_vars['print-order'] ) && is_account_page() ) {
367
+ $type = ! empty( $wp->query_vars['print-order-type'] ) ? $wp->query_vars['print-order-type'] : null;
368
+ $email = ! empty( $wp->query_vars['print-order-email'] ) ? $wp->query_vars['print-order-email'] : null;
369
  $this->generate_template( $wp->query_vars['print-order'], $type, $email );
370
  exit;
371
  }
375
  * Template handling in the back-end
376
  */
377
  public function template_redirect_admin() {
378
+ // Let the backend only access the page.
379
+ // changed.
380
+ if ( is_admin() && current_user_can( 'edit_shop_orders' ) && ! empty( $_REQUEST['print-order'] ) && ! empty( $_REQUEST['action'] ) ) {
381
+ $type = ! empty( $_REQUEST['print-order-type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['print-order-type'] ) ) : null;
382
+ $email = ! empty( $_REQUEST['print-order-email'] ) ? sanitize_email( wp_unslash( $_REQUEST['print-order-email'] ) ) : null;
383
+ // changed.
384
+ $wdn_get_print_order = isset( $_GET['print-order'] ) ? sanitize_text_field( wp_unslash( $_GET['print-order'] ) ) : '';
385
  $this->generate_template( $wdn_get_print_order, $type, $email );
386
  exit;
387
  }
390
 
391
  /**
392
  * Generate the template
393
+ *
394
+ * @param array $order_ids Order IDs.
395
+ * @param string $template_type Template type.
396
+ * @param string $order_email Order email.
397
  */
398
  public function generate_template( $order_ids, $template_type = 'order', $order_email = null ) {
399
  global $post, $wp;
400
 
401
+ // Explode the ids when needed.
402
+ if ( ! is_array( $order_ids ) ) {
403
+ $this->order_ids = array_filter( explode( '-', $order_ids ) );
404
  }
405
 
406
+ // Set the current template.
407
+ foreach ( self::$template_registrations as $template_registration ) {
408
+ if ( $template_type === $template_registration['type'] ) {
409
  $this->template = $template_registration;
410
  break;
411
  }
412
  }
413
 
414
+ // Set the email.
415
+ if ( empty( $order_email ) ) {
416
  $this->order_email = null;
417
  } else {
418
  $this->order_email = strtolower( $order_email );
419
  }
420
 
421
+ // Create the orders and check permissions.
422
  $populated = $this->populate_orders();
423
 
424
+ // Only continue if the orders are populated.
425
+ if ( ! $populated ) {
426
  die();
427
  }
428
 
429
+ // Load the print template html.
430
  $location = $this->get_template_file_location( 'print-order.php' );
431
  wc_get_template( 'print-order.php', null, $location, $location );
432
  exit;
433
  }
434
 
435
  /**
436
+ * Find the location of a template file.
437
+ *
438
+ * @param string $name Template name.
439
+ * @param boolean $url_mode URL mode.
440
  */
441
  public function get_template_file_location( $name, $url_mode = false ) {
442
  $found = '';
443
+ foreach ( $this->template_locations as $template_location ) {
444
+ if ( isset( $template_location['path'] ) && file_exists( trailingslashit( $template_location['path'] ) . $name ) ) {
445
+ if ( $url_mode ) {
446
  $found = $template_location['url'];
447
  } else {
448
  $found = $template_location['path'];
455
 
456
  /**
457
  * Get print page url
458
+ *
459
+ * @param array $order_ids Order ids.
460
+ * @param string $template_type Template type.
461
+ * @param string $order_email Order email.
462
+ * @param boolean $permalink Permalink.
463
  */
464
  public function get_print_page_url( $order_ids, $template_type = 'order', $order_email = null, $permalink = false ) {
465
+ // Explode the ids when needed.
466
+ if ( ! is_array( $order_ids ) ) {
467
  $order_ids = array_filter( explode( '-', $order_ids ) );
468
  }
469
 
470
+ // Build the args.
471
  $args = array();
472
 
473
+ // Set the template type arg.
474
+ foreach ( self::$template_registrations as $template_registration ) {
475
+ if ( $template_type === $template_registration['type'] && 'order' !== $template_type ) {
476
  $args = wp_parse_args( array( 'print-order-type' => $template_type ), $args );
477
  break;
478
  }
479
  }
480
 
481
+ // Set the email arg.
482
+ if ( ! empty( $order_email ) ) {
483
  $args = wp_parse_args( array( 'print-order-email' => $order_email ), $args );
484
  }
485
 
486
+ // Generate the url.
487
  $order_ids_slug = implode( '-', $order_ids );
488
 
489
+ // Create another url depending on where the user prints. This prevents some issues with ssl when the my-account page is secured with ssl but the admin isn't.
490
+ if ( is_admin() && current_user_can( 'edit_shop_orders' ) && false === $permalink ) {
491
+ // For the admin we use the ajax.php for better security.
492
+ $args = wp_parse_args( array( 'action' => 'print_order' ), $args );
 
 
493
  $base_url = admin_url( 'admin-ajax.php' );
494
  $endpoint = 'print-order';
495
 
496
+ // Add the order ids and create the url.
497
  $url = add_query_arg( $endpoint, $order_ids_slug, $base_url );
498
  } else {
499
+ // For the theme.
500
  $base_url = wc_get_page_permalink( 'myaccount' );
501
  $endpoint = $this->api_endpoints['print-order'];
502
 
503
+ // Add the order ids and create the url.
504
+ if ( get_option( 'permalink_structure' ) ) {
505
  $url = trailingslashit( trailingslashit( $base_url ) . $endpoint . '/' . $order_ids_slug );
506
  } else {
507
  $url = add_query_arg( $endpoint, $order_ids_slug, $base_url );
508
  }
509
  }
510
 
511
+ // Add all other args.
512
  $url = add_query_arg( $args, $url );
513
 
514
  return esc_url( $url );
515
  }
516
 
517
  /**
518
+ * Create the orders list and check the permissions.
519
  */
520
  private function populate_orders() {
521
  $this->orders = array();
522
 
523
+ // Get the orders.
524
+ $args = array(
525
  'posts_per_page' => -1,
526
+ 'post_type' => 'shop_order',
527
+ 'post_status' => 'any',
528
+ 'post__in' => $this->order_ids,
529
+ 'orderby' => 'post__in',
530
  );
531
  $posts = get_posts( $args );
532
 
533
+ // All orders should exist.
534
+ if ( count( $posts ) !== count( $this->order_ids ) ) {
535
  $this->orders = null;
536
  return false;
537
  }
538
 
539
+ // Check permissons of the user to determine if the orders should be populated.
540
+ foreach ( $posts as $post ) {
 
541
  $order = new WC_Order( $post->ID );
542
 
543
+ $wdn_order_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) ? $order->get_id() : $order->id;
544
+ // Logged in users.
545
+ if ( is_user_logged_in() && ( ! current_user_can( 'edit_shop_orders' ) && ! current_user_can( 'view_order', $wdn_order_id ) ) ) {
546
  $this->orders = null;
547
  return false;
548
  }
549
 
550
+ $wdn_order_billing_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) ? $order->get_billing_email() : $order->billing_email;
 
551
 
552
+ // An email is required for not logged in users.
553
+ if ( ! is_user_logged_in() && ( empty( $this->order_email ) || strtolower( $wdn_order_billing_id ) !== $this->order_email ) ) {
554
  $this->orders = null;
555
  return false;
556
  }
557
 
558
+ // Save the order to get it without an additional database call.
559
+ $this->orders[ $post->ID ] = $order;
560
  }
561
  return true;
562
  }
563
 
564
  /**
565
+ * Get the order.
566
+ *
567
+ * @param int $order_id Order id.
568
  */
569
  public function get_order( $order_id ) {
570
+ if ( isset( $this->orders[ $order_id ] ) ) {
571
+ return $this->orders[ $order_id ];
572
  }
573
+ return false;
574
  }
575
 
576
  /**
577
+ * Get the order invoice number.
578
+ *
579
+ * @param int $order_id Order id.
580
  */
581
  public function get_order_invoice_number( $order_id ) {
582
+ $invoice_count = intval( get_option( 'wcdn_invoice_number_count', 1 ) );
583
  $invoice_prefix = get_option( 'wcdn_invoice_number_prefix' );
584
  $invoice_suffix = get_option( 'wcdn_invoice_number_suffix' );
585
 
586
+ // Add the invoice number to the order when it doesn't yet exist.
587
+ $meta_key = '_wcdn_invoice_number';
588
  $meta_added = add_post_meta( $order_id, $meta_key, $invoice_prefix . $invoice_count . $invoice_suffix, true );
589
 
590
+ // Update the total count.
591
+ if ( $meta_added ) {
592
+ update_option( 'wcdn_invoice_number_count', $invoice_count + 1 );
593
  }
594
 
595
+ // Get the invoice number.
596
  return apply_filters( 'wcdn_order_invoice_number', get_post_meta( $order_id, $meta_key, true ) );
597
  }
598
 
599
  /**
600
+ * Get the order invoice date.
601
+ *
602
+ * @param int $order_id Order id.
603
  */
604
  public function get_order_invoice_date( $order_id ) {
605
+ // Add the invoice date to the order when it doesn't yet exist.
606
+ $meta_key = '_wcdn_invoice_date';
607
  $meta_added = add_post_meta( $order_id, $meta_key, time(), true );
608
 
609
+ // Get the invoice date.
610
+ $meta_date = get_post_meta( $order_id, $meta_key, true );
611
+ $formatted_date = date_i18n( get_option( 'date_format' ), $meta_date );
612
  return apply_filters( 'wcdn_order_invoice_date', $formatted_date, $meta_date );
613
  }
614
 
615
  }
616
 
617
  }
618
+ ?>
includes/class-wcdn-settings.php CHANGED
@@ -1,35 +1,45 @@
1
  <?php
 
 
 
 
 
2
 
3
  /**
4
  * Exit if accessed directly
5
  */
6
- if ( !defined( 'ABSPATH' ) ) {
7
  exit;
8
  }
9
 
10
  /**
11
  * Settings class
12
  */
13
- if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
14
 
15
  /**
16
  * WooCommerce Print Delivery Notes
17
- *
18
  * @author Tyche Softwares
19
  * @package WooCommerce-Delivery-Notes/Settings
20
  */
21
- class WooCommerce_Delivery_Notes_Settings {
22
 
 
 
 
 
 
23
  public $id;
24
 
25
  /**
26
  * Constructor
27
  */
28
  public function __construct() {
29
- // Define default variables
30
  $this->id = 'wcdn-settings';
31
 
32
- // Load the hooks
33
  add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 200 );
34
  add_action( 'woocommerce_settings_start', array( $this, 'add_assets' ) );
35
  add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) );
@@ -38,16 +48,19 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
38
  add_action( 'woocommerce_admin_field_wcdn_image_select', array( $this, 'output_image_select' ) );
39
  add_action( 'wp_ajax_wcdn_settings_load_image', array( $this, 'load_image_ajax' ) );
40
  add_filter( 'wcdn_get_settings', array( $this, 'generate_template_type_fields' ), 10, 2 );
41
- add_action( 'woocommerce_admin_field_link' , array( &$this, 'wcdn_add_admin_field_reset_button' ) );
42
  }
43
 
44
  /**
45
  * It will add a reset tracking data button on the settting page.
 
46
  * @hook woocommerce_admin_field_link
 
 
47
  */
48
- public static function wcdn_add_admin_field_reset_button ( $value ) {
49
- if ( $value [ 'id' ] == 'ts_reset_tracking' ){
50
- do_action ( 'wcdn_add_new_settings', $value );
51
  }
52
  }
53
 
@@ -55,79 +68,85 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
55
  * Add the scripts
56
  */
57
  public function add_assets() {
58
- // Styles
59
- wp_enqueue_style( 'woocommerce-delivery-notes-admin', WooCommerce_Delivery_Notes::$plugin_url . 'css/admin.css' );
60
 
61
- // Scripts
62
  wp_enqueue_media();
63
- wp_enqueue_script( 'woocommerce-delivery-notes-print-link', WooCommerce_Delivery_Notes::$plugin_url . 'js/jquery.print-link.js', array( 'jquery' ) );
64
- wp_enqueue_script( 'woocommerce-delivery-notes-admin', WooCommerce_Delivery_Notes::$plugin_url . 'js/admin.js', array( 'jquery', 'custom-header', 'woocommerce-delivery-notes-print-link' ) );
65
 
66
- // Localize the script strings
67
  $translation = array( 'resetCounter' => __( 'Do you really want to reset the counter to zero? This process can\'t be undone.', 'woocommerce-delivery-notes' ) );
68
  wp_localize_script( 'woocommerce-delivery-notes-admin', 'WCDNText', $translation );
69
  }
70
 
71
  /**
72
  * Create a new settings tab
 
 
73
  */
74
  public function add_settings_page( $settings_tabs ) {
75
- $settings_tabs[$this->id] = __( 'Print', 'woocommerce-delivery-notes' );
76
  return $settings_tabs;
77
  }
78
 
79
  /**
80
- * Output the settings fields into the tab
81
  */
82
  public function output() {
83
  global $current_section;
84
  $settings = $this->get_settings( $current_section );
85
- woocommerce_admin_fields( $settings );
86
  }
87
 
88
  /**
89
  * Save the settings
90
  */
91
- function save() {
92
- global $current_section;
93
  set_transient( 'wcdn_flush_rewrite_rules', true );
94
  $settings = $this->get_settings( $current_section );
95
- woocommerce_update_options( $settings );
96
  }
97
 
98
  /**
99
  * Get the settings fields
 
 
100
  */
101
  public function get_settings( $section = '' ) {
102
- $wcdn_faq_url = admin_url( 'index.php?page=wcdn_faq_page' ) ;
103
- $settings = apply_filters( 'wcdn_get_settings_no_section',
104
- array(
105
- array(
106
- 'title' => __( 'Template', 'woocommerce-delivery-notes' ),
107
- 'type' => 'title',
108
- 'desc' => $this->get_template_description(),
109
- 'id' => 'general_options'
110
- ),
 
111
 
112
  array(
113
  'title' => __( 'Style', 'woocommerce-delivery-notes' ),
 
114
  'desc' => sprintf( __( 'The default print style. Read the <a href="%1$s">FAQ</a> to learn how to customize it.', 'woocommerce-delivery-notes' ), $wcdn_faq_url, '#' ),
115
  'id' => 'wcdn_template_style',
116
  'class' => 'wc-enhanced-select',
117
  'default' => '',
118
  'type' => 'select',
119
  'options' => $this->get_options_styles(),
120
- 'desc_tip' => false,
121
  ),
122
 
123
  array(
124
- 'title' => __( 'Shop Logo', 'woocommerce-delivery-notes' ),
125
- 'desc' => '',
126
- 'id' => 'wcdn_company_logo_image_id',
127
- 'css' => '',
128
- 'default' => '',
129
- 'type' => 'wcdn_image_select',
130
- 'desc_tip' => __( 'A shop logo representing your business. When the image is printed, its pixel density will automatically be eight times higher than the original. This means, 1 printed inch will correspond to about 288 pixels on the screen.', 'woocommerce-delivery-notes' )
131
  ),
132
 
133
  array(
@@ -137,7 +156,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
137
  'css' => 'min-width:100%;',
138
  'default' => '',
139
  'type' => 'text',
140
- 'desc_tip' => __( 'The shop name. Leave blank to use the default Website or Blog title defined in WordPress settings. The name will be ignored when a Logo is set.', 'woocommerce-delivery-notes' ),
141
  ),
142
 
143
  array(
@@ -147,7 +166,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
147
  'css' => 'min-width:100%;min-height:100px;',
148
  'default' => '',
149
  'type' => 'textarea',
150
- 'desc_tip' => true,
151
  ),
152
 
153
  array(
@@ -157,7 +176,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
157
  'css' => 'min-width:100%;min-height:100px;',
158
  'default' => '',
159
  'type' => 'textarea',
160
- 'desc_tip' => true,
161
  ),
162
 
163
  array(
@@ -167,7 +186,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
167
  'css' => 'min-width:100%;min-height:100px;',
168
  'default' => '',
169
  'type' => 'textarea',
170
- 'desc_tip' => true,
171
  ),
172
 
173
  array(
@@ -177,22 +196,22 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
177
  'css' => 'min-width:100%;min-height:100px;',
178
  'default' => '',
179
  'type' => 'textarea',
180
- 'desc_tip' => true,
181
  ),
182
 
183
  array(
184
- 'type' => 'sectionend',
185
- 'id' => 'general_options'
186
  ),
187
 
188
  array(
189
- 'title' => __( 'Pages & Buttons', 'woocommerce-delivery-notes' ),
190
- 'type' => 'title',
191
- 'desc' => '',
192
- 'id' => 'display_options'
193
- ),
194
 
195
- array(
196
  'title' => __( 'Print Page Endpoint', 'woocommerce-delivery-notes' ),
197
  'desc' => '',
198
  'id' => 'wcdn_print_order_page_endpoint',
@@ -203,50 +222,50 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
203
  ),
204
 
205
  array(
206
- 'title' => __( 'Email', 'woocommerce-delivery-notes' ),
207
- 'desc' => __( 'Show print link in customer emails', 'woocommerce-delivery-notes' ),
208
- 'id' => 'wcdn_email_print_link',
209
- 'default' => 'no',
210
- 'type' => 'checkbox',
211
- 'desc_tip' => __( 'This includes the emails for a new, processing and completed order. On top of that the customer invoice email also includes the link.', 'woocommerce-delivery-notes' )
 
 
 
 
 
 
 
 
 
212
  ),
213
 
214
  array(
215
- 'title' => __( 'My Account', 'woocommerce-delivery-notes' ),
216
- 'desc' => __( 'Show print button on the "View Order" page', 'woocommerce-delivery-notes' ),
217
- 'id' => 'wcdn_print_button_on_view_order_page',
218
- 'default' => 'no',
219
- 'type' => 'checkbox',
220
- 'checkboxgroup' => 'start'
221
  ),
222
 
223
  array(
224
- 'desc' => __( 'Show print buttons on the "My Account" page', 'woocommerce-delivery-notes' ),
225
- 'id' => 'wcdn_print_button_on_my_account_page',
226
- 'default' => 'no',
227
- 'type' => 'checkbox',
228
- 'checkboxgroup' => 'end'
229
  ),
230
 
231
- array(
232
- 'type' => 'sectionend',
233
- 'id' => 'display_options'
 
 
234
  ),
235
 
236
  array(
237
- 'title' => __( 'Invoice', 'woocommerce-delivery-notes' ),
238
- 'type' => 'title',
239
- 'desc' => '',
240
- 'id' => 'invoice_options'
241
- ),
242
-
243
- array(
244
- 'title' => __( 'Numbering', 'woocommerce-delivery-notes' ),
245
- 'desc' => __( 'Create invoice numbers', 'woocommerce-delivery-notes' ),
246
- 'id' => 'wcdn_create_invoice_number',
247
- 'default' => 'no',
248
- 'type' => 'checkbox',
249
- 'desc_tip' => ''
250
  ),
251
 
252
  array(
@@ -257,7 +276,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
257
  'css' => '',
258
  'default' => 1,
259
  'type' => 'number',
260
- 'desc_tip' => __( 'The next invoice number.', 'woocommerce-delivery-notes' )
261
  ),
262
 
263
  array(
@@ -268,7 +287,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
268
  'css' => '',
269
  'default' => '',
270
  'type' => 'text',
271
- 'desc_tip' => __( 'This text will be prepended to the invoice number.', 'woocommerce-delivery-notes' )
272
  ),
273
 
274
  array(
@@ -279,25 +298,29 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
279
  'css' => '',
280
  'default' => '',
281
  'type' => 'text',
282
- 'desc_tip' => __( 'This text will be appended to the invoice number.', 'woocommerce-delivery-notes' )
283
  ),
284
- apply_filters ( 'wcdn_add_settings_field', '' ),
285
- array(
286
- 'type' => 'sectionend',
287
- 'id' => 'invoice_options'
288
  ),
289
- )
290
- );
291
 
292
- return apply_filters( 'wcdn_get_settings', $settings, $section );
293
  }
294
 
295
  /**
296
- * Get the position of a setting inside the array
 
 
 
 
297
  */
298
  public function get_setting_position( $id, $settings, $type = null ) {
299
- foreach( $settings as $key => $value ) {
300
- if( isset( $value['id'] ) && $value['id'] == $id ) {
301
  return $key;
302
  }
303
  }
@@ -307,43 +330,46 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
307
 
308
  /**
309
  * Generate the template type setting fields
 
 
 
310
  */
311
  public function generate_template_type_fields( $settings, $section = '' ) {
312
  $position = $this->get_setting_position( 'wcdn_email_print_link', $settings );
313
- if( $position !== false ) {
314
  $new_settings = array();
315
 
316
- // Go through all registrations but remove the default 'order' type
317
- $template_registrations = WooCommerce_Delivery_Notes_Print::$template_registrations;
318
  array_splice( $template_registrations, 0, 1 );
319
  $end = count( $template_registrations ) - 1;
320
- foreach( $template_registrations as $index => $template_registration ) {
321
- $title = '';
322
- $desc_tip = '';
323
  $checkboxgroup = '';
324
 
325
- // Define the group settings
326
- if( $index == 0 ) {
327
- $title = __( 'Admin', 'woocommerce-delivery-notes' );
328
  $checkboxgroup = 'start';
329
- } else if( $index == $end ) {
330
- $desc_tip = __( 'The print buttons are available on the order listing and on the order detail screen.', 'woocommerce-delivery-notes' );
331
  $checkboxgroup = 'end';
332
  }
333
 
334
- // Create the setting
335
  $new_settings[] = array(
336
- 'title' => $title,
337
- 'desc' => $template_registration['labels']['setting'],
338
- 'id' => 'wcdn_template_type_' . $template_registration['type'],
339
- 'default' => 'no',
340
- 'type' => 'checkbox',
341
- 'checkboxgroup' => $checkboxgroup,
342
- 'desc_tip' => $desc_tip
343
  );
344
  }
345
 
346
- // Add the settings
347
  $settings = $this->array_merge_at( $settings, $new_settings, $position );
348
  }
349
 
@@ -351,24 +377,25 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
351
  }
352
 
353
  /**
354
- * Generate the description for the template settings
355
  */
356
  public function get_template_description() {
357
  $description = '';
358
- $args = array(
359
- 'post_type' => 'shop_order',
360
- 'post_status' => array( 'wc-pending', 'wc-processing', 'wc-on-hold', 'wc-completed', 'wc-cancelled', 'wc-refunded', 'wc-failed' ),
361
- 'posts_per_page' => 1
362
  );
363
- $query = new WP_Query( $args );
364
 
365
- // show template preview links when an order is available
366
- if( $query->have_posts() ) {
367
- $results = $query->get_posts();
368
- $test_id = $results[0]->ID;
369
- $invoice_url = wcdn_get_print_link( $test_id, 'invoice' );
370
  $delivery_note_url = wcdn_get_print_link( $test_id, 'delivery-note' );
371
- $receipt_url = wcdn_get_print_link( $test_id, 'receipt' );
 
372
  $description = sprintf( __( 'This section lets you customise the content. You can preview the <a href="%1$s" target="%4$s" class="%5$s">invoice</a>, <a href="%2$s" target="%4$s" class="%5$s">delivery note</a> or <a href="%3$s" target="%4$s" class="%5$s">receipt</a> template.', 'woocommerce-delivery-notes' ), $invoice_url, $delivery_note_url, $receipt_url, '_blank', '' );
373
  }
374
 
@@ -376,14 +403,14 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
376
  }
377
 
378
  /**
379
- * Generate the options for the template styles field
380
  */
381
  public function get_options_styles() {
382
  $options = array();
383
 
384
- foreach( WooCommerce_Delivery_Notes_Print::$template_styles as $template_style ) {
385
- if( is_array( $template_style ) && isset( $template_style['type'] ) && isset( $template_style['name'] ) ) {
386
- $options[$template_style['type']] = $template_style['name'];
387
  }
388
  }
389
 
@@ -391,46 +418,50 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
391
  }
392
 
393
  /**
394
- * Load image with ajax
395
  */
396
  public function load_image_ajax() {
397
- // Verify the nonce
398
- if ( empty( $_REQUEST['nonce'] ) || ! wp_verify_nonce( $_REQUEST['nonce'], 'woocommerce-settings' ) ) {
399
  die();
400
  }
401
 
402
- // Verify the id
403
- if( empty( $_POST['attachment_id'] ) && is_numeric( $_POST['attachment_id'] ) ) {
404
  die();
405
  }
406
 
407
- $wdn_image_attachmnet_id = sanitize_text_field( $_POST['attachment_id'] );
408
- // create the image
409
  $this->create_image( $wdn_image_attachmnet_id );
410
 
411
  exit;
412
  }
413
 
414
  /**
415
- * Create image
 
 
416
  */
417
  public function create_image( $attachment_id ) {
418
  $attachment_src = wp_get_attachment_image_src( $attachment_id, 'medium', false );
419
- $orientation = 'landscape';
420
- if( ( $attachment_src[1] / $attachment_src[2] ) < 1 ) {
421
  $orientation = 'portrait';
422
  }
423
 
424
  ?>
425
- <img src="<?php echo $attachment_src[0]; ?>" class="<?php echo $orientation; ?>" alt="" />
426
  <?php
427
  }
428
 
429
  /**
430
- * Output image select field
 
 
431
  */
432
  public function output_image_select( $value ) {
433
- // Define the defaults
434
  if ( ! isset( $value['title_select'] ) ) {
435
  $value['title_select'] = __( 'Select', 'woocommerce-delivery-notes' );
436
  }
@@ -439,65 +470,78 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
439
  $value['title_remove'] = __( 'Remove', 'woocommerce-delivery-notes' );
440
  }
441
 
442
- // Get additional data fields
443
- $field = WC_Admin_Settings::get_field_description( $value );
444
- $description = $field['description'];
445
  $tooltip_html = $field['tooltip_html'];
446
  $option_value = WC_Admin_Settings::get_option( $value['id'], $value['default'] );
447
- $class_name = 'wcdn-image-select';
448
 
449
- ?><tr valign="top">
 
450
 
451
 
452
  <th scope="row" class="titledesc">
453
- <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?> <?php echo $tooltip_html; ?></label>
454
  </th>
455
  <td class="forminp image_width_settings">
456
- <input name="<?php echo esc_attr( $value['id'] ); ?>" id="<?php echo esc_attr( $value['id'] ); ?>" type="hidden" value="<?php echo esc_attr( $option_value ); ?>" class="<?php echo $class_name; ?>-image-id <?php echo esc_attr( $value['class'] ); ?>" />
457
 
458
- <div id="<?php echo esc_attr( $value['id'] ); ?>_field" class="<?php echo $class_name; ?>-field <?php echo esc_attr( $value['class'] ); ?>" style="<?php echo esc_attr( $value['css'] ); ?>">
459
- <span id="<?php echo esc_attr( $value['id'] ); ?>_spinner" class="<?php echo $class_name; ?>-spinner spinner"></span>
460
- <div id="<?php echo esc_attr( $value['id'] ); ?>_attachment" class="<?php echo $class_name; ?>-attachment <?php echo esc_attr( $value['class'] ); ?> ">
461
  <div class="thumbnail">
462
  <div class="centered">
463
- <?php if( !empty( $option_value ) ) : ?>
464
  <?php $this->create_image( $option_value ); ?>
465
  <?php endif; ?>
466
  </div>
467
  </div>
468
  </div>
469
 
470
- <div id="<?php echo esc_attr( $value['id'] ); ?>_buttons" class="<?php echo $class_name; ?>-buttons <?php echo esc_attr( $value['class'] ); ?>">
471
- <a href="#" id="<?php echo esc_attr( $value['id'] ); ?>_remove_button" class="<?php echo $class_name; ?>-remove-button <?php if( empty( $option_value ) ) : ?>hidden<?php endif; ?> button">
 
 
 
 
472
  <?php echo esc_html( $value['title_remove'] ); ?>
473
  </a>
474
- <a href="#" id="<?php echo esc_attr( $value['id'] ); ?>_add_button" class="<?php echo $class_name; ?>-add-button <?php if( !empty( $option_value ) ) : ?>hidden<?php endif; ?> button" data-uploader-title="<?php echo esc_attr( $value['title'] ); ?>" data-uploader-button-title="<?php echo esc_attr( $value['title_select'] ); ?>">
 
 
 
 
475
  <?php echo esc_html( $value['title_select'] ); ?>
476
  </a>
477
  </div>
478
  </div>
479
 
480
- <?php echo $description; ?>
481
  </td>
482
  </tr><?php
483
  }
484
 
485
  /**
486
- * Merge array at given position
 
 
 
 
487
  */
488
  public function array_merge_at( $array, $insert, $position ) {
489
  $new_array = array();
490
- // if pos is start, just merge them
491
- if( $position == 0 ) {
492
  $new_array = array_merge( $insert, $array );
493
  } else {
494
- // if pos is end just merge them
495
- if( $position >= ( count( $array ) - 1 ) ) {
496
- $new_array = array_merge($array, $insert);
497
  } else {
498
- // split into head and tail, then merge head+inserted bit+tail
499
- $head = array_slice( $array, 0, $position );
500
- $tail = array_slice( $array, $position );
501
  $new_array = array_merge( $head, $insert, $tail );
502
  }
503
  }
@@ -506,4 +550,4 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
506
  }
507
 
508
  }
509
- ?>
1
  <?php
2
+ /**
3
+ * Settings class
4
+ *
5
+ * @package woocommerce-print-invoice-delivery-notes
6
+ */
7
 
8
  /**
9
  * Exit if accessed directly
10
  */
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
  exit;
13
  }
14
 
15
  /**
16
  * Settings class
17
  */
18
+ if ( ! class_exists( 'WCDN_Settings' ) ) {
19
 
20
  /**
21
  * WooCommerce Print Delivery Notes
22
+ *
23
  * @author Tyche Softwares
24
  * @package WooCommerce-Delivery-Notes/Settings
25
  */
26
+ class WCDN_Settings {
27
 
28
+ /**
29
+ * Id variable
30
+ *
31
+ * @var int $id ID variable
32
+ */
33
  public $id;
34
 
35
  /**
36
  * Constructor
37
  */
38
  public function __construct() {
39
+ // Define default variables.
40
  $this->id = 'wcdn-settings';
41
 
42
+ // Load the hooks.
43
  add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 200 );
44
  add_action( 'woocommerce_settings_start', array( $this, 'add_assets' ) );
45
  add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) );
48
  add_action( 'woocommerce_admin_field_wcdn_image_select', array( $this, 'output_image_select' ) );
49
  add_action( 'wp_ajax_wcdn_settings_load_image', array( $this, 'load_image_ajax' ) );
50
  add_filter( 'wcdn_get_settings', array( $this, 'generate_template_type_fields' ), 10, 2 );
51
+ add_action( 'woocommerce_admin_field_link', array( &$this, 'wcdn_add_admin_field_reset_button' ) );
52
  }
53
 
54
  /**
55
  * It will add a reset tracking data button on the settting page.
56
+ *
57
  * @hook woocommerce_admin_field_link
58
+ *
59
+ * @param string $value Check if tracking is reset.
60
  */
61
+ public static function wcdn_add_admin_field_reset_button( $value ) {
62
+ if ( 'ts_reset_tracking' === $value ['id'] ) {
63
+ do_action( 'wcdn_add_new_settings', $value );
64
  }
65
  }
66
 
68
  * Add the scripts
69
  */
70
  public function add_assets() {
71
+ // Styles.
72
+ wp_enqueue_style( 'woocommerce-delivery-notes-admin', WooCommerce_Delivery_Notes::$plugin_url . 'css/admin.css', '', WooCommerce_Delivery_Notes::$plugin_version );
73
 
74
+ // Scripts.
75
  wp_enqueue_media();
76
+ wp_enqueue_script( 'woocommerce-delivery-notes-print-link', WooCommerce_Delivery_Notes::$plugin_url . 'js/jquery.print-link.js', array( 'jquery' ), WooCommerce_Delivery_Notes::$plugin_version, false );
77
+ wp_enqueue_script( 'woocommerce-delivery-notes-admin', WooCommerce_Delivery_Notes::$plugin_url . 'js/admin.js', array( 'jquery', 'custom-header', 'woocommerce-delivery-notes-print-link' ), WooCommerce_Delivery_Notes::$plugin_version, false );
78
 
79
+ // Localize the script strings.
80
  $translation = array( 'resetCounter' => __( 'Do you really want to reset the counter to zero? This process can\'t be undone.', 'woocommerce-delivery-notes' ) );
81
  wp_localize_script( 'woocommerce-delivery-notes-admin', 'WCDNText', $translation );
82
  }
83
 
84
  /**
85
  * Create a new settings tab
86
+ *
87
+ * @param array $settings_tabs Add settings tab in WooCommerce->Settings page.
88
  */
89
  public function add_settings_page( $settings_tabs ) {
90
+ $settings_tabs[ $this->id ] = __( 'Print', 'woocommerce-delivery-notes' );
91
  return $settings_tabs;
92
  }
93
 
94
  /**
95
+ * Output the settings fields into the tab.
96
  */
97
  public function output() {
98
  global $current_section;
99
  $settings = $this->get_settings( $current_section );
100
+ woocommerce_admin_fields( $settings );
101
  }
102
 
103
  /**
104
  * Save the settings
105
  */
106
+ public function save() {
107
+ global $current_section;
108
  set_transient( 'wcdn_flush_rewrite_rules', true );
109
  $settings = $this->get_settings( $current_section );
110
+ woocommerce_update_options( $settings );
111
  }
112
 
113
  /**
114
  * Get the settings fields
115
+ *
116
+ * @param string $section Section name.
117
  */
118
  public function get_settings( $section = '' ) {
119
+ $wcdn_faq_url = admin_url( 'index.php?page=wcdn_faq_page' );
120
+ $settings = apply_filters(
121
+ 'wcdn_get_settings_no_section',
122
+ array(
123
+ array(
124
+ 'title' => __( 'Template', 'woocommerce-delivery-notes' ),
125
+ 'type' => 'title',
126
+ 'desc' => $this->get_template_description(),
127
+ 'id' => 'general_options',
128
+ ),
129
 
130
  array(
131
  'title' => __( 'Style', 'woocommerce-delivery-notes' ),
132
+ /* translators: %s: link to faq */
133
  'desc' => sprintf( __( 'The default print style. Read the <a href="%1$s">FAQ</a> to learn how to customize it.', 'woocommerce-delivery-notes' ), $wcdn_faq_url, '#' ),
134
  'id' => 'wcdn_template_style',
135
  'class' => 'wc-enhanced-select',
136
  'default' => '',
137
  'type' => 'select',
138
  'options' => $this->get_options_styles(),
139
+ 'desc_tip' => false,
140
  ),
141
 
142
  array(
143
+ 'title' => __( 'Shop Logo', 'woocommerce-delivery-notes' ),
144
+ 'desc' => '',
145
+ 'id' => 'wcdn_company_logo_image_id',
146
+ 'css' => '',
147
+ 'default' => '',
148
+ 'type' => 'wcdn_image_select',
149
+ 'desc_tip' => __( 'A shop logo representing your business. When the image is printed, its pixel density will automatically be eight times higher than the original. This means, 1 printed inch will correspond to about 288 pixels on the screen.', 'woocommerce-delivery-notes' ),
150
  ),
151
 
152
  array(
156
  'css' => 'min-width:100%;',
157
  'default' => '',
158
  'type' => 'text',
159
+ 'desc_tip' => __( 'The shop name. Leave blank to use the default Website or Blog title defined in WordPress settings. The name will be ignored when a Logo is set.', 'woocommerce-delivery-notes' ),
160
  ),
161
 
162
  array(
166
  'css' => 'min-width:100%;min-height:100px;',
167
  'default' => '',
168
  'type' => 'textarea',
169
+ 'desc_tip' => true,
170
  ),
171
 
172
  array(
176
  'css' => 'min-width:100%;min-height:100px;',
177
  'default' => '',
178
  'type' => 'textarea',
179
+ 'desc_tip' => true,
180
  ),
181
 
182
  array(
186
  'css' => 'min-width:100%;min-height:100px;',
187
  'default' => '',
188
  'type' => 'textarea',
189
+ 'desc_tip' => true,
190
  ),
191
 
192
  array(
196
  'css' => 'min-width:100%;min-height:100px;',
197
  'default' => '',
198
  'type' => 'textarea',
199
+ 'desc_tip' => true,
200
  ),
201
 
202
  array(
203
+ 'type' => 'sectionend',
204
+ 'id' => 'general_options',
205
  ),
206
 
207
  array(
208
+ 'title' => __( 'Pages & Buttons', 'woocommerce-delivery-notes' ),
209
+ 'type' => 'title',
210
+ 'desc' => '',
211
+ 'id' => 'display_options',
212
+ ),
213
 
214
+ array(
215
  'title' => __( 'Print Page Endpoint', 'woocommerce-delivery-notes' ),
216
  'desc' => '',
217
  'id' => 'wcdn_print_order_page_endpoint',
222
  ),
223
 
224
  array(
225
+ 'title' => __( 'Email', 'woocommerce-delivery-notes' ),
226
+ 'desc' => __( 'Show print link in customer emails', 'woocommerce-delivery-notes' ),
227
+ 'id' => 'wcdn_email_print_link',
228
+ 'default' => 'no',
229
+ 'type' => 'checkbox',
230
+ 'desc_tip' => __( 'This includes the emails for a new, processing and completed order. On top of that the customer invoice email also includes the link.', 'woocommerce-delivery-notes' ),
231
+ ),
232
+
233
+ array(
234
+ 'title' => __( 'My Account', 'woocommerce-delivery-notes' ),
235
+ 'desc' => __( 'Show print button on the "View Order" page', 'woocommerce-delivery-notes' ),
236
+ 'id' => 'wcdn_print_button_on_view_order_page',
237
+ 'default' => 'no',
238
+ 'type' => 'checkbox',
239
+ 'checkboxgroup' => 'start',
240
  ),
241
 
242
  array(
243
+ 'desc' => __( 'Show print buttons on the "My Account" page', 'woocommerce-delivery-notes' ),
244
+ 'id' => 'wcdn_print_button_on_my_account_page',
245
+ 'default' => 'no',
246
+ 'type' => 'checkbox',
247
+ 'checkboxgroup' => 'end',
 
248
  ),
249
 
250
  array(
251
+ 'type' => 'sectionend',
252
+ 'id' => 'display_options',
 
 
 
253
  ),
254
 
255
+ array(
256
+ 'title' => __( 'Invoice', 'woocommerce-delivery-notes' ),
257
+ 'type' => 'title',
258
+ 'desc' => '',
259
+ 'id' => 'invoice_options',
260
  ),
261
 
262
  array(
263
+ 'title' => __( 'Numbering', 'woocommerce-delivery-notes' ),
264
+ 'desc' => __( 'Create invoice numbers', 'woocommerce-delivery-notes' ),
265
+ 'id' => 'wcdn_create_invoice_number',
266
+ 'default' => 'no',
267
+ 'type' => 'checkbox',
268
+ 'desc_tip' => '',
 
 
 
 
 
 
 
269
  ),
270
 
271
  array(
276
  'css' => '',
277
  'default' => 1,
278
  'type' => 'number',
279
+ 'desc_tip' => __( 'The next invoice number.', 'woocommerce-delivery-notes' ),
280
  ),
281
 
282
  array(
287
  'css' => '',
288
  'default' => '',
289
  'type' => 'text',
290
+ 'desc_tip' => __( 'This text will be prepended to the invoice number.', 'woocommerce-delivery-notes' ),
291
  ),
292
 
293
  array(
298
  'css' => '',
299
  'default' => '',
300
  'type' => 'text',
301
+ 'desc_tip' => __( 'This text will be appended to the invoice number.', 'woocommerce-delivery-notes' ),
302
  ),
303
+ apply_filters( 'wcdn_add_settings_field', '' ),
304
+ array(
305
+ 'type' => 'sectionend',
306
+ 'id' => 'invoice_options',
307
  ),
308
+ )
309
+ );
310
 
311
+ return apply_filters( 'wcdn_get_settings', $settings, $section );
312
  }
313
 
314
  /**
315
+ * Get the position of a setting inside the array.
316
+ *
317
+ * @param int $id Setting ID.
318
+ * @param array $settings Setting details.
319
+ * @param string $type Type.
320
  */
321
  public function get_setting_position( $id, $settings, $type = null ) {
322
+ foreach ( $settings as $key => $value ) {
323
+ if ( isset( $value['id'] ) && $value['id'] === $id ) {
324
  return $key;
325
  }
326
  }
330
 
331
  /**
332
  * Generate the template type setting fields
333
+ *
334
+ * @param array $settings Settings fields.
335
+ * @param string $section Section name.
336
  */
337
  public function generate_template_type_fields( $settings, $section = '' ) {
338
  $position = $this->get_setting_position( 'wcdn_email_print_link', $settings );
339
+ if ( false !== $position ) {
340
  $new_settings = array();
341
 
342
+ // Go through all registrations but remove the default 'order' type.
343
+ $template_registrations = WCDN_Print::$template_registrations;
344
  array_splice( $template_registrations, 0, 1 );
345
  $end = count( $template_registrations ) - 1;
346
+ foreach ( $template_registrations as $index => $template_registration ) {
347
+ $title = '';
348
+ $desc_tip = '';
349
  $checkboxgroup = '';
350
 
351
+ // Define the group settings.
352
+ if ( 0 === $index ) {
353
+ $title = __( 'Admin', 'woocommerce-delivery-notes' );
354
  $checkboxgroup = 'start';
355
+ } elseif ( $index === $end ) {
356
+ $desc_tip = __( 'The print buttons are available on the order listing and on the order detail screen.', 'woocommerce-delivery-notes' );
357
  $checkboxgroup = 'end';
358
  }
359
 
360
+ // Create the setting.
361
  $new_settings[] = array(
362
+ 'title' => $title,
363
+ 'desc' => $template_registration['labels']['setting'],
364
+ 'id' => 'wcdn_template_type_' . $template_registration['type'],
365
+ 'default' => 'no',
366
+ 'type' => 'checkbox',
367
+ 'checkboxgroup' => $checkboxgroup,
368
+ 'desc_tip' => $desc_tip,
369
  );
370
  }
371
 
372
+ // Add the settings.
373
  $settings = $this->array_merge_at( $settings, $new_settings, $position );
374
  }
375
 
377
  }
378
 
379
  /**
380
+ * Generate the description for the template settings.
381
  */
382
  public function get_template_description() {
383
  $description = '';
384
+ $args = array(
385
+ 'post_type' => 'shop_order',
386
+ 'post_status' => array( 'wc-pending', 'wc-processing', 'wc-on-hold', 'wc-completed', 'wc-cancelled', 'wc-refunded', 'wc-failed' ),
387
+ 'posts_per_page' => 1,
388
  );
389
+ $query = new WP_Query( $args );
390
 
391
+ // show template preview links when an order is available.
392
+ if ( $query->have_posts() ) {
393
+ $results = $query->get_posts();
394
+ $test_id = $results[0]->ID;
395
+ $invoice_url = wcdn_get_print_link( $test_id, 'invoice' );
396
  $delivery_note_url = wcdn_get_print_link( $test_id, 'delivery-note' );
397
+ $receipt_url = wcdn_get_print_link( $test_id, 'receipt' );
398
+ /* translators: %s: invoice url, delivery note url, receipt url */
399
  $description = sprintf( __( 'This section lets you customise the content. You can preview the <a href="%1$s" target="%4$s" class="%5$s">invoice</a>, <a href="%2$s" target="%4$s" class="%5$s">delivery note</a> or <a href="%3$s" target="%4$s" class="%5$s">receipt</a> template.', 'woocommerce-delivery-notes' ), $invoice_url, $delivery_note_url, $receipt_url, '_blank', '' );
400
  }
401
 
403
  }
404
 
405
  /**
406
+ * Generate the options for the template styles field.
407
  */
408
  public function get_options_styles() {
409
  $options = array();
410
 
411
+ foreach ( WCDN_Print::$template_styles as $template_style ) {
412
+ if ( is_array( $template_style ) && isset( $template_style['type'] ) && isset( $template_style['name'] ) ) {
413
+ $options[ $template_style['type'] ] = $template_style['name'];
414
  }
415
  }
416
 
418
  }
419
 
420
  /**
421
+ * Load image with ajax.
422
  */
423
  public function load_image_ajax() {
424
+ // Verify the nonce.
425
+ if ( empty( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['nonce'] ) ), 'woocommerce-settings' ) ) {
426
  die();
427
  }
428
 
429
+ // Verify the id.
430
+ if ( empty( $_POST['attachment_id'] ) && is_numeric( $_POST['attachment_id'] ) ) {
431
  die();
432
  }
433
 
434
+ $wdn_image_attachmnet_id = sanitize_text_field( wp_unslash( $_POST['attachment_id'] ) );
435
+ // create the image.
436
  $this->create_image( $wdn_image_attachmnet_id );
437
 
438
  exit;
439
  }
440
 
441
  /**
442
+ * Create image.
443
+ *
444
+ * @param int $attachment_id Attachment ID.
445
  */
446
  public function create_image( $attachment_id ) {
447
  $attachment_src = wp_get_attachment_image_src( $attachment_id, 'medium', false );
448
+ $orientation = 'landscape';
449
+ if ( ( $attachment_src[1] / $attachment_src[2] ) < 1 ) {
450
  $orientation = 'portrait';
451
  }
452
 
453
  ?>
454
+ <img src="<?php echo esc_url( $attachment_src[0] ); ?>" class="<?php echo esc_attr( $orientation ); ?>" alt="" />
455
  <?php
456
  }
457
 
458
  /**
459
+ * Output image select field.
460
+ *
461
+ * @param array $value Title.
462
  */
463
  public function output_image_select( $value ) {
464
+ // Define the defaults.
465
  if ( ! isset( $value['title_select'] ) ) {
466
  $value['title_select'] = __( 'Select', 'woocommerce-delivery-notes' );
467
  }
470
  $value['title_remove'] = __( 'Remove', 'woocommerce-delivery-notes' );
471
  }
472
 
473
+ // Get additional data fields.
474
+ $field = WC_Admin_Settings::get_field_description( $value );
475
+ $description = $field['description'];
476
  $tooltip_html = $field['tooltip_html'];
477
  $option_value = WC_Admin_Settings::get_option( $value['id'], $value['default'] );
478
+ $class_name = 'wcdn-image-select';
479
 
480
+ ?>
481
+ <tr valign="top">
482
 
483
 
484
  <th scope="row" class="titledesc">
485
+ <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?> <?php echo wp_kses_post( $tooltip_html ); ?></label>
486
  </th>
487
  <td class="forminp image_width_settings">
488
+ <input name="<?php echo esc_attr( $value['id'] ); ?>" id="<?php echo esc_attr( $value['id'] ); ?>" type="hidden" value="<?php echo esc_attr( $option_value ); ?>" class="<?php echo esc_attr( $class_name ); ?>-image-id <?php echo esc_attr( $value['class'] ); ?>" />
489
 
490
+ <div id="<?php echo esc_attr( $value['id'] ); ?>_field" class="<?php echo esc_attr( $class_name ); ?>-field <?php echo esc_attr( $value['class'] ); ?>" style="<?php echo esc_attr( $value['css'] ); ?>">
491
+ <span id="<?php echo esc_attr( $value['id'] ); ?>_spinner" class="<?php echo esc_attr( $class_name ); ?>-spinner spinner"></span>
492
+ <div id="<?php echo esc_attr( $value['id'] ); ?>_attachment" class="<?php echo esc_attr( $class_name ); ?>-attachment <?php echo esc_attr( $value['class'] ); ?> ">
493
  <div class="thumbnail">
494
  <div class="centered">
495
+ <?php if ( ! empty( $option_value ) ) : ?>
496
  <?php $this->create_image( $option_value ); ?>
497
  <?php endif; ?>
498
  </div>
499
  </div>
500
  </div>
501
 
502
+ <div id="<?php echo esc_attr( $value['id'] ); ?>_buttons" class="<?php echo esc_attr( $class_name ); ?>-buttons <?php echo esc_attr( $value['class'] ); ?>">
503
+ <a href="#" id="<?php echo esc_attr( $value['id'] ); ?>_remove_button" class="<?php echo esc_attr( $class_name ); ?>-remove-button
504
+ <?php
505
+ if ( empty( $option_value ) ) :
506
+ ?>
507
+ hidden<?php endif; ?> button">
508
  <?php echo esc_html( $value['title_remove'] ); ?>
509
  </a>
510
+ <a href="#" id="<?php echo esc_attr( $value['id'] ); ?>_add_button" class="<?php echo esc_attr( $class_name ); ?>-add-button
511
+ <?php
512
+ if ( ! empty( $option_value ) ) :
513
+ ?>
514
+ hidden<?php endif; ?> button" data-uploader-title="<?php echo esc_attr( $value['title'] ); ?>" data-uploader-button-title="<?php echo esc_attr( $value['title_select'] ); ?>">
515
  <?php echo esc_html( $value['title_select'] ); ?>
516
  </a>
517
  </div>
518
  </div>
519
 
520
+ <?php echo wp_kses_post( $description ); ?>
521
  </td>
522
  </tr><?php
523
  }
524
 
525
  /**
526
+ * Merge array at given position.
527
+ *
528
+ * @param array $array Parent array.
529
+ * @param array $insert New array.
530
+ * @param int $position Position to merge at.
531
  */
532
  public function array_merge_at( $array, $insert, $position ) {
533
  $new_array = array();
534
+ // if pos is start, just merge them.
535
+ if ( 0 === $position ) {
536
  $new_array = array_merge( $insert, $array );
537
  } else {
538
+ // if pos is end just merge them.
539
+ if ( $position >= ( count( $array ) - 1 ) ) {
540
+ $new_array = array_merge( $array, $insert );
541
  } else {
542
+ // split into head and tail, then merge head+inserted bit+tail.
543
+ $head = array_slice( $array, 0, $position );
544
+ $tail = array_slice( $array, $position );
545
  $new_array = array_merge( $head, $insert, $tail );
546
  }
547
  }
550
  }
551
 
552
  }
553
+ ?>
includes/class-wcdn-theme.php CHANGED
@@ -1,24 +1,32 @@
1
  <?php
 
 
 
 
 
2
 
3
  /**
4
  * Exit if accessed directly
5
  */
6
- if ( !defined( 'ABSPATH' ) ) {
7
  exit;
8
  }
9
 
10
  /**
11
- * Frontend Theme class
12
  */
13
- if ( !class_exists( 'WooCommerce_Delivery_Notes_Theme' ) ) {
14
 
15
- class WooCommerce_Delivery_Notes_Theme {
 
 
 
16
 
17
  /**
18
  * Constructor
19
  */
20
  public function __construct() {
21
- // Load the hooks
22
  add_action( 'wp_loaded', array( $this, 'load_hooks' ) );
23
  }
24
 
@@ -27,7 +35,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Theme' ) ) {
27
  * the theme and plugins are ready.
28
  */
29
  public function load_hooks() {
30
- // hooks
31
  add_filter( 'woocommerce_my_account_my_orders_actions', array( $this, 'create_print_button_account_page' ), 10, 2 );
32
  add_action( 'woocommerce_view_order', array( $this, 'create_print_button_order_page' ) );
33
  add_action( 'woocommerce_thankyou', array( $this, 'create_print_button_order_page' ) );
@@ -40,50 +48,53 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Theme' ) ) {
40
  */
41
  public function add_scripts() {
42
  if ( is_account_page() || is_order_received_page() || $this->is_woocommerce_tracking_page() ) {
43
- wp_enqueue_script( 'woocommerce-delivery-notes-print-link', WooCommerce_Delivery_Notes::$plugin_url . 'js/jquery.print-link.js', array( 'jquery' ) );
44
- wp_enqueue_script( 'woocommerce-delivery-notes-theme', WooCommerce_Delivery_Notes::$plugin_url . 'js/theme.js', array( 'jquery', 'woocommerce-delivery-notes-print-link' ) );
45
  }
46
  }
47
 
48
  /**
49
- * Create a print button for the 'My Account' page
 
 
 
50
  */
51
  public function create_print_button_account_page( $actions, $order ) {
52
- if( get_option( 'wcdn_print_button_on_my_account_page' ) == 'yes' ) {
53
- // Add the print button
54
- $wdn_order_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_id() : $order->id;
55
  $actions['print'] = array(
56
  'url' => wcdn_get_print_link( $wdn_order_id, $this->get_template_type( $order ) ),
57
- 'name' => __( 'Print', 'woocommerce-delivery-notes' )
58
  );
59
  }
60
  return $actions;
61
  }
62
 
63
  /**
64
- * Create a print button for the 'View Order' page
 
 
65
  */
66
  public function create_print_button_order_page( $order_id ) {
67
- $order = new WC_Order( $order_id );
68
- $wdn_order_billing_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_billing_email() : $order->billing_email;
69
- // Output the button only when the option is enabled
70
- if( get_option( 'wcdn_print_button_on_view_order_page' ) == 'yes' ) {
71
- // Default button for all pages and logged in users
72
  $print_url = wcdn_get_print_link( $order_id, $this->get_template_type( $order ) );
73
 
74
- // Pass the email to the url for the tracking
75
- // and thank you page. This allows to view the
76
- // print page without logging in.
77
- if( $this->is_woocommerce_tracking_page() ) {
78
- //changed
79
- $wdn_order_email = sanitize_email( $_REQUEST['order_email'] ) ;
80
- $print_url = wcdn_get_print_link( $order_id, $this->get_template_type( $order ), $wdn_order_email );
81
  }
82
 
83
- // Thank you page
84
- if( is_order_received_page() && !is_user_logged_in() ) {
85
- // Don't output the butten when there is no email
86
- if( !$wdn_order_billing_id ) {
87
  return;
88
  }
89
  $print_url = wcdn_get_print_link( $order_id, $this->get_template_type( $order ), $wdn_order_billing_id );
@@ -91,7 +102,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Theme' ) ) {
91
 
92
  ?>
93
  <p class="order-print">
94
- <a href="<?php echo $print_url; ?>" class="button print"><?php _e( 'Print', 'woocommerce-delivery-notes' ); ?></a>
95
  </p>
96
  <?php
97
  }
@@ -99,24 +110,28 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Theme' ) ) {
99
 
100
  /**
101
  * Add a print url to the emails that are sent to the customer
 
 
 
 
102
  */
103
  public function add_email_print_url( $order, $sent_to_admin = true, $plain_text = false ) {
104
- if( get_option( 'wcdn_email_print_link' ) == 'yes' ) {
105
- $wdn_order_billing_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_billing_email() : $order->billing_email;
106
- if( $wdn_order_billing_id && !$sent_to_admin ) {
107
- $wdn_order_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_id() : $order->id;
108
 
109
  $url = wcdn_get_print_link( $wdn_order_id, $this->get_template_type( $order ), $wdn_order_billing_id, true );
110
 
111
- if( $plain_text ) :
112
- echo __( 'Print your order', 'woocommerce-delivery-notes' ) . "\n\n";
113
 
114
- echo $url . "\n";
115
 
116
- echo "\n****************************************************\n\n";
117
- else : ?>
118
- <?php // changed ?>
119
- <p><strong><?php _e( 'Print:', 'woocommerce-delivery-notes' ); ?></strong> <a href="<?php echo esc_url_raw( $url ); ?>"><?php _e( 'Open print view in browser', 'woocommerce-delivery-notes' ); ?></a></p>
120
  <?php endif;
121
  }
122
  }
@@ -124,16 +139,21 @@ echo "\n****************************************************\n\n";
124
 
125
  /**
126
  * Get the print button template type depnding on order status
 
 
127
  */
128
  public function get_template_type( $order ) {
129
 
130
- $wdn_order_status = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_status() : $order->status;
131
 
132
- if( $wdn_order_status == 'completed' ) {
133
  $type = apply_filters( 'wcdn_theme_print_button_template_type_complete_status', 'invoice' );
134
  } else {
135
  $type = apply_filters( 'wcdn_theme_print_button_template_type', 'order' );
136
  }
 
 
 
137
  return $type;
138
  }
139
 
@@ -141,11 +161,11 @@ echo "\n****************************************************\n\n";
141
  * Is WooCommerce 'Order Tracking' page
142
  */
143
  public function is_woocommerce_tracking_page() {
144
- return ( is_page( wc_get_page_id( 'order_tracking' ) ) && isset( $_REQUEST['order_email'] ) ) ? true : false;
145
  }
146
 
147
  }
148
 
149
  }
150
 
151
- ?>
1
  <?php
2
+ /**
3
+ * Theme class
4
+ *
5
+ * @package woocommerce-print-invoice-delivery-notes
6
+ */
7
 
8
  /**
9
  * Exit if accessed directly
10
  */
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
  exit;
13
  }
14
 
15
  /**
16
+ * Frontend Theme class.
17
  */
18
+ if ( ! class_exists( 'WCDN_Theme' ) ) {
19
 
20
+ /**
21
+ * Theme class
22
+ */
23
+ class WCDN_Theme {
24
 
25
  /**
26
  * Constructor
27
  */
28
  public function __construct() {
29
+ // Load the hooks.
30
  add_action( 'wp_loaded', array( $this, 'load_hooks' ) );
31
  }
32
 
35
  * the theme and plugins are ready.
36
  */
37
  public function load_hooks() {
38
+ // hooks.
39
  add_filter( 'woocommerce_my_account_my_orders_actions', array( $this, 'create_print_button_account_page' ), 10, 2 );
40
  add_action( 'woocommerce_view_order', array( $this, 'create_print_button_order_page' ) );
41
  add_action( 'woocommerce_thankyou', array( $this, 'create_print_button_order_page' ) );
48
  */
49
  public function add_scripts() {
50
  if ( is_account_page() || is_order_received_page() || $this->is_woocommerce_tracking_page() ) {
51
+ wp_enqueue_script( 'woocommerce-delivery-notes-print-link', WooCommerce_Delivery_Notes::$plugin_url . 'js/jquery.print-link.js', array( 'jquery' ), WooCommerce_Delivery_Notes::$plugin_version, false );
52
+ wp_enqueue_script( 'woocommerce-delivery-notes-theme', WooCommerce_Delivery_Notes::$plugin_url . 'js/theme.js', array( 'jquery', 'woocommerce-delivery-notes-print-link' ), WooCommerce_Delivery_Notes::$plugin_version, false );
53
  }
54
  }
55
 
56
  /**
57
+ * Create a print button for the 'My Account' page.
58
+ *
59
+ * @param array $actions My Account page actions.
60
+ * @param object $order Order object.
61
  */
62
  public function create_print_button_account_page( $actions, $order ) {
63
+ if ( 'yes' === get_option( 'wcdn_print_button_on_my_account_page' ) ) {
64
+ // Add the print button.
65
+ $wdn_order_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) ? $order->get_id() : $order->id;
66
  $actions['print'] = array(
67
  'url' => wcdn_get_print_link( $wdn_order_id, $this->get_template_type( $order ) ),
68
+ 'name' => apply_filters( 'wcdn_print_button_name_on_my_account_page', __( 'Print', 'woocommerce-delivery-notes' ), $order ),
69
  );
70
  }
71
  return $actions;
72
  }
73
 
74
  /**
75
+ * Create a print button for the 'View Order' page.
76
+ *
77
+ * @param int $order_id Order ID.
78
  */
79
  public function create_print_button_order_page( $order_id ) {
80
+ $order = new WC_Order( $order_id );
81
+ $wdn_order_billing_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) ? $order->get_billing_email() : $order->billing_email;
82
+ // Output the button only when the option is enabled.
83
+ if ( 'yes' === get_option( 'wcdn_print_button_on_view_order_page' ) ) {
84
+ // Default button for all pages and logged in users.
85
  $print_url = wcdn_get_print_link( $order_id, $this->get_template_type( $order ) );
86
 
87
+ // Pass the email to the url for the tracking and thank you page. This allows to view the print page without logging in.
88
+ if ( $this->is_woocommerce_tracking_page() ) {
89
+ // changed.
90
+ $wdn_order_email = isset( $_REQUEST['order_email'] ) ? sanitize_email( wp_unslash( $_REQUEST['order_email'] ) ) : '';
91
+ $print_url = wcdn_get_print_link( $order_id, $this->get_template_type( $order ), $wdn_order_email );
 
 
92
  }
93
 
94
+ // Thank you page.
95
+ if ( is_order_received_page() && ! is_user_logged_in() ) {
96
+ // Don't output the butten when there is no email.
97
+ if ( ! $wdn_order_billing_id ) {
98
  return;
99
  }
100
  $print_url = wcdn_get_print_link( $order_id, $this->get_template_type( $order ), $wdn_order_billing_id );
102
 
103
  ?>
104
  <p class="order-print">
105
+ <a href="<?php echo esc_url( $print_url ); ?>" class="button print"><?php echo esc_attr( apply_filters( 'wcdn_print_button_name_order_page', __( 'Print', 'woocommerce-delivery-notes' ), $order ) ); ?></a>
106
  </p>
107
  <?php
108
  }
110
 
111
  /**
112
  * Add a print url to the emails that are sent to the customer
113
+ *
114
+ * @param object $order Order Object.
115
+ * @param boolean $sent_to_admin Sent to admin true or false.
116
+ * @param boolean $plain_text Whether only to send plain text email or not.
117
  */
118
  public function add_email_print_url( $order, $sent_to_admin = true, $plain_text = false ) {
119
+ if ( 'yes' === get_option( 'wcdn_email_print_link' ) ) {
120
+ $wdn_order_billing_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) ? $order->get_billing_email() : $order->billing_email;
121
+ if ( $wdn_order_billing_id && ! $sent_to_admin ) {
122
+ $wdn_order_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) ? $order->get_id() : $order->id;
123
 
124
  $url = wcdn_get_print_link( $wdn_order_id, $this->get_template_type( $order ), $wdn_order_billing_id, true );
125
 
126
+ if ( $plain_text ) :
127
+ echo esc_html_e( 'Print your order', 'woocommerce-delivery-notes' ) . "\n\n";
128
 
129
+ echo esc_url( $url ) . "\n";
130
 
131
+ echo "\n****************************************************\n\n";
132
+ else :
133
+ ?>
134
+ <p><strong><?php esc_attr_e( 'Print:', 'woocommerce-delivery-notes' ); ?></strong> <a href="<?php echo esc_url_raw( $url ); ?>"><?php esc_attr_e( 'Open print view in browser', 'woocommerce-delivery-notes' ); ?></a></p>
135
  <?php endif;
136
  }
137
  }
139
 
140
  /**
141
  * Get the print button template type depnding on order status
142
+ *
143
+ * @param object $order Order object.
144
  */
145
  public function get_template_type( $order ) {
146
 
147
+ $wdn_order_status = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) ? $order->get_status() : $order->status;
148
 
149
+ if ( 'completed' === $wdn_order_status ) {
150
  $type = apply_filters( 'wcdn_theme_print_button_template_type_complete_status', 'invoice' );
151
  } else {
152
  $type = apply_filters( 'wcdn_theme_print_button_template_type', 'order' );
153
  }
154
+
155
+ $type = apply_filters( 'wcdn_theme_print_button_template_type_arbitrary', $type, $order );
156
+
157
  return $type;
158
  }
159
 
161
  * Is WooCommerce 'Order Tracking' page
162
  */
163
  public function is_woocommerce_tracking_page() {
164
+ return ( is_page( wc_get_page_id( 'order_tracking' ) ) && isset( $_REQUEST['order_email'] ) ) ? true : false;
165
  }
166
 
167
  }
168
 
169
  }
170
 
171
+ ?>
includes/class-wcdn-writepanel.php CHANGED
@@ -1,24 +1,32 @@
1
  <?php
 
 
 
 
 
2
 
3
  /**
4
  * Exit if accessed directly
5
  */
6
- if ( !defined( 'ABSPATH' ) ) {
7
  exit;
8
  }
9
 
10
  /**
11
  * Writepanel class
12
  */
13
- if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
14
 
15
- class WooCommerce_Delivery_Notes_Writepanel {
 
 
 
16
 
17
  /**
18
  * Constructor
19
  */
20
  public function __construct() {
21
- // Load the hooks
22
  add_action( 'admin_init', array( $this, 'load_admin_hooks' ) );
23
  }
24
 
@@ -26,7 +34,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
26
  * Load the admin hooks
27
  */
28
  public function load_admin_hooks() {
29
- // Hooks
30
  add_action( 'woocommerce_admin_order_actions_end', array( $this, 'add_listing_actions' ) );
31
  add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts' ) );
32
  add_action( 'admin_enqueue_scripts', array( $this, 'add_styles' ) );
@@ -34,7 +42,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
34
  add_action( 'add_meta_boxes_shop_order', array( $this, 'add_box' ) );
35
 
36
  add_action( 'admin_footer-edit.php', array( $this, 'add_bulk_actions' ) );
37
- add_action( 'load-edit.php', array( $this, 'load_bulk_actions' ) );
38
  add_action( 'admin_notices', array( $this, 'confirm_bulk_actions' ) );
39
  }
40
 
@@ -42,9 +50,9 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
42
  * Add the styles
43
  */
44
  public function add_styles() {
45
- if( $this->is_order_edit_page() || $this->is_order_post_page() ) {
46
- wp_enqueue_style('thickbox');
47
- wp_enqueue_style( 'woocommerce-delivery-notes-admin', WooCommerce_Delivery_Notes::$plugin_url . 'css/admin.css' );
48
  }
49
  }
50
 
@@ -52,10 +60,10 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
52
  * Add the scripts
53
  */
54
  public function add_scripts() {
55
- if( $this->is_order_edit_page() || $this->is_order_post_page() ) {
56
  wp_enqueue_script( 'thickbox' );
57
- wp_enqueue_script( 'woocommerce-delivery-notes-print-link', WooCommerce_Delivery_Notes::$plugin_url . 'js/jquery.print-link.js', array( 'jquery' ) );
58
- wp_enqueue_script( 'woocommerce-delivery-notes-admin', WooCommerce_Delivery_Notes::$plugin_url . 'js/admin.js', array( 'jquery', 'woocommerce-delivery-notes-print-link' ) );
59
  }
60
  }
61
 
@@ -64,7 +72,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
64
  */
65
  public function is_order_edit_page() {
66
  global $typenow, $pagenow;
67
- if( $typenow == 'shop_order' && $pagenow == 'edit.php' ) {
68
  return true;
69
  } else {
70
  return false;
@@ -76,7 +84,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
76
  */
77
  public function is_order_post_page() {
78
  global $typenow, $pagenow;
79
- if( $typenow == 'shop_order' && ( $pagenow == 'post.php' || $pagenow == 'post-new.php' ) ) {
80
  return true;
81
  } else {
82
  return false;
@@ -85,18 +93,20 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
85
 
86
  /**
87
  * Add print actions to the orders listing
 
 
88
  */
89
  public function add_listing_actions( $order ) {
90
 
91
- $wdn_order_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_id() : $order->id;
92
  ?>
93
- <?php foreach( WooCommerce_Delivery_Notes_Print::$template_registrations as $template_registration ) : ?>
94
- <?php if( get_option( 'wcdn_template_type_' . $template_registration['type'] ) == 'yes' && $template_registration['type'] !== 'order' ) : ?>
95
-
96
- <a href="<?php echo wcdn_get_print_link( $wdn_order_id, $template_registration['type'] ); ?>" class="button tips print-preview-button <?php echo $template_registration['type']; ?>" target="_blank" alt="<?php esc_attr_e( __( $template_registration['labels']['print'], 'woocommerce-delivery-notes' ) ); ?>" data-tip="<?php esc_attr_e( __( $template_registration['labels']['print'], 'woocommerce-delivery-notes' ) ); ?>">
97
- <?php _e( $template_registration['labels']['print'], 'woocommerce-delivery-notes' ); ?>
98
  </a>
99
-
100
  <?php endif; ?>
101
  <?php endforeach; ?>
102
 
@@ -113,109 +123,122 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
113
  * https://core.trac.wordpress.org/ticket/16031
114
  */
115
  public function add_bulk_actions() {
116
- if( $this->is_order_edit_page() ) : ?>
 
117
  <script type="text/javascript">
118
  jQuery(document).ready(function($) {
119
- <?php foreach( WooCommerce_Delivery_Notes_Print::$template_registrations as $template_registration ) : ?>
120
- <?php if( get_option( 'wcdn_template_type_' . $template_registration['type'] ) == 'yes' && $template_registration['type'] !== 'order' ) : ?>
121
-
122
- $('<option>').val('wcdn_print_<?php echo $template_registration['type']; ?>').attr('title', '<?php echo $template_registration['type']; ?>').text('<?php echo esc_js( __( $template_registration['labels']['print'], 'woocommerce-delivery-notes' ) ); ?>').appendTo('select[name="action"]');
123
- $('<option>').val('wcdn_print_<?php echo $template_registration['type']; ?>').attr('title', '<?php echo $template_registration['type']; ?>').text('<?php echo esc_js( __( $template_registration['labels']['print'], 'woocommerce-delivery-notes' ) ); ?>').appendTo('select[name="action2"]');
124
-
125
  <?php endif; ?>
126
  <?php endforeach; ?>
127
  });
128
  </script>
129
- <?php endif;
 
130
  }
131
 
132
  /**
133
  * Add bulk print actions to the orders listing
134
  */
135
  public function load_bulk_actions() {
136
- if( $this->is_order_edit_page() ) {
137
- // get the action staht should be started
138
- $wp_list_table = _get_list_table('WP_Posts_List_Table');
139
- $action = $wp_list_table->current_action();
140
 
141
- // stop if there are no post ids
142
- if( !isset( $_REQUEST['post'] ) ) {
143
  return;
144
  }
145
 
146
- // only for specified actions
147
- foreach( WooCommerce_Delivery_Notes_Print::$template_registrations as $template_registration ) {
148
- if( $action == 'wcdn_print_' . $template_registration['type'] ) {
149
  $template_type = $template_registration['type'];
150
  $report_action = 'printed_' . $template_registration['type'];
151
  break;
152
  }
153
  }
154
- if( !isset( $report_action ) ) {
155
  return;
156
  }
157
 
158
- // security check
159
- check_admin_referer('bulk-posts');
160
 
161
- // get referrer
162
- if( !wp_get_referer() ) {
163
  return;
164
  }
165
 
166
- // filter the referer args
167
  $referer_args = array();
168
- parse_str( parse_url( wp_get_referer(), PHP_URL_QUERY ), $referer_args );
169
 
170
- // set the basic args for the sendback
171
  $args = array(
172
- 'post_type' => $referer_args['post_type']
173
  );
174
- if( isset( $referer_args['post_status'] ) ) {
175
  $args = wp_parse_args( array( 'post_status' => $referer_args['post_status'] ), $args );
176
  }
177
- if( isset( $referer_args['paged'] ) ) {
178
  $args = wp_parse_args( array( 'paged' => $referer_args['paged'] ), $args );
179
  }
180
- if( isset( $referer_args['orderby'] ) ) {
181
  $args = wp_parse_args( array( 'orderby' => $referer_args['orderby'] ), $args );
182
  }
183
- if( isset( $referer_args['order'] ) ) {
184
  $args = wp_parse_args( array( 'orderby' => $referer_args['order'] ), $args );
185
  }
186
 
187
- // do the action
188
  $post_ids = array_map( 'absint', (array) $_REQUEST['post'] );
189
- $total = count( $post_ids );
190
- $url = wcdn_get_print_link( $post_ids , $template_type );
191
-
192
- // generate more args and the sendback string
193
- $args = wp_parse_args( array( $report_action => true, 'total' => $total, 'print_url' => urlencode( $url ) ), $args );
 
 
 
 
 
 
 
194
  $sendback = add_query_arg( $args, '' );
195
- wp_redirect( $sendback );
196
  exit;
197
  }
198
- }
199
 
200
  /**
201
  * Show confirmation message that orders are printed
202
  */
203
  public function confirm_bulk_actions() {
204
- if( $this->is_order_edit_page() ) {
205
- foreach( WooCommerce_Delivery_Notes_Print::$template_registrations as $template_registration ) {
206
- if( isset( $_REQUEST['printed_' . $template_registration['type']] ) ) {
207
- // use singular or plural form
208
  $total = isset( $_REQUEST['total'] ) ? absint( $_REQUEST['total'] ) : 0;
209
- if( $total <= 1 ) {
210
  $message = $template_registration['labels']['message'];
211
  } else {
212
  $message = $template_registration['labels']['message_plural'];
213
  }
214
- // changed
215
  ?>
216
 
217
  <div id="woocommerce-delivery-notes-bulk-print-message" class="updated">
218
- <p><?php _e( $message, 'woocommerce-delivery-notes' ); ?> <a href="<?php echo urldecode( esc_url_raw ( $_REQUEST['print_url'] ) ); ?>" target="_blank" class="print-preview-button" id="woocommerce-delivery-notes-bulk-print-button"><?php _e( 'Print now', 'woocommerce-delivery-notes' ) ?></a> <span class="print-preview-loading spinner"></span></p>
 
 
 
 
 
219
  </div>
220
 
221
  <?php
@@ -239,25 +262,26 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
239
  global $post_id, $wcdn;
240
  ?>
241
  <div class="print-actions">
242
- <?php foreach( WooCommerce_Delivery_Notes_Print::$template_registrations as $template_registration ) : ?>
243
- <?php if( get_option( 'wcdn_template_type_' . $template_registration['type'] ) == 'yes' && $template_registration['type'] !== 'order' ) : ?>
244
-
245
- <a href="<?php echo wcdn_get_print_link( $post_id, $template_registration['type'] ); ?>" class="button print-preview-button <?php echo $template_registration['type']; ?>" target="_blank" alt="<?php esc_attr_e( __( $template_registration['labels']['print'], 'woocommerce-delivery-notes' ) ); ?>"><?php _e( $template_registration['labels']['print'], 'woocommerce-delivery-notes' ); ?></a>
246
-
247
  <?php endif; ?>
248
  <?php endforeach; ?>
249
  <span class="print-preview-loading spinner"></span>
250
  </div>
251
  <?php
252
  $create_invoice_number = get_option( 'wcdn_create_invoice_number' );
253
- $has_invoice_number = get_post_meta( $post_id, '_wcdn_invoice_number', true );
254
- if( !empty( $create_invoice_number ) && $create_invoice_number == 'yes' && $has_invoice_number ) :
255
  $invoice_number = wcdn_get_order_invoice_number( $post_id );
256
- $invoice_date = wcdn_get_order_invoice_date( $post_id ); ?>
 
257
 
258
  <ul class="print-info">
259
- <li><strong><?php _e( 'Invoice number: ', 'woocommerce-delivery-notes' ); ?></strong> <?php echo $invoice_number; ?></li>
260
- <li><strong><?php _e( 'Invoice date: ', 'woocommerce-delivery-notes' ); ?></strong> <?php echo $invoice_date; ?></li>
261
  </ul>
262
 
263
  <?php endif; ?>
@@ -268,4 +292,4 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
268
 
269
  }
270
 
271
- ?>
1
  <?php
2
+ /**
3
+ * Write Panel class
4
+ *
5
+ * @package woocommerce-print-invoice-delivery-notes
6
+ */
7
 
8
  /**
9
  * Exit if accessed directly
10
  */
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
  exit;
13
  }
14
 
15
  /**
16
  * Writepanel class
17
  */
18
+ if ( ! class_exists( 'WCDN_Writepanel' ) ) {
19
 
20
+ /**
21
+ * Write Panel class
22
+ */
23
+ class WCDN_Writepanel {
24
 
25
  /**
26
  * Constructor
27
  */
28
  public function __construct() {
29
+ // Load the hooks.
30
  add_action( 'admin_init', array( $this, 'load_admin_hooks' ) );
31
  }
32
 
34
  * Load the admin hooks
35
  */
36
  public function load_admin_hooks() {
37
+ // Hooks.
38
  add_action( 'woocommerce_admin_order_actions_end', array( $this, 'add_listing_actions' ) );
39
  add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts' ) );
40
  add_action( 'admin_enqueue_scripts', array( $this, 'add_styles' ) );
42
  add_action( 'add_meta_boxes_shop_order', array( $this, 'add_box' ) );
43
 
44
  add_action( 'admin_footer-edit.php', array( $this, 'add_bulk_actions' ) );
45
+ add_action( 'load-edit.php', array( $this, 'load_bulk_actions' ) );
46
  add_action( 'admin_notices', array( $this, 'confirm_bulk_actions' ) );
47
  }
48
 
50
  * Add the styles
51
  */
52
  public function add_styles() {
53
+ if ( $this->is_order_edit_page() || $this->is_order_post_page() ) {
54
+ wp_enqueue_style( 'thickbox' );
55
+ wp_enqueue_style( 'woocommerce-delivery-notes-admin', WooCommerce_Delivery_Notes::$plugin_url . 'css/admin.css', '', WooCommerce_Delivery_Notes::$plugin_version );
56
  }
57
  }
58
 
60
  * Add the scripts
61
  */
62
  public function add_scripts() {
63
+ if ( $this->is_order_edit_page() || $this->is_order_post_page() ) {
64
  wp_enqueue_script( 'thickbox' );
65
+ wp_enqueue_script( 'woocommerce-delivery-notes-print-link', WooCommerce_Delivery_Notes::$plugin_url . 'js/jquery.print-link.js', array( 'jquery' ), WooCommerce_Delivery_Notes::$plugin_version, false );
66
+ wp_enqueue_script( 'woocommerce-delivery-notes-admin', WooCommerce_Delivery_Notes::$plugin_url . 'js/admin.js', array( 'jquery', 'woocommerce-delivery-notes-print-link' ), WooCommerce_Delivery_Notes::$plugin_version, false );
67
  }
68
  }
69
 
72
  */
73
  public function is_order_edit_page() {
74
  global $typenow, $pagenow;
75
+ if ( 'shop_order' === $typenow && 'edit.php' === $pagenow ) {
76
  return true;
77
  } else {
78
  return false;
84
  */
85
  public function is_order_post_page() {
86
  global $typenow, $pagenow;
87
+ if ( 'shop_order' === $typenow && ( 'post.php' === $pagenow || 'post-new.php' === $pagenow ) ) {
88
  return true;
89
  } else {
90
  return false;
93
 
94
  /**
95
  * Add print actions to the orders listing
96
+ *
97
+ * @param object $order Order Object.
98
  */
99
  public function add_listing_actions( $order ) {
100
 
101
+ $wdn_order_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) ? $order->get_id() : $order->id;
102
  ?>
103
+ <?php foreach ( WCDN_Print::$template_registrations as $template_registration ) : ?>
104
+ <?php if ( 'yes' === get_option( 'wcdn_template_type_' . $template_registration['type'] ) && 'order' !== $template_registration['type'] ) : ?>
105
+ <?php // phpcs:disable ?>
106
+ <a href="<?php echo esc_url( wcdn_get_print_link( $wdn_order_id, $template_registration['type'] ) ); ?>" class="button tips print-preview-button <?php echo esc_attr( $template_registration['type'] ); ?>" target="_blank" alt="<?php esc_attr_e( __( $template_registration['labels']['print'], 'woocommerce-delivery-notes' ) ); ?>" data-tip="<?php esc_attr_e( __( $template_registration['labels']['print'], 'woocommerce-delivery-notes' ) ); ?>">
107
+ <?php esc_html_e( $template_registration['labels']['print'], 'woocommerce-delivery-notes' ); ?>
108
  </a>
109
+ <?php // phpcs:enable ?>
110
  <?php endif; ?>
111
  <?php endforeach; ?>
112
 
123
  * https://core.trac.wordpress.org/ticket/16031
124
  */
125
  public function add_bulk_actions() {
126
+ if ( $this->is_order_edit_page() ) :
127
+ ?>
128
  <script type="text/javascript">
129
  jQuery(document).ready(function($) {
130
+ <?php foreach ( WCDN_Print::$template_registrations as $template_registration ) : ?>
131
+ <?php if ( 'yes' === get_option( 'wcdn_template_type_' . $template_registration['type'] ) && 'order' !== $template_registration['type'] ) : ?>
132
+ <?php //phpcs:disable ?>
133
+ $('<option>').val('wcdn_print_<?php echo esc_attr( $template_registration['type'] ); ?>').attr('title', '<?php echo esc_attr( $template_registration['type'] ); ?>').text('<?php echo esc_js( __( $template_registration['labels']['print'], 'woocommerce-delivery-notes' ) ); ?>').appendTo('select[name="action"]');
134
+ $('<option>').val('wcdn_print_<?php echo esc_attr( $template_registration['type'] ); ?>').attr('title', '<?php echo esc_attr( $template_registration['type'] ); ?>').text('<?php echo esc_js( __( $template_registration['labels']['print'], 'woocommerce-delivery-notes' ) ); ?>').appendTo('select[name="action2"]');
135
+ <?php //phpcs:enable ?>
136
  <?php endif; ?>
137
  <?php endforeach; ?>
138
  });
139
  </script>
140
+ <?php
141
+ endif;
142
  }
143
 
144
  /**
145
  * Add bulk print actions to the orders listing
146
  */
147
  public function load_bulk_actions() {
148
+ if ( $this->is_order_edit_page() ) {
149
+ // get the action that should be started.
150
+ $wp_list_table = _get_list_table( 'WP_Posts_List_Table' );
151
+ $action = $wp_list_table->current_action();
152
 
153
+ // stop if there are no post ids.
154
+ if ( ! isset( $_REQUEST['post'] ) ) {
155
  return;
156
  }
157
 
158
+ // only for specified actions.
159
+ foreach ( WCDN_Print::$template_registrations as $template_registration ) {
160
+ if ( 'wcdn_print_' . $template_registration['type'] === $action ) {
161
  $template_type = $template_registration['type'];
162
  $report_action = 'printed_' . $template_registration['type'];
163
  break;
164
  }
165
  }
166
+ if ( ! isset( $report_action ) ) {
167
  return;
168
  }
169
 
170
+ // security check.
171
+ check_admin_referer( 'bulk-posts' );
172
 
173
+ // get referrer.
174
+ if ( ! wp_get_referer() ) {
175
  return;
176
  }
177
 
178
+ // filter the referer args.
179
  $referer_args = array();
180
+ parse_str( wp_parse_url( wp_get_referer(), PHP_URL_QUERY ), $referer_args );
181
 
182
+ // set the basic args for the sendback.
183
  $args = array(
184
+ 'post_type' => $referer_args['post_type'],
185
  );
186
+ if ( isset( $referer_args['post_status'] ) ) {
187
  $args = wp_parse_args( array( 'post_status' => $referer_args['post_status'] ), $args );
188
  }
189
+ if ( isset( $referer_args['paged'] ) ) {
190
  $args = wp_parse_args( array( 'paged' => $referer_args['paged'] ), $args );
191
  }
192
+ if ( isset( $referer_args['orderby'] ) ) {
193
  $args = wp_parse_args( array( 'orderby' => $referer_args['orderby'] ), $args );
194
  }
195
+ if ( isset( $referer_args['order'] ) ) {
196
  $args = wp_parse_args( array( 'orderby' => $referer_args['order'] ), $args );
197
  }
198
 
199
+ // do the action.
200
  $post_ids = array_map( 'absint', (array) $_REQUEST['post'] );
201
+ $total = count( $post_ids );
202
+ $url = wcdn_get_print_link( $post_ids, $template_type );
203
+
204
+ // generate more args and the sendback string.
205
+ $args = wp_parse_args(
206
+ array(
207
+ $report_action => true,
208
+ 'total' => $total,
209
+ 'print_url' => rawurlencode( $url ),
210
+ ),
211
+ $args
212
+ );
213
  $sendback = add_query_arg( $args, '' );
214
+ wp_safe_redirect( $sendback );
215
  exit;
216
  }
217
+ }
218
 
219
  /**
220
  * Show confirmation message that orders are printed
221
  */
222
  public function confirm_bulk_actions() {
223
+ if ( $this->is_order_edit_page() ) {
224
+ foreach ( WCDN_Print::$template_registrations as $template_registration ) {
225
+ if ( isset( $_REQUEST[ 'printed_' . $template_registration['type'] ] ) ) {
226
+ // use singular or plural form.
227
  $total = isset( $_REQUEST['total'] ) ? absint( $_REQUEST['total'] ) : 0;
228
+ if ( $total <= 1 ) {
229
  $message = $template_registration['labels']['message'];
230
  } else {
231
  $message = $template_registration['labels']['message_plural'];
232
  }
 
233
  ?>
234
 
235
  <div id="woocommerce-delivery-notes-bulk-print-message" class="updated">
236
+ <p><?php wp_kses_post( $message, 'woocommerce-delivery-notes' ); ?>
237
+ <a href="<?php if ( isset( $_REQUEST['print_url'] ) ) : ?>
238
+ <?php
239
+ // phpcs:ignore
240
+ echo urldecode( esc_url_raw( $_REQUEST['print_url'] ) ); ?>
241
+ <?php endif; ?>" target="_blank" class="print-preview-button" id="woocommerce-delivery-notes-bulk-print-button"><?php esc_attr_e( 'Print now', 'woocommerce-delivery-notes' ); ?></a> <span class="print-preview-loading spinner"></span></p>
242
  </div>
243
 
244
  <?php
262
  global $post_id, $wcdn;
263
  ?>
264
  <div class="print-actions">
265
+ <?php foreach ( WCDN_Print::$template_registrations as $template_registration ) : ?>
266
+ <?php if ( 'yes' === get_option( 'wcdn_template_type_' . $template_registration['type'] ) && 'order' !== $template_registration['type'] ) : ?>
267
+ <?php // phpcs:disable ?>
268
+ <a href="<?php echo esc_url( wcdn_get_print_link( $post_id, $template_registration['type'] ) ); ?>" class="button print-preview-button <?php echo esc_attr( $template_registration['type'] ); ?>" target="_blank" alt="<?php esc_attr_e( __( $template_registration['labels']['print'], 'woocommerce-delivery-notes' ) ); ?>"><?php esc_attr_e( $template_registration['labels']['print'], 'woocommerce-delivery-notes' ); ?></a>
269
+ <?php // phpcs:enable ?>
270
  <?php endif; ?>
271
  <?php endforeach; ?>
272
  <span class="print-preview-loading spinner"></span>
273
  </div>
274
  <?php
275
  $create_invoice_number = get_option( 'wcdn_create_invoice_number' );
276
+ $has_invoice_number = get_post_meta( $post_id, '_wcdn_invoice_number', true );
277
+ if ( ! empty( $create_invoice_number ) && 'yes' === $create_invoice_number && $has_invoice_number ) :
278
  $invoice_number = wcdn_get_order_invoice_number( $post_id );
279
+ $invoice_date = wcdn_get_order_invoice_date( $post_id );
280
+ ?>
281
 
282
  <ul class="print-info">
283
+ <li><strong><?php esc_html_e( 'Invoice number: ', 'woocommerce-delivery-notes' ); ?></strong> <?php echo esc_attr( $invoice_number ); ?></li>
284
+ <li><strong><?php esc_html_e( 'Invoice date: ', 'woocommerce-delivery-notes' ); ?></strong> <?php echo esc_attr( $invoice_date ); ?></li>
285
  </ul>
286
 
287
  <?php endif; ?>
292
 
293
  }
294
 
295
+ ?>
includes/class-woocommerce-delivery-notes.php ADDED
@@ -0,0 +1,419 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Main class
4
+ *
5
+ * @package woocommerce-print-invoice-delivery-notes
6
+ */
7
+
8
+ /**
9
+ * Exit if accessed directly
10
+ */
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ exit;
13
+ }
14
+
15
+ /**
16
+ * Base class
17
+ */
18
+ if ( ! class_exists( 'WooCommerce_Delivery_Notes' ) ) {
19
+ /**
20
+ * WooCommerce Delivery Notes
21
+ *
22
+ * @author Tyche Softwares
23
+ * @package WooCommerce-Delivery-Notes
24
+ */
25
+ final class WooCommerce_Delivery_Notes {
26
+
27
+ /**
28
+ * The single instance of the class
29
+ *
30
+ * @var object $wcdn_instance Instance object
31
+ */
32
+ protected static $wcdn_instance = null;
33
+
34
+ /**
35
+ * Default properties
36
+ *
37
+ * @var string $plugin_version Current plugin version number
38
+ */
39
+ public static $plugin_version = '4.5.2';
40
+
41
+ /**
42
+ * Plugin URL on current installation
43
+ *
44
+ * @var string
45
+ */
46
+ public static $plugin_url;
47
+
48
+ /**
49
+ * Plugin folder path on current installation
50
+ *
51
+ * @var string
52
+ */
53
+ public static $plugin_path;
54
+
55
+ /**
56
+ * Plugin's basefile name
57
+ *
58
+ * @var string
59
+ */
60
+ public static $plugin_basefile;
61
+
62
+ /**
63
+ * Plugin's basefile path
64
+ *
65
+ * @var string
66
+ */
67
+ public static $plugin_basefile_path;
68
+
69
+ /**
70
+ * Plugin's text domain
71
+ *
72
+ * @var string
73
+ */
74
+ public static $plugin_text_domain;
75
+
76
+ /**
77
+ * Sub class instances
78
+ *
79
+ * @var object $writepanel
80
+ */
81
+ public $writepanel;
82
+
83
+ /**
84
+ * Sub class instances
85
+ *
86
+ * @var object $settings
87
+ */
88
+ public $settings;
89
+
90
+ /**
91
+ * Sub class instances
92
+ *
93
+ * @var object $print
94
+ */
95
+ public $print;
96
+
97
+ /**
98
+ * Sub class instances
99
+ *
100
+ * @var object $theme
101
+ */
102
+ public $theme;
103
+
104
+ /**
105
+ * Main Instance.
106
+ */
107
+ public static function instance() {
108
+ if ( is_null( self::$wcdn_instance ) ) {
109
+ self::$wcdn_instance = new self();
110
+ }
111
+ return self::$wcdn_instance;
112
+ }
113
+
114
+ /**
115
+ * Cloning is forbidden.
116
+ */
117
+ public function __clone() {
118
+ _doing_it_wrong( __FUNCTION__, esc_html_e( 'Cheatin&#8217; huh?', 'woocommerce-delivery-notes' ), '4.1' );
119
+ }
120
+
121
+ /**
122
+ * Unserializing instances of this class is forbidden.
123
+ */
124
+ public function __wakeup() {
125
+ _doing_it_wrong( __FUNCTION__, esc_html_e( 'Cheatin&#8217; huh?', 'woocommerce-delivery-notes' ), '4.1' );
126
+ }
127
+
128
+ /**
129
+ * Constructor.
130
+ */
131
+ public function __construct() {
132
+ $this->define_constants();
133
+ $this->init_hooks();
134
+
135
+ // Send out the load action.
136
+ do_action( 'wcdn_load' );
137
+ }
138
+
139
+ /**
140
+ * Hook into actions and filters.
141
+ */
142
+ public function init_hooks() {
143
+ add_action( 'init', array( $this, 'localise' ) );
144
+ add_action( 'woocommerce_init', array( $this, 'load' ) );
145
+
146
+ }
147
+
148
+ /**
149
+ * Define WC Constants.
150
+ */
151
+ private function define_constants() {
152
+ self::$plugin_basefile_path = dirname( dirname( __FILE__ ) ) . '/woocommerce-delivery-notes.php';
153
+ self::$plugin_basefile = plugin_basename( self::$plugin_basefile_path );
154
+ self::$plugin_url = plugin_dir_url( self::$plugin_basefile );
155
+ self::$plugin_path = trailingslashit( dirname( self::$plugin_basefile_path ) );
156
+ self::$plugin_text_domain = trim( dirname( self::$plugin_basefile ) );
157
+ }
158
+
159
+ /**
160
+ * Define constant if not already set.
161
+ *
162
+ * @param string $name Constant name.
163
+ * @param string $value Constant value.
164
+ */
165
+ private function define( $name, $value ) {
166
+
167
+ if ( ! defined( $name ) ) {
168
+ define( $name, $value );
169
+ }
170
+ }
171
+
172
+ /**
173
+ * Include the main plugin classes and functions.
174
+ */
175
+ public function include_classes() {
176
+ include_once 'class-wcdn-print.php';
177
+ include_once 'class-wcdn-settings.php';
178
+ include_once 'class-wcdn-writepanel.php';
179
+ include_once 'class-wcdn-theme.php';
180
+ if ( true === is_admin() ) {
181
+ include_once 'wcdn-all-component.php';
182
+ }
183
+ }
184
+
185
+ /**
186
+ * Function used to init Template Functions.
187
+ * This makes them pluggable by plugins and themes.
188
+ */
189
+ public function include_template_functions() {
190
+ include_once 'wcdn-template-functions.php';
191
+ include_once 'wcdn-template-hooks.php';
192
+ }
193
+
194
+ /**
195
+ * Load the localisation.
196
+ */
197
+ public function localise() {
198
+ // Load language files from the wp-content/languages/plugins folder.
199
+ $mo_file = WP_LANG_DIR . '/plugins/' . self::$plugin_text_domain . '-' . get_locale() . '.mo';
200
+ if ( is_readable( $mo_file ) ) {
201
+ load_textdomain( self::$plugin_text_domain, $mo_file );
202
+ }
203
+
204
+ // Otherwise load them from the plugin folder.
205
+ load_plugin_textdomain( self::$plugin_text_domain, false, dirname( self::$plugin_basefile ) . '/languages/' );
206
+ }
207
+
208
+ /**
209
+ * Load the main plugin classes and functions.
210
+ */
211
+ public function load() {
212
+ // WooCommerce activation required.
213
+ if ( $this->is_woocommerce_activated() ) {
214
+ // Include the classes.
215
+ $this->include_classes();
216
+
217
+ // Create the instances.
218
+ $this->print = new WCDN_Print();
219
+ $this->settings = new WCDN_Settings();
220
+ $this->writepanel = new WCDN_Writepanel();
221
+ $this->theme = new WCDN_Theme();
222
+
223
+ // Load the hooks for the template after the objetcs.
224
+ // Like this the template has full access to all objects.
225
+ add_filter( 'plugin_action_links_' . self::$plugin_basefile, array( $this, 'add_settings_link' ) );
226
+ add_action( 'admin_init', array( $this, 'update' ) );
227
+ add_action( 'init', array( $this, 'include_template_functions' ) );
228
+
229
+ add_filter( 'ts_deativate_plugin_questions', array( &$this, 'wcdn_deactivate_add_questions' ), 10, 1 );
230
+ add_filter( 'ts_tracker_data', array( &$this, 'wcdn_ts_add_plugin_tracking_data' ), 10, 1 );
231
+ add_filter( 'ts_tracker_opt_out_data', array( &$this, 'wcdn_get_data_for_opt_out' ), 10, 1 );
232
+
233
+ // Send out the init action.
234
+ do_action( 'wcdn_init' );
235
+ }
236
+ }
237
+
238
+ /**
239
+ * Plugin's data to be tracked when Allow option is choosed.
240
+ *
241
+ * @hook ts_tracker_data
242
+ *
243
+ * @param array $data Contains the data to be tracked.
244
+ *
245
+ * @return array Plugin's data to track.
246
+ */
247
+ public static function wcdn_ts_add_plugin_tracking_data( $data ) {
248
+
249
+ $wcdn_tracker_nonce = isset( $_GET['wcdn_tracker_nonce'] ) ? sanitize_text_field( wp_unslash( $_GET['wcdn_tracker_nonce'] ) ) : '';
250
+
251
+ if ( isset( $_GET['wcdn_tracker_optin'] ) && isset( $_GET['wcdn_tracker_nonce'] ) && wp_verify_nonce( $wcdn_tracker_nonce, 'wcdn_tracker_optin' ) ) {
252
+
253
+ $plugin_data['ts_meta_data_table_name'] = 'ts_tracking_wcdn_meta_data';
254
+ $plugin_data['ts_plugin_name'] = 'WooCommerce Print Invoice & Delivery Note';
255
+
256
+ // Get all plugin options info.
257
+ $plugin_data['invoice_in_admin'] = get_option( 'wcdn_template_type_invoice' );
258
+ $plugin_data['delivery_in_admin'] = get_option( 'wcdn_template_type_delivery-note' );
259
+ $plugin_data['receipt_in_admin'] = get_option( 'wcdn_template_type_receipt' );
260
+ $plugin_data['print_in_myaccount'] = get_option( 'wcdn_print_button_on_my_account_page' );
261
+ $plugin_data['print_in_vieworder'] = get_option( 'wcdn_print_button_on_my_account_page' );
262
+ $plugin_data['print_in_email'] = get_option( 'wcdn_print_button_on_my_account_page' );
263
+ $plugin_data['wcdn_plugin_version'] = self::$plugin_version;
264
+ $plugin_data['wcdn_allow_tracking'] = get_option( 'wcdn_allow_tracking' );
265
+ $data['plugin_data'] = $plugin_data;
266
+ }
267
+ return $data;
268
+ }
269
+
270
+
271
+ /**
272
+ * Tracking data to send when No, thanks. button is clicked.
273
+ *
274
+ * @hook ts_tracker_opt_out_data
275
+ *
276
+ * @param array $params Parameters to pass for tracking data.
277
+ *
278
+ * @return array Data to track when opted out.
279
+ */
280
+ public static function wcdn_get_data_for_opt_out( $params ) {
281
+ $plugin_data['ts_meta_data_table_name'] = 'ts_tracking_wcdn_meta_data';
282
+ $plugin_data['ts_plugin_name'] = 'WooCommerce Print Invoice & Delivery Note';
283
+
284
+ // Store count info.
285
+ $params['plugin_data'] = $plugin_data;
286
+
287
+ return $params;
288
+ }
289
+
290
+ /**
291
+ * It will add the question for the deactivate popup modal.
292
+ *
293
+ * @param array $dfw_deactivate_questions Array of all questions.
294
+ *
295
+ * @return array $dfw_deactivate_questions All questions.
296
+ */
297
+ public static function wcdn_deactivate_add_questions( $dfw_deactivate_questions ) {
298
+
299
+ $dfw_deactivate_questions = array(
300
+ 0 => array(
301
+ 'id' => 4,
302
+ 'text' => __( "I can't differentiate between Invoice, Delivery Notes & Receipt. The templates are the same. ", 'woocommerce-delivery-notes' ),
303
+ 'input_type' => '',
304
+ 'input_placeholder' => '',
305
+ ),
306
+ 1 => array(
307
+ 'id' => 5,
308
+ 'text' => __( "The invoice sent through mail can't be downloaded as PDF directly.", 'woocommerce-delivery-notes' ),
309
+ 'input_type' => '',
310
+ 'input_placeholder' => '',
311
+ ),
312
+ 2 => array(
313
+ 'id' => 6,
314
+ 'text' => __( 'The plugin is not compatible with another plugin.', 'woocommerce-delivery-notes' ),
315
+ 'input_type' => 'textfield',
316
+ 'input_placeholder' => 'Which plugin?',
317
+ ),
318
+ 3 => array(
319
+ 'id' => 7,
320
+ 'text' => __( 'This plugin is not useful to me.', 'woocommerce-delivery-notes' ),
321
+ 'input_type' => '',
322
+ 'input_placeholder' => '',
323
+ ),
324
+
325
+ );
326
+ return $dfw_deactivate_questions;
327
+ }
328
+ /**
329
+ * Install or update the default settings.
330
+ */
331
+ public function update() {
332
+ $option_version = get_option( 'wcdn_version', '1' );
333
+
334
+ // Update the settings.
335
+ if ( version_compare( $option_version, self::$plugin_version, '<' ) ) {
336
+ // Legacy updates.
337
+ if ( version_compare( $option_version, '4.2.0', '<' ) ) {
338
+ // Group invoice numbering.
339
+ $invoice_start = intval( get_option( 'wcdn_invoice_number_start', 1 ) );
340
+ $invoice_counter = intval( get_option( 'wcdn_invoice_number_counter', 0 ) );
341
+ update_option( 'wcdn_invoice_number_count', $invoice_start + $invoice_counter );
342
+
343
+ // Translate checkbox values.
344
+ foreach ( $this->settings->get_settings() as $value ) {
345
+ if ( isset( $value['id'] ) && isset( $value['type'] ) && 'checkbox' === $value['type'] ) {
346
+ $autoload = isset( $value['autoload'] ) ? (bool) $value['autoload'] : true;
347
+ $option = get_option( $value['id'] );
348
+ if ( (bool) $option ) {
349
+ update_option( $value['id'], 'yes' );
350
+ } else {
351
+ update_option( $value['id'], 'no' );
352
+ }
353
+ }
354
+ }
355
+ }
356
+
357
+ // Set all options that have default values.
358
+ foreach ( $this->settings->get_settings() as $value ) {
359
+ if ( isset( $value['default'] ) && isset( $value['id'] ) ) {
360
+ $autoload = isset( $value['autoload'] ) ? (bool) $value['autoload'] : true;
361
+ add_option( $value['id'], $value['default'], '', ( $autoload ? 'yes' : 'no' ) );
362
+ }
363
+ }
364
+
365
+ // Flush the transients in case the endpoint changed.
366
+ set_transient( 'wcdn_flush_rewrite_rules', true );
367
+
368
+ // Update the settings to the latest version.
369
+ update_option( 'wcdn_version', self::$plugin_version );
370
+ }
371
+ }
372
+
373
+ /**
374
+ * Add settings link to plugin page.
375
+ *
376
+ * @param array $links Links on Plugins page.
377
+ */
378
+ public function add_settings_link( $links ) {
379
+ $url = esc_url(
380
+ admin_url(
381
+ add_query_arg(
382
+ array(
383
+ 'page' => 'wc-settings',
384
+ 'tab' => $this->settings->id,
385
+ ),
386
+ 'admin.php'
387
+ )
388
+ )
389
+ );
390
+ $settings = sprintf( '<a href="%s" title="%s">%s</a>', $url, __( 'Go to the settings page', 'woocommerce-delivery-notes' ), __( 'Settings', 'woocommerce-delivery-notes' ) );
391
+ array_unshift( $links, $settings );
392
+ return $links;
393
+ }
394
+
395
+ /**
396
+ * Check if woocommerce is activated.
397
+ */
398
+ public function is_woocommerce_activated() {
399
+ $blog_plugins = get_option( 'active_plugins', array() );
400
+ $site_plugins = get_site_option( 'active_sitewide_plugins', array() );
401
+ $woocommerce_basename = plugin_basename( WC_PLUGIN_FILE );
402
+
403
+ if ( ( in_array( $woocommerce_basename, $blog_plugins, true ) || isset( $site_plugins[ $woocommerce_basename ] ) ) && version_compare( WC_VERSION, '2.2', '>=' ) ) {
404
+ return true;
405
+ } else {
406
+ return false;
407
+ }
408
+ }
409
+
410
+ }
411
+ }
412
+
413
+ /**
414
+ * Returns the main instance of the plugin to prevent the need to use globals.
415
+ */
416
+ function wcdn_init() {
417
+ return WC_Delivery_Notes::instance();
418
+ }
419
+
includes/wcdn-template-functions.php CHANGED
@@ -1,19 +1,27 @@
1
  <?php
 
 
 
 
 
2
 
3
  /**
4
  * Exit if accessed directly
5
  */
6
- if ( !defined( 'ABSPATH' ) ) {
7
- exit;
8
  }
9
 
10
  /**
11
  * Output the template part
 
 
 
12
  */
13
  function wcdn_get_template_content( $name, $args = null ) {
14
  global $wcdn;
15
  $location = $wcdn->print->get_template_file_location( $name );
16
- if( $location ) {
17
  wc_get_template( $name, $args, $location, $location );
18
  }
19
  }
@@ -31,11 +39,17 @@ function wcdn_get_template_type() {
31
  */
32
  function wcdn_get_template_title() {
33
  global $wcdn;
 
34
  return apply_filters( 'wcdn_template_title', __( $wcdn->print->template['labels']['name'], 'woocommerce-delivery-notes' ) );
35
  }
36
 
37
  /**
38
  * Return print page link
 
 
 
 
 
39
  */
40
  function wcdn_get_print_link( $order_ids, $template_type = 'order', $order_email = null, $permalink = false ) {
41
  global $wcdn;
@@ -46,7 +60,7 @@ function wcdn_get_print_link( $order_ids, $template_type = 'order', $order_email
46
  * Output the document title depending on type
47
  */
48
  function wcdn_document_title() {
49
- echo apply_filters( 'wcdn_document_title', wcdn_get_template_title() );
50
  }
51
 
52
  /**
@@ -86,24 +100,23 @@ function wcdn_navigation_style() {
86
  -webkit-box-sizing: border-box;
87
  -moz-box-sizing: border-box;
88
  box-sizing: border-box;
89
-
90
  background: #2ea2cc;
91
  border-color: #0074a2;
92
- -webkit-box-shadow: inset 0 1px 0 rgba(120,200,230,0.5), 0 1px 0 rgba(0,0,0,.15);
93
- box-shadow: inset 0 1px 0 rgba(120,200,230,0.5), 0 1px 0 rgba(0,0,0,.15);
94
- color: #fff;
95
  text-decoration: none;
96
  }
97
-
98
  #navigation .button:hover,
99
  #navigation .button:focus {
100
  background: #1e8cbe;
101
  border-color: #0074a2;
102
- -webkit-box-shadow: inset 0 1px 0 rgba(120,200,230,0.6);
103
- box-shadow: inset 0 1px 0 rgba(120,200,230,0.6);
104
  color: #fff;
105
  }
106
-
107
  #navigation .button:active {
108
  background: #1b7aa6;
109
  border-color: #005684;
@@ -111,7 +124,7 @@ function wcdn_navigation_style() {
111
  -webkit-box-shadow: inset 0 1px 0 rgba(0,0,0,0.1);
112
  box-shadow: inset 0 1px 0 rgba(0,0,0,0.1);
113
  }
114
-
115
  @media print {
116
  #navigation {
117
  display: none;
@@ -127,7 +140,7 @@ function wcdn_navigation_style() {
127
  function wcdn_navigation() {
128
  ?>
129
  <div id="navigation">
130
- <a href="#" class="button" onclick="window.print();return false;"><?php _e( 'Print', 'woocommerce-delivery-notes' ); ?></a>
131
  </div><!-- #navigation -->
132
  <?php
133
  }
@@ -138,25 +151,35 @@ function wcdn_navigation() {
138
  function wcdn_template_stylesheet() {
139
  global $wcdn;
140
  $name = apply_filters( 'wcdn_template_stylesheet_name', 'style.css' );
 
141
  ?>
142
- <link rel="stylesheet" href="<?php echo $wcdn->print->get_template_file_location( $name, true ) . $name; ?>" type="text/css" media="screen,print" />
143
  <?php
 
144
  }
145
 
146
  /**
147
  * Output the template print content
 
 
 
148
  */
149
  function wcdn_content( $order, $template_type ) {
150
  global $wcdn;
151
-
152
- // Add WooCommerce hooks here to not
153
- // make global changes to the totals
154
  add_filter( 'woocommerce_get_order_item_totals', 'wcdn_remove_semicolon_from_totals', 10, 2 );
155
  add_filter( 'woocommerce_get_order_item_totals', 'wcdn_remove_payment_method_from_totals', 20, 2 );
156
  add_filter( 'woocommerce_get_order_item_totals', 'wcdn_add_refunded_order_totals', 30, 2 );
157
-
158
- // Load the template
159
- wcdn_get_template_content( 'print-content.php', array( 'order' => $order, 'template_type' => $template_type ) );
 
 
 
 
 
 
160
  }
161
 
162
  /**
@@ -173,28 +196,28 @@ function wcdn_get_company_logo_id() {
173
  function wcdn_company_logo() {
174
  global $wcdn;
175
  $attachment_id = wcdn_get_company_logo_id();
176
- $company = get_option( 'wcdn_custom_company_name' );
177
- if( $attachment_id ) {
178
  $attachment_src = wp_get_attachment_image_src( $attachment_id, 'full', false );
179
-
180
- // resize the image to a 1/4 of the original size
181
- // to have a printing point density of about 288ppi.
182
  ?>
183
- <img src="<?php echo $attachment_src[0]; ?>" width="<?php echo round( $attachment_src[1] / 4 ); ?>" height="<?php echo round( $attachment_src[2] / 4 ); ?>" alt="<?php echo esc_attr( $company ); ?>" />
184
  <?php
185
  }
186
  }
187
 
188
  /**
189
- * Return default title name of Delivery Note
190
  */
191
  function wcdn_company_name() {
192
  global $wcdn;
193
  $name = trim( get_option( 'wcdn_custom_company_name' ) );
194
- if( !empty( $name ) ) {
195
- echo apply_filters( 'wcdn_company_name', stripslashes( wptexturize( $name ) ) );
 
196
  } else {
197
- echo apply_filters( 'wcdn_company_name', get_bloginfo( 'name' ) );
198
  }
199
  }
200
 
@@ -203,7 +226,7 @@ function wcdn_company_name() {
203
  */
204
  function wcdn_company_info() {
205
  global $wcdn;
206
- echo stripslashes( wpautop( wptexturize( get_option( 'wcdn_company_address' ) ) ) );
207
  }
208
 
209
  /**
@@ -216,6 +239,8 @@ function wcdn_get_orders() {
216
 
217
  /**
218
  * Get an order
 
 
219
  */
220
  function wcdn_get_order( $order_id ) {
221
  global $wcdn;
@@ -224,71 +249,74 @@ function wcdn_get_order( $order_id ) {
224
 
225
  /**
226
  * Get the order info fields
 
 
227
  */
228
  function wcdn_get_order_info( $order ) {
229
  global $wcdn;
230
- $fields = array();
231
  $create_invoice_number = get_option( 'wcdn_create_invoice_number' );
232
-
233
-
234
-
235
- $wdn_order_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_id() : $order->id;
236
- $order_post = get_post( $wdn_order_id );
237
-
238
- $wdn_order_order_date = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order_post->post_date : $order->order_date;
239
- $wdn_order_payment_method_title = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_payment_method_title() : $order->payment_method_title;
240
- $wdn_order_billing_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_billing_email() : $order->billing_email;
241
- $wdn_order_billing_phone = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_billing_phone() : $order->billing_phone;
242
-
243
- if( wcdn_get_template_type() == 'invoice' && !empty( $create_invoice_number ) && $create_invoice_number == 'yes' ) {
244
-
245
- $fields['invoice_number'] = array(
246
  'label' => __( 'Invoice Number', 'woocommerce-delivery-notes' ),
247
- 'value' => wcdn_get_order_invoice_number( $wdn_order_id )
248
  );
249
  }
250
-
251
- if( wcdn_get_template_type() == 'invoice:' ) {
252
- $fields['invoice_date'] = array(
253
  'label' => __( 'Invoice Date', 'woocommerce-delivery-notes' ),
254
- 'value' => wcdn_get_order_invoice_date( $wdn_order_id )
255
  );
256
  }
257
-
258
- $fields['order_number'] = array(
259
  'label' => __( 'Order Number', 'woocommerce-delivery-notes' ),
260
- 'value' => $order->get_order_number()
261
  );
262
-
263
- $fields['order_date'] = array(
264
  'label' => __( 'Order Date', 'woocommerce-delivery-notes' ),
265
- 'value' => date_i18n( get_option( 'date_format' ), strtotime( $wdn_order_order_date ) )
266
  );
267
-
268
- $fields['payment_method'] = array(
269
  'label' => __( 'Payment Method', 'woocommerce-delivery-notes' ),
270
- 'value' => __( $wdn_order_payment_method_title, 'woocommerce' )
 
271
  );
272
-
273
- if( $wdn_order_billing_id ) {
274
  $fields['billing_email'] = array(
275
  'label' => __( 'Email', 'woocommerce-delivery-notes' ),
276
- 'value' => $wdn_order_billing_id
277
  );
278
  }
279
-
280
- if( $wdn_order_billing_phone ) {
281
  $fields['billing_phone'] = array(
282
  'label' => __( 'Telephone', 'woocommerce-delivery-notes' ),
283
- 'value' => $wdn_order_billing_phone
284
  );
285
  }
286
-
287
  return $fields;
288
  }
289
 
290
  /**
291
  * Get the invoice number of an order
 
 
292
  */
293
  function wcdn_get_order_invoice_number( $order_id ) {
294
  global $wcdn;
@@ -297,6 +325,8 @@ function wcdn_get_order_invoice_number( $order_id ) {
297
 
298
  /**
299
  * Get the invoice date of an order
 
 
300
  */
301
  function wcdn_get_order_invoice_date( $order_id ) {
302
  global $wcdn;
@@ -305,27 +335,33 @@ function wcdn_get_order_invoice_date( $order_id ) {
305
 
306
  /**
307
  * Additional fields for the product
 
 
 
 
308
  */
309
  function wcdn_additional_product_fields( $fields = null, $product = null, $order ) {
310
  $new_fields = array();
311
-
312
- // Stock keeping unit
313
- if( $product && $product->exists() && $product->get_sku() ) {
314
  $fields['sku'] = array(
315
  'label' => __( 'SKU:', 'woocommerce-delivery-notes' ),
316
- 'value' => $product->get_sku()
317
  );
318
- }
319
  return array_merge( $fields, $new_fields );
320
  }
321
 
322
  /**
323
  * Check if a shipping address is enabled
 
 
324
  */
325
  function wcdn_has_shipping_address( $order ) {
326
- // Works only with WooCommerce 2.2 and higher
327
- if( version_compare( WC_VERSION, '2.2.0', '>=' ) ) {
328
- if( ! wc_ship_to_billing_address_only() && $order->needs_shipping_address() && get_option( 'woocommerce_calc_shipping' ) !== 'no' ) {
329
  return true;
330
  } else {
331
  return false;
@@ -336,11 +372,13 @@ function wcdn_has_shipping_address( $order ) {
336
 
337
  /**
338
  * Check if an order contains a refund
 
 
339
  */
340
  function wcdn_has_refund( $order ) {
341
- // Works only with WooCommerce 2.2 and higher
342
- if( version_compare( WC_VERSION, '2.2.0', '>=' ) ) {
343
- if( $order->get_total_refunded() ) {
344
  return true;
345
  }
346
  }
@@ -349,6 +387,10 @@ function wcdn_has_refund( $order ) {
349
 
350
  /**
351
  * Gets formatted item subtotal for display.
 
 
 
 
352
  */
353
  function wcdn_get_formatted_item_price( $order, $item, $tax_display = '' ) {
354
  if ( ! $tax_display ) {
@@ -359,19 +401,24 @@ function wcdn_get_formatted_item_price( $order, $item, $tax_display = '' ) {
359
  return '';
360
  }
361
 
362
- $wdn_order_currency = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_currency() : $order->get_order_currency();
363
-
364
- if ( 'excl' == $tax_display ) {
365
- if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ){
366
- $ex_tax_label = wc_prices_include_tax() ? 1 : 0;
367
- }else{
368
- $ex_tax_label = $order->prices_include_tax ? 1 : 0;
369
- }
370
-
371
-
372
- $subtotal = wc_price( $order->get_item_subtotal( $item ), array( 'ex_tax_label' => $ex_tax_label, 'currency' => $wdn_order_currency ) );
 
 
 
 
 
373
  } else {
374
- $subtotal = wc_price( $order->get_item_subtotal( $item, true ), array('currency' => $wdn_order_currency ) );
375
  }
376
 
377
  return apply_filters( 'wcdn_formatted_item_price', $subtotal, $item, $order );
@@ -379,119 +426,135 @@ function wcdn_get_formatted_item_price( $order, $item, $tax_display = '' ) {
379
 
380
  /**
381
  * Add refund totals
 
 
 
382
  */
383
- function wcdn_add_refunded_order_totals( $total_rows, $order ) {
384
- if( wcdn_has_refund( $order ) ) {
385
- $wdn_order_currency = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_currency() : $order->get_order_currency();
386
 
387
- if( version_compare( WC_VERSION, '2.3.0', '>=' ) ) {
388
  $refunded_tax_del = '';
389
  $refunded_tax_ins = '';
390
-
391
- // Tax for inclusive prices
392
- if ( wc_tax_enabled() && 'incl' == get_option( 'woocommerce_tax_display_cart' ) ) {
393
  $tax_del_array = array();
394
  $tax_ins_array = array();
395
-
396
- if ( 'itemized' == get_option( 'woocommerce_tax_total_display' ) ) {
397
-
398
  foreach ( $order->get_tax_totals() as $code => $tax ) {
399
  $tax_del_array[] = sprintf( '%s %s', $tax->formatted_amount, $tax->label );
400
  $tax_ins_array[] = sprintf( '%s %s', wc_price( $tax->amount - $order->get_total_tax_refunded_by_rate_id( $tax->rate_id ), array( 'currency' => $wdn_order_currency ) ), $tax->label );
401
  }
402
-
403
  } else {
404
  $tax_del_array[] = sprintf( '%s %s', wc_price( $order->get_total_tax(), array( 'currency' => $wdn_order_currency ) ), WC()->countries->tax_or_vat() );
405
  $tax_ins_array[] = sprintf( '%s %s', wc_price( $order->get_total_tax() - $order->get_total_tax_refunded(), array( 'currency' => $wdn_order_currency ) ), WC()->countries->tax_or_vat() );
406
  }
407
-
408
  if ( ! empty( $tax_del_array ) ) {
 
409
  $refunded_tax_del .= ' ' . sprintf( __( '(Includes %s)', 'woocommerce' ), implode( ', ', $tax_del_array ) );
410
  }
411
-
412
  if ( ! empty( $tax_ins_array ) ) {
 
413
  $refunded_tax_ins .= ' ' . sprintf( __( '(Includes %s)', 'woocommerce' ), implode( ', ', $tax_ins_array ) );
414
  }
415
  }
416
- // use only the number for new wc versions
417
  $order_subtotal = wc_price( $order->get_total(), array( 'currency' => $wdn_order_currency ) );
418
  } else {
419
  $refunded_tax_del = '';
420
  $refunded_tax_ins = '';
421
-
422
- // use the normal total for older wc versions
423
  $order_subtotal = $total_rows['order_total']['value'];
424
- }
425
-
426
- // Add refunded totals row
427
  $total_rows['wcdn_refunded_total'] = array(
428
- 'label' => __( 'Refund', 'woocommerce-delivery-notes' ),
429
- 'value' => wc_price( -$order->get_total_refunded(), array( 'currency' => $wdn_order_currency ) )
430
  );
431
-
432
- // Add new order totals row
433
  $total_rows['wcdn_order_total'] = array(
434
- 'label' => $total_rows['order_total']['label'],
435
- 'value' => wc_price( $order->get_total() - $order->get_total_refunded(), array( 'currency' => $wdn_order_currency ) ) . $refunded_tax_ins
436
  );
437
-
438
- // Edit the original order total row
439
  $total_rows['order_total'] = array(
440
- 'label' => __( 'Order Subtotal', 'woocommerce-delivery-notes' ),
441
- 'value' => $order_subtotal
442
  );
443
  }
444
-
445
  return $total_rows;
446
  }
447
 
448
  /**
449
- * Remove the semicolon from the totals
 
 
 
450
  */
451
- function wcdn_remove_semicolon_from_totals( $total_rows, $order ) {
452
- foreach( $total_rows as $key => $row ) {
453
  $label = $row['label'];
454
  $colon = strrpos( $label, ':' );
455
- if( $colon !== false ) {
456
  $label = substr_replace( $label, '', $colon, 1 );
457
- }
458
- $total_rows[$key]['label'] = $label;
459
  }
460
  return $total_rows;
461
  }
462
 
463
  /**
464
- * Remove the payment method text from the totals
 
 
 
465
  */
466
- function wcdn_remove_payment_method_from_totals( $total_rows, $order ) {
467
- unset($total_rows['payment_method']);
468
  return $total_rows;
469
  }
470
 
471
  /**
472
  * Return customer notes
 
 
473
  */
474
  function wcdn_get_customer_notes( $order ) {
475
  global $wcdn;
476
-
477
- $wdn_order_customer_notes = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_customer_note() : $order->customer_note;
478
- return stripslashes( wpautop( wptexturize( $wdn_order_customer_notes ) ) );
479
  }
480
 
481
  /**
482
  * Show customer notes
 
 
483
  */
484
  function wcdn_customer_notes( $order ) {
485
  global $wcdn;
486
- echo wcdn_get_customer_notes( $order );
487
  }
488
 
489
  /**
490
  * Return has customer notes
 
 
491
  */
492
  function wcdn_has_customer_notes( $order ) {
493
  global $wcdn;
494
- if( wcdn_get_customer_notes( $order ) ) {
495
  return true;
496
  } else {
497
  return false;
@@ -511,7 +574,7 @@ function wcdn_get_personal_notes() {
511
  */
512
  function wcdn_personal_notes() {
513
  global $wcdn;
514
- echo wcdn_get_personal_notes();
515
  }
516
 
517
  /**
@@ -527,7 +590,7 @@ function wcdn_get_policies_conditions() {
527
  */
528
  function wcdn_policies_conditions() {
529
  global $wcdn;
530
- echo wcdn_get_policies_conditions();
531
  }
532
 
533
  /**
@@ -535,7 +598,7 @@ function wcdn_policies_conditions() {
535
  */
536
  function wcdn_get_imprint() {
537
  global $wcdn;
538
- return stripslashes( wpautop( wptexturize( get_option( 'wcdn_footer_imprint' ) ) ) );
539
  }
540
 
541
  /**
@@ -543,8 +606,8 @@ function wcdn_get_imprint() {
543
  */
544
  function wcdn_imprint() {
545
  global $wcdn;
546
- echo wcdn_get_imprint();
547
  }
548
 
549
 
550
- ?>
1
  <?php
2
+ /**
3
+ * Template functions
4
+ *
5
+ * @package woocommerce-print-invoice-delivery-notes
6
+ */
7
 
8
  /**
9
  * Exit if accessed directly
10
  */
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ exit;
13
  }
14
 
15
  /**
16
  * Output the template part
17
+ *
18
+ * @param string $name Template name.
19
+ * @param array $args Arguments array.
20
  */
21
  function wcdn_get_template_content( $name, $args = null ) {
22
  global $wcdn;
23
  $location = $wcdn->print->get_template_file_location( $name );
24
+ if ( $location ) {
25
  wc_get_template( $name, $args, $location, $location );
26
  }
27
  }
39
  */
40
  function wcdn_get_template_title() {
41
  global $wcdn;
42
+ // phpcs:ignore
43
  return apply_filters( 'wcdn_template_title', __( $wcdn->print->template['labels']['name'], 'woocommerce-delivery-notes' ) );
44
  }
45
 
46
  /**
47
  * Return print page link
48
+ *
49
+ * @param array $order_ids Order IDs.
50
+ * @param string $template_type Template Type.
51
+ * @param string $order_email Order email.
52
+ * @param boolean $permalink Permalinks.
53
  */
54
  function wcdn_get_print_link( $order_ids, $template_type = 'order', $order_email = null, $permalink = false ) {
55
  global $wcdn;
60
  * Output the document title depending on type
61
  */
62
  function wcdn_document_title() {
63
+ echo esc_attr( apply_filters( 'wcdn_document_title', wcdn_get_template_title() ) );
64
  }
65
 
66
  /**
100
  -webkit-box-sizing: border-box;
101
  -moz-box-sizing: border-box;
102
  box-sizing: border-box;
 
103
  background: #2ea2cc;
104
  border-color: #0074a2;
105
+ -webkit-box-shadow: inset 0 1px 0 rgba(120,200,230,0.5), 0 1px 0 rgba(0,0,0,.15);
106
+ box-shadow: inset 0 1px 0 rgba(120,200,230,0.5), 0 1px 0 rgba(0,0,0,.15);
107
+ color: #fff;
108
  text-decoration: none;
109
  }
110
+
111
  #navigation .button:hover,
112
  #navigation .button:focus {
113
  background: #1e8cbe;
114
  border-color: #0074a2;
115
+ -webkit-box-shadow: inset 0 1px 0 rgba(120,200,230,0.6);
116
+ box-shadow: inset 0 1px 0 rgba(120,200,230,0.6);
117
  color: #fff;
118
  }
119
+
120
  #navigation .button:active {
121
  background: #1b7aa6;
122
  border-color: #005684;
124
  -webkit-box-shadow: inset 0 1px 0 rgba(0,0,0,0.1);
125
  box-shadow: inset 0 1px 0 rgba(0,0,0,0.1);
126
  }
127
+
128
  @media print {
129
  #navigation {
130
  display: none;
140
  function wcdn_navigation() {
141
  ?>
142
  <div id="navigation">
143
+ <a href="#" class="button" onclick="window.print();return false;"><?php esc_html_e( 'Print', 'woocommerce-delivery-notes' ); ?></a>
144
  </div><!-- #navigation -->
145
  <?php
146
  }
151
  function wcdn_template_stylesheet() {
152
  global $wcdn;
153
  $name = apply_filters( 'wcdn_template_stylesheet_name', 'style.css' );
154
+ // phpcs:disable
155
  ?>
156
+ <link rel="stylesheet" href="<?php echo esc_url( $wcdn->print->get_template_file_location( $name, true ) ) . esc_html( $name ); ?>" type="text/css" media="screen,print" />
157
  <?php
158
+ // phpcs:enable
159
  }
160
 
161
  /**
162
  * Output the template print content
163
+ *
164
+ * @param object $order Order object.
165
+ * @param string $template_type Template type.
166
  */
167
  function wcdn_content( $order, $template_type ) {
168
  global $wcdn;
169
+
170
+ // Add WooCommerce hooks here to not make global changes to the totals.
 
171
  add_filter( 'woocommerce_get_order_item_totals', 'wcdn_remove_semicolon_from_totals', 10, 2 );
172
  add_filter( 'woocommerce_get_order_item_totals', 'wcdn_remove_payment_method_from_totals', 20, 2 );
173
  add_filter( 'woocommerce_get_order_item_totals', 'wcdn_add_refunded_order_totals', 30, 2 );
174
+
175
+ // Load the template.
176
+ wcdn_get_template_content(
177
+ 'print-content.php',
178
+ array(
179
+ 'order' => $order,
180
+ 'template_type' => $template_type,
181
+ )
182
+ );
183
  }
184
 
185
  /**
196
  function wcdn_company_logo() {
197
  global $wcdn;
198
  $attachment_id = wcdn_get_company_logo_id();
199
+ $company = get_option( 'wcdn_custom_company_name' );
200
+ if ( $attachment_id ) {
201
  $attachment_src = wp_get_attachment_image_src( $attachment_id, 'full', false );
202
+
203
+ // resize the image to a 1/4 of the original size to have a printing point density of about 288ppi.
 
204
  ?>
205
+ <img src="<?php echo esc_url( $attachment_src[0] ); ?>" width="<?php echo esc_attr( round( $attachment_src[1] / 4 ) ); ?>" height="<?php echo esc_attr( round( $attachment_src[2] / 4 ) ); ?>" alt="<?php echo esc_attr( $company ); ?>" />
206
  <?php
207
  }
208
  }
209
 
210
  /**
211
+ * Return default title name of Delivery Note
212
  */
213
  function wcdn_company_name() {
214
  global $wcdn;
215
  $name = trim( get_option( 'wcdn_custom_company_name' ) );
216
+
217
+ if ( ! empty( $name ) ) {
218
+ echo esc_attr( apply_filters( 'wcdn_company_name', stripslashes( wptexturize( $name ) ) ) );
219
  } else {
220
+ echo esc_attr( apply_filters( 'wcdn_company_name', get_bloginfo( 'name' ) ) );
221
  }
222
  }
223
 
226
  */
227
  function wcdn_company_info() {
228
  global $wcdn;
229
+ echo wp_kses_post( stripslashes( wpautop( wptexturize( get_option( 'wcdn_company_address' ) ) ) ) );
230
  }
231
 
232
  /**
239
 
240
  /**
241
  * Get an order
242
+ *
243
+ * @param int $order_id Order ID.
244
  */
245
  function wcdn_get_order( $order_id ) {
246
  global $wcdn;
249
 
250
  /**
251
  * Get the order info fields
252
+ *
253
+ * @param object $order Order object.
254
  */
255
  function wcdn_get_order_info( $order ) {
256
  global $wcdn;
257
+ $fields = array();
258
  $create_invoice_number = get_option( 'wcdn_create_invoice_number' );
259
+
260
+ $wdn_order_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) ? $order->get_id() : $order->id;
261
+ $order_post = get_post( $wdn_order_id );
262
+
263
+ $wdn_order_order_date = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) ? $order_post->post_date : $order->order_date;
264
+ $wdn_order_payment_method_title = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) ? $order->get_payment_method_title() : $order->payment_method_title;
265
+ $wdn_order_billing_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) ? $order->get_billing_email() : $order->billing_email;
266
+ $wdn_order_billing_phone = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) ? $order->get_billing_phone() : $order->billing_phone;
267
+
268
+ if ( 'invoice' === wcdn_get_template_type() && ! empty( $create_invoice_number ) && 'yes' === $create_invoice_number ) {
269
+
270
+ $fields['invoice_number'] = array(
 
 
271
  'label' => __( 'Invoice Number', 'woocommerce-delivery-notes' ),
272
+ 'value' => wcdn_get_order_invoice_number( $wdn_order_id ),
273
  );
274
  }
275
+
276
+ if ( 'invoice:' === wcdn_get_template_type() ) {
277
+ $fields['invoice_date'] = array(
278
  'label' => __( 'Invoice Date', 'woocommerce-delivery-notes' ),
279
+ 'value' => wcdn_get_order_invoice_date( $wdn_order_id ),
280
  );
281
  }
282
+
283
+ $fields['order_number'] = array(
284
  'label' => __( 'Order Number', 'woocommerce-delivery-notes' ),
285
+ 'value' => $order->get_order_number(),
286
  );
287
+
288
+ $fields['order_date'] = array(
289
  'label' => __( 'Order Date', 'woocommerce-delivery-notes' ),
290
+ 'value' => date_i18n( get_option( 'date_format' ), strtotime( $wdn_order_order_date ) ),
291
  );
292
+
293
+ $fields['payment_method'] = array(
294
  'label' => __( 'Payment Method', 'woocommerce-delivery-notes' ),
295
+ // phpcs:ignore
296
+ 'value' => __( $wdn_order_payment_method_title, 'woocommerce' ),
297
  );
298
+
299
+ if ( $wdn_order_billing_id ) {
300
  $fields['billing_email'] = array(
301
  'label' => __( 'Email', 'woocommerce-delivery-notes' ),
302
+ 'value' => $wdn_order_billing_id,
303
  );
304
  }
305
+
306
+ if ( $wdn_order_billing_phone ) {
307
  $fields['billing_phone'] = array(
308
  'label' => __( 'Telephone', 'woocommerce-delivery-notes' ),
309
+ 'value' => $wdn_order_billing_phone,
310
  );
311
  }
312
+
313
  return $fields;
314
  }
315
 
316
  /**
317
  * Get the invoice number of an order
318
+ *
319
+ * @param int $order_id Order ID.
320
  */
321
  function wcdn_get_order_invoice_number( $order_id ) {
322
  global $wcdn;
325
 
326
  /**
327
  * Get the invoice date of an order
328
+ *
329
+ * @param int $order_id Order ID.
330
  */
331
  function wcdn_get_order_invoice_date( $order_id ) {
332
  global $wcdn;
335
 
336
  /**
337
  * Additional fields for the product
338
+ *
339
+ * @param array $fields Fields array.
340
+ * @param object $product Product Object.
341
+ * @param object $order Order object.
342
  */
343
  function wcdn_additional_product_fields( $fields = null, $product = null, $order ) {
344
  $new_fields = array();
345
+
346
+ // Stock keeping unit.
347
+ if ( $product && $product->exists() && $product->get_sku() ) {
348
  $fields['sku'] = array(
349
  'label' => __( 'SKU:', 'woocommerce-delivery-notes' ),
350
+ 'value' => $product->get_sku(),
351
  );
352
+ }
353
  return array_merge( $fields, $new_fields );
354
  }
355
 
356
  /**
357
  * Check if a shipping address is enabled
358
+ *
359
+ * @param object $order Order object.
360
  */
361
  function wcdn_has_shipping_address( $order ) {
362
+ // Works only with WooCommerce 2.2 and higher.
363
+ if ( version_compare( WC_VERSION, '2.2.0', '>=' ) ) {
364
+ if ( ! wc_ship_to_billing_address_only() && $order->needs_shipping_address() && 'no' !== get_option( 'woocommerce_calc_shipping' ) ) {
365
  return true;
366
  } else {
367
  return false;
372
 
373
  /**
374
  * Check if an order contains a refund
375
+ *
376
+ * @param object $order Order object.
377
  */
378
  function wcdn_has_refund( $order ) {
379
+ // Works only with WooCommerce 2.2 and higher.
380
+ if ( version_compare( WC_VERSION, '2.2.0', '>=' ) ) {
381
+ if ( $order->get_total_refunded() ) {
382
  return true;
383
  }
384
  }
387
 
388
  /**
389
  * Gets formatted item subtotal for display.
390
+ *
391
+ * @param object $order Order object.
392
+ * @param array $item Item array.
393
+ * @param string $tax_display Display excluding tax or including.
394
  */
395
  function wcdn_get_formatted_item_price( $order, $item, $tax_display = '' ) {
396
  if ( ! $tax_display ) {
401
  return '';
402
  }
403
 
404
+ $wdn_order_currency = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) ? $order->get_currency() : $order->get_order_currency();
405
+
406
+ if ( 'excl' === $tax_display ) {
407
+ if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) {
408
+ $ex_tax_label = wc_prices_include_tax() ? 1 : 0;
409
+ } else {
410
+ $ex_tax_label = $order->prices_include_tax ? 1 : 0;
411
+ }
412
+
413
+ $subtotal = wc_price(
414
+ $order->get_item_subtotal( $item ),
415
+ array(
416
+ 'ex_tax_label' => $ex_tax_label,
417
+ 'currency' => $wdn_order_currency,
418
+ )
419
+ );
420
  } else {
421
+ $subtotal = wc_price( $order->get_item_subtotal( $item, true ), array( 'currency' => $wdn_order_currency ) );
422
  }
423
 
424
  return apply_filters( 'wcdn_formatted_item_price', $subtotal, $item, $order );
426
 
427
  /**
428
  * Add refund totals
429
+ *
430
+ * @param array $total_rows Rows array.
431
+ * @param object $order Order object.
432
  */
433
+ function wcdn_add_refunded_order_totals( $total_rows, $order ) {
434
+ if ( wcdn_has_refund( $order ) ) {
435
+ $wdn_order_currency = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) ? $order->get_currency() : $order->get_order_currency();
436
 
437
+ if ( version_compare( WC_VERSION, '2.3.0', '>=' ) ) {
438
  $refunded_tax_del = '';
439
  $refunded_tax_ins = '';
440
+
441
+ // Tax for inclusive prices.
442
+ if ( wc_tax_enabled() && 'incl' === get_option( 'woocommerce_tax_display_cart' ) ) {
443
  $tax_del_array = array();
444
  $tax_ins_array = array();
445
+
446
+ if ( 'itemized' === get_option( 'woocommerce_tax_total_display' ) ) {
447
+
448
  foreach ( $order->get_tax_totals() as $code => $tax ) {
449
  $tax_del_array[] = sprintf( '%s %s', $tax->formatted_amount, $tax->label );
450
  $tax_ins_array[] = sprintf( '%s %s', wc_price( $tax->amount - $order->get_total_tax_refunded_by_rate_id( $tax->rate_id ), array( 'currency' => $wdn_order_currency ) ), $tax->label );
451
  }
 
452
  } else {
453
  $tax_del_array[] = sprintf( '%s %s', wc_price( $order->get_total_tax(), array( 'currency' => $wdn_order_currency ) ), WC()->countries->tax_or_vat() );
454
  $tax_ins_array[] = sprintf( '%s %s', wc_price( $order->get_total_tax() - $order->get_total_tax_refunded(), array( 'currency' => $wdn_order_currency ) ), WC()->countries->tax_or_vat() );
455
  }
456
+
457
  if ( ! empty( $tax_del_array ) ) {
458
+ /* translators: %s: Taxes to delete */
459
  $refunded_tax_del .= ' ' . sprintf( __( '(Includes %s)', 'woocommerce' ), implode( ', ', $tax_del_array ) );
460
  }
461
+
462
  if ( ! empty( $tax_ins_array ) ) {
463
+ /* translators: %s: Taxes to insert */
464
  $refunded_tax_ins .= ' ' . sprintf( __( '(Includes %s)', 'woocommerce' ), implode( ', ', $tax_ins_array ) );
465
  }
466
  }
467
+ // use only the number for new wc versions.
468
  $order_subtotal = wc_price( $order->get_total(), array( 'currency' => $wdn_order_currency ) );
469
  } else {
470
  $refunded_tax_del = '';
471
  $refunded_tax_ins = '';
472
+
473
+ // use the normal total for older wc versions.
474
  $order_subtotal = $total_rows['order_total']['value'];
475
+ }
476
+
477
+ // Add refunded totals row.
478
  $total_rows['wcdn_refunded_total'] = array(
479
+ 'label' => __( 'Refund', 'woocommerce-delivery-notes' ),
480
+ 'value' => wc_price( -$order->get_total_refunded(), array( 'currency' => $wdn_order_currency ) ),
481
  );
482
+
483
+ // Add new order totals row.
484
  $total_rows['wcdn_order_total'] = array(
485
+ 'label' => $total_rows['order_total']['label'],
486
+ 'value' => wc_price( $order->get_total() - $order->get_total_refunded(), array( 'currency' => $wdn_order_currency ) ) . $refunded_tax_ins,
487
  );
488
+
489
+ // Edit the original order total row.
490
  $total_rows['order_total'] = array(
491
+ 'label' => __( 'Order Subtotal', 'woocommerce-delivery-notes' ),
492
+ 'value' => $order_subtotal,
493
  );
494
  }
495
+
496
  return $total_rows;
497
  }
498
 
499
  /**
500
+ * Remove the semicolon from the totals
501
+ *
502
+ * @param array $total_rows Rows array.
503
+ * @param object $order Order object.
504
  */
505
+ function wcdn_remove_semicolon_from_totals( $total_rows, $order ) {
506
+ foreach ( $total_rows as $key => $row ) {
507
  $label = $row['label'];
508
  $colon = strrpos( $label, ':' );
509
+ if ( false !== $colon ) {
510
  $label = substr_replace( $label, '', $colon, 1 );
511
+ }
512
+ $total_rows[ $key ]['label'] = $label;
513
  }
514
  return $total_rows;
515
  }
516
 
517
  /**
518
+ * Remove the payment method text from the totals
519
+ *
520
+ * @param array $total_rows Rows array.
521
+ * @param object $order Order object.
522
  */
523
+ function wcdn_remove_payment_method_from_totals( $total_rows, $order ) {
524
+ unset( $total_rows['payment_method'] );
525
  return $total_rows;
526
  }
527
 
528
  /**
529
  * Return customer notes
530
+ *
531
+ * @param object $order Order object.
532
  */
533
  function wcdn_get_customer_notes( $order ) {
534
  global $wcdn;
535
+
536
+ $wdn_order_customer_notes = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) ? $order->get_customer_note() : $order->customer_note;
537
+ return stripslashes( wpautop( wptexturize( $wdn_order_customer_notes ) ) );
538
  }
539
 
540
  /**
541
  * Show customer notes
542
+ *
543
+ * @param object $order Order object.
544
  */
545
  function wcdn_customer_notes( $order ) {
546
  global $wcdn;
547
+ echo wp_kses_post( wcdn_get_customer_notes( $order ) );
548
  }
549
 
550
  /**
551
  * Return has customer notes
552
+ *
553
+ * @param object $order Order object.
554
  */
555
  function wcdn_has_customer_notes( $order ) {
556
  global $wcdn;
557
+ if ( wcdn_get_customer_notes( $order ) ) {
558
  return true;
559
  } else {
560
  return false;
574
  */
575
  function wcdn_personal_notes() {
576
  global $wcdn;
577
+ echo wp_kses_post( wcdn_get_personal_notes() );
578
  }
579
 
580
  /**
590
  */
591
  function wcdn_policies_conditions() {
592
  global $wcdn;
593
+ echo wp_kses_post( wcdn_get_policies_conditions() );
594
  }
595
 
596
  /**
598
  */
599
  function wcdn_get_imprint() {
600
  global $wcdn;
601
+ return wp_kses_post( stripslashes( wpautop( wptexturize( get_option( 'wcdn_footer_imprint' ) ) ) ) );
602
  }
603
 
604
  /**
606
  */
607
  function wcdn_imprint() {
608
  global $wcdn;
609
+ echo wp_kses_post( wcdn_get_imprint() );
610
  }
611
 
612
 
613
+ ?>
includes/wcdn-template-hooks.php CHANGED
@@ -1,26 +1,31 @@
1
  <?php
 
 
 
 
 
2
 
3
  /**
4
  * Exit if accessed directly
5
  */
6
- if ( !defined( 'ABSPATH' ) ) {
7
- exit;
8
  }
9
 
10
- /**
11
  * Header
12
  */
13
  add_action( 'wcdn_head', 'wcdn_navigation_style' );
14
  add_action( 'wcdn_head', 'wcdn_template_stylesheet' );
15
 
16
- /**
17
  * Before page
18
  */
19
  add_action( 'wcdn_before_page', 'wcdn_navigation' );
20
 
21
- /**
22
  * Content
23
  */
24
  add_action( 'wcdn_loop_content', 'wcdn_content', 10, 2 );
25
- add_filter( 'wcdn_order_item_fields', 'wcdn_additional_product_fields', 10, 3);
26
- ?>
1
  <?php
2
+ /**
3
+ * Template Hooks
4
+ *
5
+ * @package woocommerce-print-invoice-delivery-notes
6
+ */
7
 
8
  /**
9
  * Exit if accessed directly
10
  */
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ exit;
13
  }
14
 
15
+ /**
16
  * Header
17
  */
18
  add_action( 'wcdn_head', 'wcdn_navigation_style' );
19
  add_action( 'wcdn_head', 'wcdn_template_stylesheet' );
20
 
21
+ /**
22
  * Before page
23
  */
24
  add_action( 'wcdn_before_page', 'wcdn_navigation' );
25
 
26
+ /**
27
  * Content
28
  */
29
  add_action( 'wcdn_loop_content', 'wcdn_content', 10, 2 );
30
+ add_filter( 'wcdn_order_item_fields', 'wcdn_additional_product_fields', 10, 3 );
31
+
readme.txt CHANGED
@@ -1,12 +1,12 @@
1
  === WooCommerce Print Invoice & Delivery Note ===
2
 
3
- Contributors: ashokrane, bhavik.kiri, tychesoftwares, rashmim
4
  Donate link: https://www.paypal.me/TycheSoftwares
5
  Tags: delivery note, packing slip, pdf invoice, delivery, shipping, print order, woocommerce, woothemes, shop
6
  Requires at least: 4.0
7
- Tested up to: 5.1
8
  Author URI: https://www.tychesoftwares.com/
9
- Stable tag: 4.4.8
10
  License: GPLv3 or later
11
  License URI: http://www.opensource.org/licenses/gpl-license.php
12
 
@@ -328,7 +328,26 @@ Please [contribute your translation](https://github.com/TycheSoftwares/woocommer
328
 
329
  == Changelog ==
330
 
331
- = Minimum Requirements: WooCommerce 2.2 =
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
332
 
333
  = 4.4.8 (02.04.2019) =
334
 
1
  === WooCommerce Print Invoice & Delivery Note ===
2
 
3
+ Contributors: ashokrane, tychesoftwares, rashmim
4
  Donate link: https://www.paypal.me/TycheSoftwares
5
  Tags: delivery note, packing slip, pdf invoice, delivery, shipping, print order, woocommerce, woothemes, shop
6
  Requires at least: 4.0
7
+ Tested up to: 5.2
8
  Author URI: https://www.tychesoftwares.com/
9
+ Stable tag: trunk
10
  License: GPLv3 or later
11
  License URI: http://www.opensource.org/licenses/gpl-license.php
12
 
328
 
329
  == Changelog ==
330
 
331
+ = Minimum Requirements: WooCommerce 3.0 =
332
+
333
+ = 4.5.2 (23.08.2019) =
334
+
335
+ * Fixed the issue of Print buttons not working on PHP versions below 7.0.
336
+
337
+ = 4.5.1 (21.08.2019) =
338
+
339
+ * Fixed the issue of Print buttons not showing up on Order details page after the 4.4.9 update.
340
+
341
+ = 4.5.0 (21.08.2019) =
342
+
343
+ * Added a missing file from v4.4.9.
344
+
345
+ = 4.4.9 (21.08.2019) =
346
+
347
+ * Made the plugin code compliant with WPCS coding standards
348
+ * Added filter wcdn_theme_print_button_template_type_arbitrary - this filter hook allows to change template type based on order status
349
+ * Added filters wcdn_print_button_name_on_my_account_page, wcdn_print_button_name_order_page - these filter hooks allows to change the label of the Print button
350
+ * When plugin is uninstalled, data cleanup wasn't happening. This has been fixed.
351
 
352
  = 4.4.8 (02.04.2019) =
353
 
templates/print-order/print-content.php CHANGED
@@ -1,244 +1,266 @@
1
- <?php
2
- /**
3
- * Print order content. Copy this file to your themes
4
- * directory /woocommerce/print-order to customize it.
5
- *
6
- * @package WooCommerce Print Invoice & Delivery Note/Templates
7
- */
8
-
9
- if ( !defined( 'ABSPATH' ) ) exit;
10
- ?>
11
-
12
- <div class="order-branding">
13
- <div class="company-logo">
14
- <?php if( wcdn_get_company_logo_id() ) : ?><?php wcdn_company_logo(); ?><?php endif; ?>
15
- </div>
16
-
17
- <div class="company-info">
18
- <?php if( !wcdn_get_company_logo_id() ) : ?><h1 class="company-name"><?php wcdn_company_name(); ?></h1><?php endif; ?>
19
- <div class="company-address"><?php wcdn_company_info(); ?></div>
20
- </div>
21
-
22
- <?php do_action( 'wcdn_after_branding', $order ); ?>
23
- </div><!-- .order-branding -->
24
-
25
-
26
- <div class="order-addresses<?php if( !wcdn_has_shipping_address( $order ) ) : ?> no-shipping-address<?php endif; ?>">
27
- <div class="billing-address">
28
- <h3><?php _e( 'Billing Address', 'woocommerce-delivery-notes' ); ?></h3>
29
- <address>
30
-
31
- <?php if( !$order->get_formatted_billing_address() ) _e( 'N/A', 'woocommerce-delivery-notes' ); else echo apply_filters( 'wcdn_address_billing', $order->get_formatted_billing_address(), $order ); ?>
32
-
33
- </address>
34
- </div>
35
-
36
- <div class="shipping-address">
37
- <h3><?php _e( 'Shipping Address', 'woocommerce-delivery-notes' ); ?></h3>
38
- <address>
39
-
40
- <?php if( !$order->get_formatted_shipping_address() ) _e( 'N/A', 'woocommerce-delivery-notes' ); else echo apply_filters( 'wcdn_address_shipping', $order->get_formatted_shipping_address(), $order ); ?>
41
-
42
- </address>
43
- </div>
44
-
45
- <?php do_action( 'wcdn_after_addresses', $order ); ?>
46
- </div><!-- .order-addresses -->
47
-
48
-
49
- <div class="order-info">
50
- <h2><?php wcdn_document_title(); ?></h2>
51
-
52
- <ul class="info-list">
53
- <?php $fields = apply_filters( 'wcdn_order_info_fields', wcdn_get_order_info( $order ), $order );
54
- ?>
55
- <?php foreach( $fields as $field ) : ?>
56
- <li>
57
- <strong><?php echo apply_filters( 'wcdn_order_info_name', $field['label'], $field ); ?></strong>
58
- <span><?php echo apply_filters( 'wcdn_order_info_content', $field['value'], $field ); ?></span>
59
- </li>
60
- <?php endforeach; ?>
61
- </ul>
62
-
63
- <?php do_action( 'wcdn_after_info', $order ); ?>
64
- </div><!-- .order-info -->
65
-
66
-
67
- <div class="order-items">
68
- <table>
69
- <thead>
70
- <tr>
71
- <th class="head-name"><span><?php _e('Product', 'woocommerce-delivery-notes'); ?></span></th>
72
- <th class="head-item-price"><span><?php _e('Price', 'woocommerce-delivery-notes'); ?></span></th>
73
- <th class="head-quantity"><span><?php _e('Quantity', 'woocommerce-delivery-notes'); ?></span></th>
74
- <th class="head-price"><span><?php _e('Total', 'woocommerce-delivery-notes'); ?></span></th>
75
- </tr>
76
- </thead>
77
-
78
- <tbody>
79
- <?php
80
-
81
- if( sizeof( $order->get_items() ) > 0 ) : ?>
82
- <?php foreach( $order->get_items() as $item ) : ?>
83
-
84
- <?php
85
- $product = apply_filters( 'wcdn_order_item_product', $order->get_product_from_item( $item ), $item );
86
-
87
- if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) {
88
- $item_meta = new WC_Order_Item_Product( $item['item_meta'], $product );
89
- }else{
90
- $item_meta = new WC_Order_Item_Meta( $item['item_meta'], $product );
91
- }
92
- ?>
93
- <tr>
94
- <td class="product-name">
95
- <?php do_action( 'wcdn_order_item_before', $product, $order ); ?>
96
- <span class="name">
97
- <?php
98
-
99
- $addon_name = $item->get_meta( '_wc_pao_addon_name', true );
100
- $addon_value = $item->get_meta( '_wc_pao_addon_value', true );
101
- $is_addon = ! empty( $addon_value );
102
-
103
- if ( $is_addon ) { // Displaying options of product addon
104
- $addon_html = '<div class="wc-pao-order-item-name">' . esc_html( $addon_name ) . '</div><div class="wc-pao-order-item-value">' . esc_html( $addon_value ) . '</div></div>';
105
-
106
- echo $addon_html;
107
- } else {
108
-
109
- $product_id = $item['product_id'];
110
- $prod_name = get_post( $product_id );
111
- $product_name = $prod_name->post_title;
112
-
113
-
114
- echo apply_filters( 'wcdn_order_item_name', $product_name, $item ); ?></span>
115
-
116
- <?php
117
- // if ( version_compare( get_option( 'woocommerce_version' ), '3.1.0', ">=" ) ) {
118
- // $item_meta->get_product();
119
-
120
- // }else {
121
-
122
- // $item_meta->display();
123
- // }
124
-
125
- if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) {
126
- if( isset( $item[ 'variation_id' ] ) && $item[ 'variation_id' ] != 0 ) {
127
- $variation = wc_get_product( $item[ 'product_id' ] );
128
- foreach ( $item[ 'item_meta' ] as $key => $value ) {
129
- if( !( 0 === strpos($key, '_' ) ) ) {
130
- if( is_array( $value ) ){
131
- continue;
132
- }
133
- $term = get_term_by( 'slug', $value, $key );
134
- $attribute_name = wc_attribute_label( $key, $variation );
135
- if( isset( $term->name ) ) {
136
- echo '<br>'.$attribute_name.':'.$term->name;
137
- } else {
138
- echo '<br>'.$attribute_name.':'.$value;
139
- }
140
- }
141
- }
142
- } else {
143
- foreach ( $item[ 'item_meta' ] as $key => $value ) {
144
- if( !( 0 === strpos( $key, '_' ) ) ) {
145
- if( is_array( $value ) ){
146
- continue;
147
- }
148
- echo '<br>' . $key . ':' . $value;
149
- }
150
- }
151
- }
152
- } else {
153
- $item_meta_new = new WC_Order_Item_Meta( $item['item_meta'], $product );
154
- $item_meta_new->display( );
155
-
156
- }
157
- ?>
158
- <br>
159
- <dl class="extras">
160
- <?php if( $product && $product->exists() && $product->is_downloadable() && $order->is_download_permitted() ) : ?>
161
-
162
- <dt><?php _e( 'Download:', 'woocommerce-delivery-notes' ); ?></dt>
163
- <dd><?php printf( __( '%s Files', 'woocommerce-delivery-notes' ), count( $item->get_item_downloads() ) ); ?></dd>
164
-
165
- <?php endif; ?>
166
-
167
- <?php
168
-
169
- $fields = apply_filters( 'wcdn_order_item_fields', array(), $product, $order );
170
-
171
- foreach ( $fields as $field ) :
172
- ?>
173
-
174
- <dt><?php echo $field['label']; ?></dt>
175
- <dd><?php echo $field['value']; ?></dd>
176
-
177
- <?php endforeach; ?>
178
- </dl>
179
- <?php } ?>
180
- </td>
181
- <td class="product-item-price">
182
- <span><?php echo wcdn_get_formatted_item_price( $order, $item ); ?></span>
183
- </td>
184
- <td class="product-quantity">
185
- <span><?php echo apply_filters( 'wcdn_order_item_quantity', $item['qty'], $item ); ?></span>
186
- </td>
187
- <td class="product-price">
188
- <span><?php echo $order->get_formatted_line_subtotal( $item ); ?></span>
189
- </td>
190
- </tr>
191
- <?php endforeach; ?>
192
- <?php endif; ?>
193
- </tbody>
194
-
195
- <tfoot>
196
- <?php if( $totals = $order->get_order_item_totals() ) : ?>
197
- <?php
198
-
199
-
200
- foreach( $totals as $total ) : ?>
201
- <tr>
202
- <td class="total-name"><span><?php echo $total['label']; ?></span></td>
203
- <td class="total-item-price"></td>
204
- <td class="total-quantity"></td>
205
- <td class="total-price"><span><?php echo $total['value']; ?></span></td>
206
- </tr>
207
- <?php endforeach; ?>
208
- <?php endif; ?>
209
- </tfoot>
210
- </table>
211
-
212
- <?php do_action( 'wcdn_after_items', $order ); ?>
213
- </div><!-- .order-items -->
214
-
215
-
216
- <div class="order-notes">
217
- <?php if( wcdn_has_customer_notes( $order ) ) : ?>
218
- <h4><?php _e( 'Customer Note', 'woocommerce-delivery-notes' ); ?></h4>
219
- <?php wcdn_customer_notes( $order ); ?>
220
- <?php endif; ?>
221
-
222
- <?php do_action( 'wcdn_after_notes', $order ); ?>
223
- </div><!-- .order-notes -->
224
-
225
-
226
- <div class="order-thanks">
227
- <?php wcdn_personal_notes(); ?>
228
-
229
- <?php do_action( 'wcdn_after_thanks', $order ); ?>
230
- </div><!-- .order-thanks -->
231
-
232
-
233
- <div class="order-colophon">
234
- <div class="colophon-policies">
235
- <?php wcdn_policies_conditions(); ?>
236
- </div>
237
-
238
- <div class="colophon-imprint">
239
- <?php wcdn_imprint(); ?>
240
- </div>
241
-
242
- <?php do_action( 'wcdn_after_colophon', $order ); ?>
243
- </div><!-- .order-colophon -->
244
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Print order content. Copy this file to your themes
4
+ * directory /woocommerce/print-order to customize it.
5
+ *
6
+ * @package WooCommerce Print Invoice & Delivery Note/Templates
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+ ?>
13
+
14
+ <div class="order-branding">
15
+ <div class="company-logo">
16
+ <?php
17
+ if ( wcdn_get_company_logo_id() ) :
18
+ ?>
19
+ <?php wcdn_company_logo(); ?><?php endif; ?>
20
+ </div>
21
+
22
+ <div class="company-info">
23
+ <?php
24
+ if ( ! wcdn_get_company_logo_id() ) :
25
+ ?>
26
+ <h1 class="company-name"><?php wcdn_company_name(); ?></h1><?php endif; ?>
27
+ <div class="company-address"><?php wcdn_company_info(); ?></div>
28
+ </div>
29
+
30
+ <?php do_action( 'wcdn_after_branding', $order ); ?>
31
+ </div><!-- .order-branding -->
32
+
33
+ <div class="order-addresses
34
+ <?php
35
+ if ( ! wcdn_has_shipping_address( $order ) ) :
36
+ ?>
37
+ no-shipping-address<?php endif; ?>">
38
+ <div class="billing-address">
39
+ <h3><?php esc_attr_e( 'Billing Address', 'woocommerce-delivery-notes' ); ?></h3>
40
+ <address>
41
+
42
+ <?php
43
+ if ( ! $order->get_formatted_billing_address() ) {
44
+ esc_attr_e( 'N/A', 'woocommerce-delivery-notes' );
45
+ } else {
46
+ echo wp_kses_post( apply_filters( 'wcdn_address_billing', $order->get_formatted_billing_address(), $order ) );
47
+ }
48
+ ?>
49
+
50
+ </address>
51
+ </div>
52
+
53
+ <div class="shipping-address">
54
+ <h3><?php esc_attr_e( 'Shipping Address', 'woocommerce-delivery-notes' ); ?></h3>
55
+ <address>
56
+
57
+ <?php
58
+ if ( ! $order->get_formatted_shipping_address() ) {
59
+ esc_attr_e( 'N/A', 'woocommerce-delivery-notes' );
60
+ } else {
61
+ echo wp_kses_post( apply_filters( 'wcdn_address_shipping', $order->get_formatted_shipping_address(), $order ) );
62
+ }
63
+ ?>
64
+
65
+ </address>
66
+ </div>
67
+
68
+ <?php do_action( 'wcdn_after_addresses', $order ); ?>
69
+ </div><!-- .order-addresses -->
70
+
71
+
72
+ <div class="order-info">
73
+ <h2><?php wcdn_document_title(); ?></h2>
74
+
75
+ <ul class="info-list">
76
+ <?php
77
+ $fields = apply_filters( 'wcdn_order_info_fields', wcdn_get_order_info( $order ), $order );
78
+ ?>
79
+ <?php foreach ( $fields as $field ) : ?>
80
+ <li>
81
+ <strong><?php echo wp_kses_post( apply_filters( 'wcdn_order_info_name', $field['label'], $field ) ); ?></strong>
82
+ <span><?php echo wp_kses_post( apply_filters( 'wcdn_order_info_content', $field['value'], $field ) ); ?></span>
83
+ </li>
84
+ <?php endforeach; ?>
85
+ </ul>
86
+
87
+ <?php do_action( 'wcdn_after_info', $order ); ?>
88
+ </div><!-- .order-info -->
89
+
90
+
91
+ <div class="order-items">
92
+ <table>
93
+ <thead>
94
+ <tr>
95
+ <th class="head-name"><span><?php esc_attr_e( 'Product', 'woocommerce-delivery-notes' ); ?></span></th>
96
+ <th class="head-item-price"><span><?php esc_attr_e( 'Price', 'woocommerce-delivery-notes' ); ?></span></th>
97
+ <th class="head-quantity"><span><?php esc_attr_e( 'Quantity', 'woocommerce-delivery-notes' ); ?></span></th>
98
+ <th class="head-price"><span><?php esc_attr_e( 'Total', 'woocommerce-delivery-notes' ); ?></span></th>
99
+ </tr>
100
+ </thead>
101
+
102
+ <tbody>
103
+ <?php
104
+
105
+ if ( count( $order->get_items() ) > 0 ) :
106
+ ?>
107
+ <?php foreach ( $order->get_items() as $item ) : ?>
108
+
109
+ <?php
110
+ $product = apply_filters( 'wcdn_order_item_product', $order->get_product_from_item( $item ), $item );
111
+
112
+ if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) {
113
+ $item_meta = new WC_Order_Item_Product( $item['item_meta'], $product );
114
+ } else {
115
+ $item_meta = new WC_Order_Item_Meta( $item['item_meta'], $product );
116
+ }
117
+ ?>
118
+ <tr>
119
+ <td class="product-name">
120
+ <?php do_action( 'wcdn_order_item_before', $product, $order ); ?>
121
+ <span class="name">
122
+ <?php
123
+
124
+ $addon_name = $item->get_meta( '_wc_pao_addon_name', true );
125
+ $addon_value = $item->get_meta( '_wc_pao_addon_value', true );
126
+ $is_addon = ! empty( $addon_value );
127
+
128
+ if ( $is_addon ) { // Displaying options of product addon.
129
+ $addon_html = '<div class="wc-pao-order-item-name">' . esc_html( $addon_name ) . '</div><div class="wc-pao-order-item-value">' . esc_html( $addon_value ) . '</div></div>';
130
+
131
+ echo wp_kses_post( $addon_html );
132
+ } else {
133
+
134
+ $product_id = $item['product_id'];
135
+ $prod_name = get_post( $product_id );
136
+ $product_name = $prod_name->post_title;
137
+
138
+ echo wp_kses_post( apply_filters( 'wcdn_order_item_name', $product_name, $item ) );
139
+ ?>
140
+ </span>
141
+
142
+ <?php
143
+
144
+ if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) {
145
+ if ( isset( $item['variation_id'] ) && 0 !== $item['variation_id'] ) {
146
+ $variation = wc_get_product( $item['product_id'] );
147
+ foreach ( $item['item_meta'] as $key => $value ) {
148
+ if ( ! ( 0 === strpos( $key, '_' ) ) ) {
149
+ if ( is_array( $value ) ) {
150
+ continue;
151
+ }
152
+ $term_wp = get_term_by( 'slug', $value, $key );
153
+ $attribute_name = wc_attribute_label( $key, $variation );
154
+ if ( isset( $term_wp->name ) ) {
155
+ echo '<br>' . wp_kses_post( $attribute_name . ':' . $term_wp->name );
156
+ } else {
157
+ echo '<br>' . wp_kses_post( $attribute_name . ':' . $value );
158
+ }
159
+ }
160
+ }
161
+ } else {
162
+ foreach ( $item['item_meta'] as $key => $value ) {
163
+ if ( ! ( 0 === strpos( $key, '_' ) ) ) {
164
+ if ( is_array( $value ) ) {
165
+ continue;
166
+ }
167
+ echo '<br>' . wp_kses_post( $key . ':' . $value );
168
+ }
169
+ }
170
+ }
171
+ } else {
172
+ $item_meta_new = new WC_Order_Item_Meta( $item['item_meta'], $product );
173
+ $item_meta_new->display();
174
+
175
+ }
176
+ ?>
177
+ <br>
178
+ <dl class="extras">
179
+ <?php if ( $product && $product->exists() && $product->is_downloadable() && $order->is_download_permitted() ) : ?>
180
+
181
+ <dt><?php esc_attr_e( 'Download:', 'woocommerce-delivery-notes' ); ?></dt>
182
+ <dd>
183
+ <?php
184
+ // translators: files count.
185
+ printf( esc_attr_e( '%s Files', 'woocommerce-delivery-notes' ), count( $item->get_item_downloads() ) );
186
+ ?>
187
+ </dd>
188
+
189
+ <?php endif; ?>
190
+
191
+ <?php
192
+
193
+ $fields = apply_filters( 'wcdn_order_item_fields', array(), $product, $order );
194
+
195
+ foreach ( $fields as $field ) :
196
+ ?>
197
+
198
+ <dt><?php echo esc_html( $field['label'] ); ?></dt>
199
+ <dd><?php echo esc_html( $field['value'] ); ?></dd>
200
+
201
+ <?php endforeach; ?>
202
+ </dl>
203
+ <?php } ?>
204
+ </td>
205
+ <td class="product-item-price">
206
+ <span><?php echo wp_kses_post( wcdn_get_formatted_item_price( $order, $item ) ); ?></span>
207
+ </td>
208
+ <td class="product-quantity">
209
+ <span><?php echo esc_attr( apply_filters( 'wcdn_order_item_quantity', $item['qty'], $item ) ); ?></span>
210
+ </td>
211
+ <td class="product-price">
212
+ <span><?php echo wp_kses_post( $order->get_formatted_line_subtotal( $item ) ); ?></span>
213
+ </td>
214
+ </tr>
215
+ <?php endforeach; ?>
216
+ <?php endif; ?>
217
+ </tbody>
218
+
219
+ <tfoot>
220
+ <?php
221
+ $totals_arr = $order->get_order_item_totals();
222
+ if ( $totals_arr ) :
223
+
224
+ foreach ( $totals_arr as $total ) :
225
+ ?>
226
+ <tr>
227
+ <td class="total-name"><span><?php echo wp_kses_post( $total['label'] ); ?></span></td>
228
+ <td class="total-item-price"></td>
229
+ <td class="total-quantity"></td>
230
+ <td class="total-price"><span><?php echo wp_kses_post( $total['value'] ); ?></span></td>
231
+ </tr>
232
+ <?php endforeach; ?>
233
+ <?php endif; ?>
234
+ </tfoot>
235
+ </table>
236
+
237
+ <?php do_action( 'wcdn_after_items', $order ); ?>
238
+ </div><!-- .order-items -->
239
+
240
+ <div class="order-notes">
241
+ <?php if ( wcdn_has_customer_notes( $order ) ) : ?>
242
+ <h4><?php esc_attr_e( 'Customer Note', 'woocommerce-delivery-notes' ); ?></h4>
243
+ <?php wcdn_customer_notes( $order ); ?>
244
+ <?php endif; ?>
245
+
246
+ <?php do_action( 'wcdn_after_notes', $order ); ?>
247
+ </div><!-- .order-notes -->
248
+
249
+ <div class="order-thanks">
250
+ <?php wcdn_personal_notes(); ?>
251
+
252
+ <?php do_action( 'wcdn_after_thanks', $order ); ?>
253
+ </div><!-- .order-thanks -->
254
+
255
+ <div class="order-colophon">
256
+ <div class="colophon-policies">
257
+ <?php wcdn_policies_conditions(); ?>
258
+ </div>
259
+
260
+ <div class="colophon-imprint">
261
+ <?php wcdn_imprint(); ?>
262
+ </div>
263
+
264
+ <?php do_action( 'wcdn_after_colophon', $order ); ?>
265
+ </div><!-- .order-colophon -->
266
+
templates/print-order/print-footer.php CHANGED
@@ -5,18 +5,19 @@
5
  * @package WooCommerce Print Invoice & Delivery Note/Templates
6
  */
7
 
8
- if ( !defined( 'ABSPATH' ) ) exit;
 
 
9
  ?>
10
 
11
  </div><!-- #page -->
12
-
13
  <?php
14
- // wcdn_head hook
15
  do_action( 'wcdn_after_page' );
16
  ?>
17
-
18
  </div><!-- #container -->
19
 
20
  </body>
21
-
22
- </html>
5
  * @package WooCommerce Print Invoice & Delivery Note/Templates
6
  */
7
 
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
  ?>
12
 
13
  </div><!-- #page -->
14
+
15
  <?php
16
+ // wcdn_head hook.
17
  do_action( 'wcdn_after_page' );
18
  ?>
19
+
20
  </div><!-- #container -->
21
 
22
  </body>
23
+ </html>
 
templates/print-order/print-header.php CHANGED
@@ -4,8 +4,10 @@
4
  *
5
  * @package WooCommerce Print Invoice & Delivery Note/Templates
6
  */
7
-
8
- if ( !defined( 'ABSPATH' ) ) exit;
 
 
9
  ?>
10
 
11
  <!DOCTYPE html>
@@ -14,20 +16,20 @@ if ( !defined( 'ABSPATH' ) ) exit;
14
  <head>
15
  <meta charset="utf-8">
16
  <title><?php wcdn_document_title(); ?></title>
17
-
18
  <?php
19
- // wcdn_head hook
20
  do_action( 'wcdn_head' );
21
  ?>
22
  </head>
23
 
24
- <body class="<?php echo wcdn_get_template_type(); ?>">
25
-
26
  <div id="container">
27
-
28
  <?php
29
- // wcdn_head hook
30
  do_action( 'wcdn_before_page' );
31
  ?>
32
-
33
- <div id="page">
4
  *
5
  * @package WooCommerce Print Invoice & Delivery Note/Templates
6
  */
7
+
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
  ?>
12
 
13
  <!DOCTYPE html>
16
  <head>
17
  <meta charset="utf-8">
18
  <title><?php wcdn_document_title(); ?></title>
19
+
20
  <?php
21
+ // wcdn_head hook.
22
  do_action( 'wcdn_head' );
23
  ?>
24
  </head>
25
 
26
+ <body class="<?php echo esc_attr( wcdn_get_template_type() ); ?>">
27
+
28
  <div id="container">
29
+
30
  <?php
31
+ // wcdn_head hook.
32
  do_action( 'wcdn_before_page' );
33
  ?>
34
+
35
+ <div id="page">
templates/print-order/print-order.php CHANGED
@@ -1,59 +1,64 @@
1
  <?php
2
  /**
3
- * Print order template. This is the main file. Most
4
  * probably it is easier to edit one of the content by
5
  * copying it to your theme /woocommerce/print
6
  *
7
  * @package WooCommerce Print Invoice & Delivery Note/Templates
8
  */
9
 
10
- if ( !defined( 'ABSPATH' ) ) exit;
 
 
11
  ?>
12
 
13
  <?php
14
- // wcdn_before_template hook
15
  do_action( 'wcdn_before_template' );
16
- ?>
17
 
18
  <?php wcdn_get_template_content( 'print-header.php' ); ?>
19
 
20
  <?php
21
- // wcdn_before_content hook
22
  do_action( 'wcdn_before_content' );
23
- ?>
24
-
25
- <?php if( $orders = wcdn_get_orders() ) : ?>
26
-
 
 
 
27
  <?php
28
- // wcdn_before_loop hook
29
  do_action( 'wcdn_before_loop' );
30
  ?>
31
-
32
- <?php foreach( $orders as $order ) : ?>
33
-
34
  <article class="content">
35
-
36
- <?php do_action( 'wcdn_loop_content', $order, wcdn_get_template_type() ); ?>
37
 
38
  </article><!-- .content -->
39
-
40
  <?php endforeach; ?>
41
 
42
  <?php
43
- // wcdn_after_loop hook
44
  do_action( 'wcdn_after_loop' );
45
  ?>
46
-
47
  <?php endif; ?>
48
-
49
  <?php
50
- // wcdn_after_content hook
51
  do_action( 'wcdn_after_content' );
52
  ?>
53
 
54
  <?php wcdn_get_template_content( 'print-footer.php' ); ?>
55
 
56
  <?php
57
- // wcdn_after_template hook
58
  do_action( 'wcdn_after_template' );
59
- ?>
1
  <?php
2
  /**
3
+ * Print order template. This is the main file. Most
4
  * probably it is easier to edit one of the content by
5
  * copying it to your theme /woocommerce/print
6
  *
7
  * @package WooCommerce Print Invoice & Delivery Note/Templates
8
  */
9
 
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
  ?>
14
 
15
  <?php
16
+ // wcdn_before_template hook.
17
  do_action( 'wcdn_before_template' );
18
+ ?>
19
 
20
  <?php wcdn_get_template_content( 'print-header.php' ); ?>
21
 
22
  <?php
23
+ // wcdn_before_content hook.
24
  do_action( 'wcdn_before_content' );
25
+ ?>
26
+
27
+ <?php
28
+ $orders = wcdn_get_orders();
29
+ if ( $orders ) :
30
+ ?>
31
+
32
  <?php
33
+ // wcdn_before_loop hook.
34
  do_action( 'wcdn_before_loop' );
35
  ?>
36
+
37
+ <?php foreach ( $orders as $order_obj ) : ?>
38
+
39
  <article class="content">
40
+
41
+ <?php do_action( 'wcdn_loop_content', $order_obj, wcdn_get_template_type() ); ?>
42
 
43
  </article><!-- .content -->
44
+
45
  <?php endforeach; ?>
46
 
47
  <?php
48
+ // wcdn_after_loop hook.
49
  do_action( 'wcdn_after_loop' );
50
  ?>
51
+
52
  <?php endif; ?>
53
+
54
  <?php
55
+ // wcdn_after_content hook.
56
  do_action( 'wcdn_after_content' );
57
  ?>
58
 
59
  <?php wcdn_get_template_content( 'print-footer.php' ); ?>
60
 
61
  <?php
62
+ // wcdn_after_template hook.
63
  do_action( 'wcdn_after_template' );
64
+ ?>
uninstall.php CHANGED
@@ -4,27 +4,48 @@
4
  *
5
  * Uninstalling WooCommerce Print Invoice & Delivery Note options.
6
  *
 
7
  */
8
 
9
  if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
10
- exit;
11
  }
12
 
13
- /**
14
- * Delete the data for the WordPress Multisite.
15
- */
16
- global $wpdb;
17
-
18
- if ( is_multisite() ) {
19
- $sql_table_user_meta_cart = "DELETE FROM `" . $wpdb->prefix . "usermeta` WHERE meta_key LIKE '%wcdn_%'";
20
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
21
- $wpdb->get_results( $sql_table_user_meta_cart );
22
-
23
- } else {
24
-
25
- $sql_table_user_meta_cart = "DELETE FROM `" . $wpdb->prefix . "usermeta` WHERE meta_key LIKE '%wcdn_%'";
26
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
27
- $wpdb->get_results( $sql_table_user_meta_cart );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  }
29
-
30
- wp_cache_flush();
4
  *
5
  * Uninstalling WooCommerce Print Invoice & Delivery Note options.
6
  *
7
+ * @package woocommerce-print-invoice-delivery-notes
8
  */
9
 
10
  if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
11
+ exit;
12
  }
13
 
14
+ // Generatl information.
15
+ delete_option( 'wcdn_company_address ' );
16
+ delete_option( 'wcdn_company_logo_image_id' );
17
+ delete_option( 'wcdn_custom_company_name' );
18
+ delete_option( 'wcdn_personal_notes' );
19
+ delete_option( 'wcdn_policies_conditions' );
20
+
21
+ // Behaviour.
22
+ delete_option( 'wcdn_email_print_link' );
23
+ delete_option( 'wcdn_footer_imprint' );
24
+
25
+ // Invoice number generation.
26
+ delete_option( 'wcdn_create_invoice_number' );
27
+ delete_option( 'wcdn_invoice_number_count' );
28
+ delete_option( 'wcdn_invoice_number_prefix' );
29
+ delete_option( 'wcdn_invoice_number_suffix' );
30
+
31
+ // Customer view options.
32
+ delete_option( 'wcdn_print_button_on_my_account_page' );
33
+ delete_option( 'wcdn_print_button_on_view_order_page' );
34
+ delete_option( 'wcdn_print_order_page_endpoint' );
35
+
36
+ // Template options.
37
+ delete_option( 'wcdn_template_style' );
38
+ delete_option( 'wcdn_template_type_delivery-note' );
39
+ delete_option( 'wcdn_template_type_invoice' );
40
+ delete_option( 'wcdn_template_type_receipt' );
41
+
42
+ // Tracking options.
43
+ delete_option( 'wcdn_allow_tracking' );
44
+ delete_option( 'wcdn_ts_tracker_last_send' );
45
+ delete_option( 'wcdn_version' );
46
+
47
+ // Delete transient added for new endpoint.
48
+ if ( '1' === get_transient( 'wcdn_flush_rewrite_rules' ) ) {
49
+ delete_transient( 'wcdn_flush_rewrite_rules' );
50
+ flush_rewrite_rules();
51
  }
 
 
woocommerce-delivery-notes.php CHANGED
@@ -4,8 +4,8 @@
4
  *
5
  * Plugin Name: WooCommerce Print Invoice & Delivery Note
6
  * Plugin URI: https://www.tychesoftwares.com/
7
- * Description: Print Invoices & Delivery Notes for WooCommerce Orders.
8
- * Version: 4.4.8
9
  * Author: Tyche Softwares
10
  * Author URI: https://www.tychesoftwares.com/
11
  * License: GPLv3 or later
@@ -14,10 +14,11 @@
14
  * Domain Path: /languages
15
  * Requires PHP: 5.6
16
  * WC requires at least: 3.0.0
17
- * WC tested up to: 3.5.7
 
 
 
18
  *
19
- * Copyright 2015 Tyche Softwares
20
- *
21
  * This file is part of WooCommerce Print Invoices & Delivery Notes,
22
  * a plugin for WordPress.
23
  *
@@ -34,353 +35,23 @@
34
  *
35
  * You should have received a copy of the GNU General Public License
36
  * along with WordPress. If not, see <http://www.gnu.org/licenses/>.
 
 
37
  */
38
 
39
-
40
  /**
41
  * Exit if accessed directly
42
  */
43
- if ( !defined( 'ABSPATH' ) ) {
44
- exit;
45
  }
46
 
47
- /**
48
- * Base class
49
- */
50
- if ( !class_exists( 'WooCommerce_Delivery_Notes' ) ) {
51
  /**
52
- * WooCommerce Delivery Notes
53
- *
54
- * @author Tyche Softwares
55
- * @package WooCommerce-Delivery-Notes
56
  */
57
- final class WooCommerce_Delivery_Notes {
58
-
59
- /**
60
- * The single instance of the class
61
- */
62
- protected static $_instance = null;
63
-
64
- /**
65
- * Default properties
66
- */
67
- public static $plugin_version = '4.4.8';
68
- public static $plugin_url;
69
- public static $plugin_path;
70
- public static $plugin_basefile;
71
- public static $plugin_basefile_path;
72
- public static $plugin_text_domain;
73
-
74
- /**
75
- * Sub class instances
76
- */
77
- public $writepanel;
78
- public $settings;
79
- public $print;
80
- public $theme;
81
-
82
- /**
83
- * Main Instance
84
- */
85
- public static function instance() {
86
- if( is_null( self::$_instance ) ) {
87
- self::$_instance = new self();
88
- }
89
- return self::$_instance;
90
- }
91
-
92
- /**
93
- * Cloning is forbidden
94
- */
95
- public function __clone() {
96
- _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'woocommerce-delivery-notes' ), '4.1' );
97
- }
98
-
99
- /**
100
- * Unserializing instances of this class is forbidden
101
- */
102
- public function __wakeup() {
103
- _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'woocommerce-delivery-notes' ), '4.1' );
104
- }
105
-
106
- /**
107
- * Constructor
108
- */
109
- public function __construct() {
110
- $this->define_constants();
111
- $this->init_hooks();
112
-
113
- // Send out the load action
114
- do_action( 'wcdn_load');
115
- }
116
-
117
- /**
118
- * Hook into actions and filters
119
- */
120
- public function init_hooks() {
121
- add_action( 'init', array( $this, 'localise' ) );
122
- add_action( 'woocommerce_init', array( $this, 'load' ) );
123
-
124
- }
125
-
126
- /**
127
- * Define WC Constants
128
- */
129
- private function define_constants() {
130
- self::$plugin_basefile_path = __FILE__;
131
- self::$plugin_basefile = plugin_basename( self::$plugin_basefile_path );
132
- self::$plugin_url = plugin_dir_url( self::$plugin_basefile );
133
- self::$plugin_path = trailingslashit( dirname( self::$plugin_basefile_path ) );
134
- self::$plugin_text_domain = trim( dirname( self::$plugin_basefile ) );
135
- }
136
-
137
- /**
138
- * Define constant if not already set
139
- */
140
- private function define( $name, $value ) {
141
-
142
- if( !defined( $name ) ) {
143
- define( $name, $value );
144
- }
145
- }
146
-
147
- /**
148
- * Include the main plugin classes and functions
149
- */
150
- public function include_classes() {
151
- include_once( 'includes/class-wcdn-print.php' );
152
- include_once( 'includes/class-wcdn-settings.php' );
153
- include_once( 'includes/class-wcdn-writepanel.php' );
154
- include_once( 'includes/class-wcdn-theme.php' );
155
- if ( true === is_admin() ) {
156
- include_once( 'includes/wcdn-all-component.php' );
157
- }
158
- }
159
-
160
- /**
161
- * Function used to init Template Functions.
162
- * This makes them pluggable by plugins and themes.
163
- */
164
- public function include_template_functions() {
165
- include_once( 'includes/wcdn-template-functions.php' );
166
- include_once( 'includes/wcdn-template-hooks.php' );
167
- }
168
-
169
- /**
170
- * Load the localisation
171
- */
172
- public function localise() {
173
- // Load language files from the wp-content/languages/plugins folder
174
- $mo_file = WP_LANG_DIR . '/plugins/' . self::$plugin_text_domain . '-' . get_locale() . '.mo';
175
- if( is_readable( $mo_file ) ) {
176
- load_textdomain( self::$plugin_text_domain, $mo_file );
177
- }
178
-
179
- // Otherwise load them from the plugin folder
180
- load_plugin_textdomain( self::$plugin_text_domain, false, dirname( self::$plugin_basefile ) . '/languages/' );
181
- }
182
-
183
- /**
184
- * Load the main plugin classes and functions
185
- */
186
- public function load() {
187
- // WooCommerce activation required
188
- if ( $this->is_woocommerce_activated() ) {
189
- // Include the classes
190
- $this->include_classes();
191
-
192
- // Create the instances
193
- $this->print = new WooCommerce_Delivery_Notes_Print();
194
- $this->settings = new WooCommerce_Delivery_Notes_Settings();
195
- $this->writepanel = new WooCommerce_Delivery_Notes_Writepanel();
196
- $this->theme = new WooCommerce_Delivery_Notes_Theme();
197
-
198
- // Load the hooks for the template after the objetcs.
199
- // Like this the template has full access to all objects.
200
- add_filter( 'plugin_action_links_' . self::$plugin_basefile, array( $this, 'add_settings_link') );
201
- add_action( 'admin_init', array( $this, 'update' ) );
202
- add_action( 'init', array( $this, 'include_template_functions' ) );
203
-
204
- add_filter( 'ts_deativate_plugin_questions', array( &$this, 'wcdn_deactivate_add_questions' ), 10, 1 );
205
- add_filter( 'ts_tracker_data', array( &$this, 'wcdn_ts_add_plugin_tracking_data' ), 10, 1 );
206
- add_filter( 'ts_tracker_opt_out_data', array( &$this, 'wcdn_get_data_for_opt_out' ), 10, 1 );
207
-
208
-
209
- // Send out the init action
210
- do_action( 'wcdn_init');
211
- }
212
- }
213
-
214
- /**
215
- * Plugin's data to be tracked when Allow option is choosed.
216
- *
217
- * @hook ts_tracker_data
218
- *
219
- * @param array $data Contains the data to be tracked.
220
- *
221
- * @return array Plugin's data to track.
222
- *
223
- */
224
 
225
- public static function wcdn_ts_add_plugin_tracking_data ( $data ) {
226
- if ( isset( $_GET[ 'wcdn_tracker_optin' ] ) && isset( $_GET[ 'wcdn_tracker_nonce' ] ) && wp_verify_nonce( $_GET[ 'wcdn_tracker_nonce' ], 'wcdn_tracker_optin' ) ) {
227
-
228
- $plugin_data[ 'ts_meta_data_table_name' ] = 'ts_tracking_wcdn_meta_data';
229
- $plugin_data[ 'ts_plugin_name' ] = 'WooCommerce Print Invoice & Delivery Note';
230
-
231
- // Get all plugin options info
232
- $plugin_data[ 'invoice_in_admin' ] = get_option( 'wcdn_template_type_invoice' );
233
- $plugin_data[ 'delivery_in_admin' ] = get_option( 'wcdn_template_type_delivery-note' );
234
- $plugin_data[ 'receipt_in_admin' ] = get_option('wcdn_template_type_receipt');
235
- $plugin_data[ 'print_in_myaccount' ] = get_option('wcdn_print_button_on_my_account_page');
236
- $plugin_data[ 'print_in_vieworder' ] = get_option('wcdn_print_button_on_my_account_page');
237
- $plugin_data[ 'print_in_email' ] = get_option('wcdn_print_button_on_my_account_page');
238
- $plugin_data[ 'wcdn_plugin_version' ] = self::$plugin_version;
239
- $plugin_data[ 'wcdn_allow_tracking' ] = get_option ( 'wcdn_allow_tracking' );
240
- $data[ 'plugin_data' ] = $plugin_data;
241
- }
242
- return $data;
243
- }
244
-
245
-
246
- /**
247
- * Tracking data to send when No, thanks. button is clicked.
248
- *
249
- * @hook ts_tracker_opt_out_data
250
- *
251
- * @param array $params Parameters to pass for tracking data.
252
- *
253
- * @return array Data to track when opted out.
254
- *
255
- */
256
- public static function wcdn_get_data_for_opt_out ( $params ) {
257
- $plugin_data[ 'ts_meta_data_table_name'] = 'ts_tracking_wcdn_meta_data';
258
- $plugin_data[ 'ts_plugin_name' ] = 'WooCommerce Print Invoice & Delivery Note';
259
-
260
- // Store count info
261
- $params[ 'plugin_data' ] = $plugin_data;
262
-
263
- return $params;
264
- }
265
-
266
- /**
267
- * It will add the question for the deactivate popup modal
268
- * @return array $dfw_deactivate_questions All questions.
269
- */
270
- public static function wcdn_deactivate_add_questions ( $dfw_deactivate_questions ) {
271
-
272
- $dfw_deactivate_questions = array(
273
- 0 => array(
274
- 'id' => 4,
275
- 'text' => __( "I can't differentiate between Invoice, Delivery Notes & Receipt. The templates are the same. ", "woocommerce-delivery-notes" ),
276
- 'input_type' => '',
277
- 'input_placeholder' => ''
278
- ),
279
- 1 => array(
280
- 'id' => 5,
281
- 'text' => __( "The invoice sent through mail can't be downloaded as PDF directly.", "woocommerce-delivery-notes" ),
282
- 'input_type' => '',
283
- 'input_placeholder' => ''
284
- ),
285
- 2 => array(
286
- 'id' => 6,
287
- 'text' => __( "The plugin is not compatible with another plugin.", "woocommerce-delivery-notes" ),
288
- 'input_type' => 'textfield',
289
- 'input_placeholder' => 'Which plugin?'
290
- ),
291
- 3 => array(
292
- 'id' => 7,
293
- 'text' => __( "This plugin is not useful to me.", "woocommerce-delivery-notes" ),
294
- 'input_type' => '',
295
- 'input_placeholder' => ''
296
- )
297
-
298
- );
299
- return $dfw_deactivate_questions;
300
- }
301
- /**
302
- * Install or update the default settings
303
- */
304
- public function update() {
305
- $option_version = get_option( 'wcdn_version', '1' );
306
-
307
- // Update the settings
308
- if( version_compare( $option_version, self::$plugin_version, '<' ) ) {
309
- // Legacy updates
310
- if( version_compare( $option_version, '4.2.0', '<' ) ) {
311
- // Group invoice numbering
312
- $invoice_start = intval( get_option( 'wcdn_invoice_number_start', 1 ) );
313
- $invoice_counter = intval( get_option( 'wcdn_invoice_number_counter', 0 ) );
314
- update_option( 'wcdn_invoice_number_count', $invoice_start + $invoice_counter );
315
-
316
- // Translate checkbox values
317
- foreach( $this->settings->get_settings() as $value ) {
318
- if( isset( $value['id'] ) && isset( $value['type'] ) && $value['type'] == 'checkbox' ) {
319
- $autoload = isset( $value['autoload'] ) ? (bool) $value['autoload'] : true;
320
- $option = get_option( $value['id'] );
321
- if( (bool)$option ) {
322
- update_option( $value['id'], 'yes' );
323
- } else {
324
- update_option( $value['id'], 'no' );
325
- }
326
- }
327
- }
328
- }
329
-
330
- // Set all options that have default values
331
- foreach( $this->settings->get_settings() as $value ) {
332
- if( isset( $value['default'] ) && isset( $value['id'] ) ) {
333
- $autoload = isset( $value['autoload'] ) ? (bool) $value['autoload'] : true;
334
- add_option( $value['id'], $value['default'], '', ( $autoload ? 'yes' : 'no' ) );
335
- }
336
- }
337
-
338
- // Flush the transients in case the endpoint changed
339
- set_transient( 'wcdn_flush_rewrite_rules', true );
340
-
341
- // Update the settings to the latest version
342
- update_option( 'wcdn_version', self::$plugin_version );
343
- }
344
- }
345
-
346
- /**
347
- * Add settings link to plugin page
348
- */
349
- public function add_settings_link( $links ) {
350
- $url = esc_url( admin_url( add_query_arg( array( 'page' => 'wc-settings', 'tab' => $this->settings->id ), 'admin.php' ) ) );
351
- $settings = sprintf( '<a href="%s" title="%s">%s</a>' , $url, __( 'Go to the settings page', 'woocommerce-delivery-notes' ) , __( 'Settings', 'woocommerce-delivery-notes' ) );
352
- array_unshift( $links, $settings );
353
- return $links;
354
- }
355
-
356
- /**
357
- * Check if woocommerce is activated
358
- */
359
- public function is_woocommerce_activated() {
360
- $blog_plugins = get_option( 'active_plugins', array() );
361
- $site_plugins = get_site_option( 'active_sitewide_plugins', array() );
362
- $woocommerce_basename = plugin_basename( WC_PLUGIN_FILE );
363
-
364
- if( ( in_array( $woocommerce_basename, $blog_plugins ) || isset( $site_plugins[$woocommerce_basename] ) ) && version_compare( WC_VERSION, '2.2', '>=' ) ) {
365
- return true;
366
- } else {
367
- return false;
368
- }
369
- }
370
-
371
- }
372
  }
373
-
374
- /**
375
- * Returns the main instance of the plugin to prevent the need to use globals
376
- */
377
- function WCDN() {
378
- return WooCommerce_Delivery_Notes::instance();
379
- }
380
-
381
- /**
382
- * Global for backwards compatibility
383
- */
384
- $GLOBALS['wcdn'] = WCDN();
385
-
386
- ?>
4
  *
5
  * Plugin Name: WooCommerce Print Invoice & Delivery Note
6
  * Plugin URI: https://www.tychesoftwares.com/
7
+ * Description: Print Invoices & Delivery Notes for WooCommerce Orders.
8
+ * Version: 4.5.2
9
  * Author: Tyche Softwares
10
  * Author URI: https://www.tychesoftwares.com/
11
  * License: GPLv3 or later
14
  * Domain Path: /languages
15
  * Requires PHP: 5.6
16
  * WC requires at least: 3.0.0
17
+ * WC tested up to: 3.7
18
+ * Tested up to: 5.2
19
+ *
20
+ * Copyright 2019 Tyche Softwares
21
  *
 
 
22
  * This file is part of WooCommerce Print Invoices & Delivery Notes,
23
  * a plugin for WordPress.
24
  *
35
  *
36
  * You should have received a copy of the GNU General Public License
37
  * along with WordPress. If not, see <http://www.gnu.org/licenses/>.
38
+ *
39
+ * @package woocommerce-print-invoice-delivery-notes
40
  */
41
 
 
42
  /**
43
  * Exit if accessed directly
44
  */
45
+ if ( ! defined( 'ABSPATH' ) ) {
46
+ exit;
47
  }
48
 
49
+ if ( ! class_exists( 'WooCommerce_Delivery_Notes' ) ) {
50
+ include_once 'includes/class-woocommerce-delivery-notes.php';
51
+
 
52
  /**
53
+ * Global for backwards compatibility.
 
 
 
54
  */
55
+ $GLOBALS['wcdn'] = WooCommerce_Delivery_Notes::instance();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  }