WooCommerce Print Invoice & Delivery Note - Version 4.3.2

Version Description

(05.09.2017) =

  • In this version deprecated functions and classes have been removed. Because of that attributes were missing and attribute slug was getting printed on Invoice page. This has been fixed.

  • Fix - There was no line break before SKU element for variable products on Invoice page. This has been fixed.

  • Fix - The deprecated function WC_Order::get_order_currency has been removed and replaced with get_currency().

Download this release

Release Info

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

Code changes from version 4.2 to 4.3.2

includes/class-wcdn-print.php CHANGED
@@ -4,7 +4,7 @@
4
* Exit if accessed directly
5
*/
6
if ( !defined( 'ABSPATH' ) ) {
7
- exit;
8
}
9
10
/**
@@ -26,11 +26,11 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
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(
@@ -70,7 +70,7 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
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',
@@ -87,7 +87,7 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
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' ),
@@ -98,15 +98,15 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
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',
@@ -120,15 +120,15 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
120
add_action( 'template_redirect', array( $this, 'template_redirect_theme' ) );
121
add_action( 'wp_ajax_print_order', array( $this, 'template_redirect_admin' ) );
122
}
123
-
124
/**
125
* Load the init hooks
126
*/
127
- public function load_hooks() {
128
// Add the endpoints
129
$this->add_endpoints();
130
}
131
-
132
/**
133
* Add endpoints for query vars.
134
* the endpoint is used in the front-end to
@@ -156,7 +156,7 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
156
}
157
return $vars;
158
}
159
-
160
/**
161
* Parse the query variables
162
*/
@@ -164,7 +164,9 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
164
// Map endpoint keys to their query var keys, when another endpoint name was set.
165
foreach( $this->api_endpoints as $key => $var ) {
166
if( isset( $_GET[$var] ) ) {
167
- $wp->query_vars[$key] = $_GET[$var];
168
} elseif ( isset( $wp->query_vars[$var] ) ) {
169
$wp->query_vars[$key] = $wp->query_vars[$var];
170
}
@@ -176,7 +178,7 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
176
*/
177
public function build_template_locations() {
178
$wc_template_directory = WC_TEMPLATE_PATH . 'print-order/';
179
-
180
// Get the paths for custom styles
181
$settings_type = get_option( 'wcdn_template_style' );
182
$settings_path = null;
@@ -190,33 +192,33 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
190
}
191
}
192
}
193
-
194
// Build the locations
195
$locations = array(
196
'child_theme' => array(
197
'path' => trailingslashit( get_stylesheet_directory() ) . $wc_template_directory,
198
'url' => trailingslashit( get_stylesheet_directory_uri() ) . $wc_template_directory
199
),
200
-
201
'theme' => array(
202
'path' => trailingslashit( get_template_directory() ) . $wc_template_directory,
203
'url' => trailingslashit( get_template_directory_uri() ) . $wc_template_directory
204
),
205
-
206
'settings' => array(
207
'path' => $settings_path,
208
'url' => $settings_url
209
),
210
-
211
'plugin' => array(
212
'path' => self::$template_styles[0]['path'],
213
'url' => self::$template_styles[0]['url']
214
)
215
- );
216
-
217
return $locations;
218
}
219
-
220
/**
221
* Template handling in the front-end
222
*/
@@ -230,63 +232,66 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
230
exit;
231
}
232
}
233
-
234
/**
235
* Template handling in the back-end
236
*/
237
- public function template_redirect_admin() {
238
// Let the backend only access the page
239
if( is_admin() && current_user_can( 'edit_shop_orders' ) && !empty( $_REQUEST['print-order'] ) && !empty( $_REQUEST['action'] ) ) {
240
- $type = !empty( $_REQUEST['print-order-type'] ) ? $_REQUEST['print-order-type'] : null;
241
- $email = !empty( $_REQUEST['print-order-email'] ) ? $_REQUEST['print-order-email'] : null;
242
- $this->generate_template( $_GET['print-order'], $type, $email );
243
exit;
244
}
245
exit;
246
}
247
-
248
/**
249
- * Generate the template
250
*/
251
public function generate_template( $order_ids, $template_type = 'order', $order_email = null ) {
252
global $post, $wp;
253
-
254
// Explode the ids when needed
255
if( !is_array( $order_ids ) ) {
256
$this->order_ids = array_filter( explode('-', $order_ids ) );
257
}
258
-
259
- // Set the current template
260
foreach( self::$template_registrations as $template_registration ) {
261
if( $template_type == $template_registration['type'] ) {
262
$this->template = $template_registration;
263
break;
264
}
265
}
266
-
267
- // Set the email
268
if( empty( $order_email ) ) {
269
$this->order_email = null;
270
} else {
271
$this->order_email = strtolower( $order_email );
272
}
273
-
274
// Create the orders and check permissions
275
$populated = $this->populate_orders();
276
-
277
// Only continue if the orders are populated
278
if( !$populated ) {
279
die();
280
- }
281
-
282
// Load the print template html
283
$location = $this->get_template_file_location( 'print-order.php' );
284
wc_get_template( 'print-order.php', null, $location, $location );
285
exit;
286
}
287
-
288
/**
289
- * Find the location of a template file
290
*/
291
public function get_template_file_location( $name, $url_mode = false ) {
292
$found = '';
@@ -298,11 +303,11 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
298
$found = $template_location['path'];
299
}
300
break;
301
- }
302
}
303
return $found;
304
}
305
-
306
/**
307
* Get print page url
308
*/
@@ -311,10 +316,10 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
311
if( !is_array( $order_ids ) ) {
312
$order_ids = array_filter( explode( '-', $order_ids ) );
313
}
314
-
315
// Build the args
316
$args = array();
317
-
318
// Set the template type arg
319
foreach( self::$template_registrations as $template_registration ) {
320
if( $template_type == $template_registration['type'] && $template_type != 'order' ) {
@@ -322,31 +327,31 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
322
break;
323
}
324
}
325
-
326
// Set the email arg
327
if( !empty( $order_email ) ) {
328
$args = wp_parse_args( array( 'print-order-email' => $order_email ), $args );
329
}
330
-
331
- // Generate the url
332
$order_ids_slug = implode( '-', $order_ids );
333
-
334
// Create another url depending on where the user prints. This
335
- // prevents some issues with ssl when the my-account page is
336
// secured with ssl but the admin isn't.
337
if( is_admin() && current_user_can( 'edit_shop_orders' ) && $permalink == false ) {
338
// For the admin we use the ajax.php for better security
339
$args = wp_parse_args( array( 'action' => 'print_order' ), $args );
340
$base_url = admin_url( 'admin-ajax.php' );
341
$endpoint = 'print-order';
342
-
343
// Add the order ids and create the url
344
$url = add_query_arg( $endpoint, $order_ids_slug, $base_url );
345
- } else {
346
// For the theme
347
$base_url = wc_get_page_permalink( 'myaccount' );
348
$endpoint = $this->api_endpoints['print-order'];
349
-
350
// Add the order ids and create the url
351
if( get_option( 'permalink_structure' ) ) {
352
$url = trailingslashit( trailingslashit( $base_url ) . $endpoint . '/' . $order_ids_slug );
@@ -354,19 +359,19 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
354
$url = add_query_arg( $endpoint, $order_ids_slug, $base_url );
355
}
356
}
357
-
358
- // Add all other args
359
$url = add_query_arg( $args, $url );
360
-
361
return esc_url( $url );
362
}
363
-
364
/**
365
* Create the orders list and check the permissions
366
*/
367
- private function populate_orders() {
368
$this->orders = array();
369
-
370
// Get the orders
371
$args = array(
372
'posts_per_page' => -1,
@@ -376,81 +381,85 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
376
'orderby' => 'post__in'
377
);
378
$posts = get_posts( $args );
379
-
380
// All orders should exist
381
if( count( $posts ) !== count( $this->order_ids ) ) {
382
$this->orders = null;
383
return false;
384
}
385
-
386
- // Check permissons of the user to determine
387
// if the orders should be populated.
388
foreach( $posts as $post ) {
389
$order = new WC_Order( $post->ID );
390
-
391
- // Logged in users
392
- if( is_user_logged_in() && ( !current_user_can( 'edit_shop_orders' ) && !current_user_can( 'view_order', $order->id ) ) ) {
393
$this->orders = null;
394
return false;
395
- }
396
397
- // An email is required for not logged in users
398
- if( !is_user_logged_in() && ( empty( $this->order_email ) || strtolower( $order->billing_email ) != $this->order_email ) ) {
399
$this->orders = null;
400
return false;
401
}
402
-
403
// Save the order to get it without an additional database call
404
$this->orders[$post->ID] = $order;
405
}
406
return true;
407
}
408
-
409
/**
410
* Get the order
411
*/
412
- public function get_order( $order_id ) {
413
if( isset( $this->orders[$order_id] ) ) {
414
return $this->orders[$order_id];
415
}
416
- return;
417
- }
418
-
419
/**
420
* Get the order invoice number
421
*/
422
- public function get_order_invoice_number( $order_id ) {
423
$invoice_count = intval( get_option( 'wcdn_invoice_number_count', 1 ) );
424
$invoice_prefix = get_option( 'wcdn_invoice_number_prefix' );
425
$invoice_suffix = get_option( 'wcdn_invoice_number_suffix' );
426
-
427
// Add the invoice number to the order when it doesn't yet exist
428
$meta_key = '_wcdn_invoice_number';
429
$meta_added = add_post_meta( $order_id, $meta_key, $invoice_prefix . $invoice_count . $invoice_suffix, true );
430
-
431
// Update the total count
432
if( $meta_added ) {
433
update_option( 'wcdn_invoice_number_count', $invoice_count + 1 );
434
}
435
-
436
// Get the invoice number
437
return apply_filters( 'wcdn_order_invoice_number', get_post_meta( $order_id, $meta_key, true ) );
438
- }
439
-
440
/**
441
* Get the order invoice date
442
*/
443
- public function get_order_invoice_date( $order_id ) {
444
// Add the invoice date to the order when it doesn't yet exist
445
$meta_key = '_wcdn_invoice_date';
446
$meta_added = add_post_meta( $order_id, $meta_key, time(), true );
447
-
448
// Get the invoice date
449
$meta_date = get_post_meta( $order_id, $meta_key, true );
450
$formatted_date = date_i18n( get_option('date_format'), $meta_date );
451
return apply_filters( 'wcdn_order_invoice_date', $formatted_date, $meta_date );
452
}
453
-
454
}
455
456
}
4
* Exit if accessed directly
5
*/
6
if ( !defined( 'ABSPATH' ) ) {
7
+ exit;
8
}
9
10
/**
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(
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',
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' ),
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',
120
add_action( 'template_redirect', array( $this, 'template_redirect_theme' ) );
121
add_action( 'wp_ajax_print_order', array( $this, 'template_redirect_admin' ) );
122
}
123
+
124
/**
125
* Load the init hooks
126
*/
127
+ public function load_hooks() {
128
// Add the endpoints
129
$this->add_endpoints();
130
}
131
+
132
/**
133
* Add endpoints for query vars.
134
* the endpoint is used in the front-end to
156
}
157
return $vars;
158
}
159
+
160
/**
161
* Parse the query variables
162
*/
164
// Map endpoint keys to their query var keys, when another endpoint name was set.
165
foreach( $this->api_endpoints as $key => $var ) {
166
if( isset( $_GET[$var] ) ) {
167
+ // changed
168
+ $wdn_get_end_point_var = sanitize_text_field($_GET[$var]);
169
+ $wp->query_vars[$key] = $wdn_get_end_point_var;
170
} elseif ( isset( $wp->query_vars[$var] ) ) {
171
$wp->query_vars[$key] = $wp->query_vars[$var];
172
}
178
*/
179
public function build_template_locations() {
180
$wc_template_directory = WC_TEMPLATE_PATH . 'print-order/';
181
+
182
// Get the paths for custom styles
183
$settings_type = get_option( 'wcdn_template_style' );
184
$settings_path = null;
192
}
193
}
194
}
195
+
196
// Build the locations
197
$locations = array(
198
'child_theme' => array(
199
'path' => trailingslashit( get_stylesheet_directory() ) . $wc_template_directory,
200
'url' => trailingslashit( get_stylesheet_directory_uri() ) . $wc_template_directory
201
),
202
+
203
'theme' => array(
204
'path' => trailingslashit( get_template_directory() ) . $wc_template_directory,
205
'url' => trailingslashit( get_template_directory_uri() ) . $wc_template_directory
206
),
207
+
208
'settings' => array(
209
'path' => $settings_path,
210
'url' => $settings_url
211
),
212
+
213
'plugin' => array(
214
'path' => self::$template_styles[0]['path'],
215
'url' => self::$template_styles[0]['url']
216
)
217
+ );
218
+
219
return $locations;
220
}
221
+
222
/**
223
* Template handling in the front-end
224
*/
232
exit;
233
}
234
}
235
+
236
/**
237
* Template handling in the back-end
238
*/
239
+ public function template_redirect_admin() {
240
// Let the backend only access the page
241
+ // changed
242
if( is_admin() && current_user_can( 'edit_shop_orders' ) && !empty( $_REQUEST['print-order'] ) && !empty( $_REQUEST['action'] ) ) {
243
+ $type = !empty( $_REQUEST['print-order-type'] ) ? sanitize_text_field ( $_REQUEST['print-order-type'] ) : null;
244
+ $email = !empty( $_REQUEST['print-order-email'] ) ? sanitize_email ( $_REQUEST['print-order-email'] ) : null;
245
+ // changed
246
+ $wdn_get_print_order = sanitize_text_field ( $_GET['print-order'] );
247
+ $this->generate_template( $wdn_get_print_order, $type, $email );
248
exit;
249
}
250
exit;
251
}
252
+
253
/**
254
+ * Generate the template
255
*/
256
public function generate_template( $order_ids, $template_type = 'order', $order_email = null ) {
257
global $post, $wp;
258
+
259
// Explode the ids when needed
260
if( !is_array( $order_ids ) ) {
261
$this->order_ids = array_filter( explode('-', $order_ids ) );
262
}
263
+
264
+ // Set the current template
265
foreach( self::$template_registrations as $template_registration ) {
266
if( $template_type == $template_registration['type'] ) {
267
$this->template = $template_registration;
268
break;
269
}
270
}
271
+
272
+ // Set the email
273
if( empty( $order_email ) ) {
274
$this->order_email = null;
275
} else {
276
$this->order_email = strtolower( $order_email );
277
}
278
+
279
// Create the orders and check permissions
280
$populated = $this->populate_orders();
281
+
282
// Only continue if the orders are populated
283
if( !$populated ) {
284
die();
285
+ }
286
+
287
// Load the print template html
288
$location = $this->get_template_file_location( 'print-order.php' );
289
wc_get_template( 'print-order.php', null, $location, $location );
290
exit;
291
}
292
+
293
/**
294
+ * Find the location of a template file
295
*/
296
public function get_template_file_location( $name, $url_mode = false ) {
297
$found = '';
303
$found = $template_location['path'];
304
}
305
break;
306
+ }
307
}
308
return $found;
309
}
310
+
311
/**
312
* Get print page url
313
*/
316
if( !is_array( $order_ids ) ) {
317
$order_ids = array_filter( explode( '-', $order_ids ) );
318
}
319
+
320
// Build the args
321
$args = array();
322
+
323
// Set the template type arg
324
foreach( self::$template_registrations as $template_registration ) {
325
if( $template_type == $template_registration['type'] && $template_type != 'order' ) {
327
break;
328
}
329
}
330
+
331
// Set the email arg
332
if( !empty( $order_email ) ) {
333
$args = wp_parse_args( array( 'print-order-email' => $order_email ), $args );
334
}
335
+
336
+ // Generate the url
337
$order_ids_slug = implode( '-', $order_ids );
338
+
339
// Create another url depending on where the user prints. This
340
+ // prevents some issues with ssl when the my-account page is
341
// secured with ssl but the admin isn't.
342
if( is_admin() && current_user_can( 'edit_shop_orders' ) && $permalink == false ) {
343
// For the admin we use the ajax.php for better security
344
$args = wp_parse_args( array( 'action' => 'print_order' ), $args );
345
$base_url = admin_url( 'admin-ajax.php' );
346
$endpoint = 'print-order';
347
+
348
// Add the order ids and create the url
349
$url = add_query_arg( $endpoint, $order_ids_slug, $base_url );
350
+ } else {
351
// For the theme
352
$base_url = wc_get_page_permalink( 'myaccount' );
353
$endpoint = $this->api_endpoints['print-order'];
354
+
355
// Add the order ids and create the url
356
if( get_option( 'permalink_structure' ) ) {
357
$url = trailingslashit( trailingslashit( $base_url ) . $endpoint . '/' . $order_ids_slug );
359
$url = add_query_arg( $endpoint, $order_ids_slug, $base_url );
360
}
361
}
362
+
363
+ // Add all other args
364
$url = add_query_arg( $args, $url );
365
+
366
return esc_url( $url );
367
}
368
+
369
/**
370
* Create the orders list and check the permissions
371
*/
372
+ private function populate_orders() {
373
$this->orders = array();
374
+
375
// Get the orders
376
$args = array(
377
'posts_per_page' => -1,
381
'orderby' => 'post__in'
382
);
383
$posts = get_posts( $args );
384
+
385
// All orders should exist
386
if( count( $posts ) !== count( $this->order_ids ) ) {
387
$this->orders = null;
388
return false;
389
}
390
+
391
+ // Check permissons of the user to determine
392
// if the orders should be populated.
393
foreach( $posts as $post ) {
394
$order = new WC_Order( $post->ID );
395
+
396
+ $wdn_order_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_id() : $order->id;
397
+ // Logged in users
398
+ if( is_user_logged_in() && ( !current_user_can( 'edit_shop_orders' ) && !current_user_can( 'view_order', $wdn_order_id ) ) ) {
399
$this->orders = null;
400
return false;
401
+ }
402
+
403
+ $wdn_order_billing_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_billing_email() : $order->billing_email;
404
405
+
406
+ // An email is required for not logged in users
407
+ if( !is_user_logged_in() && ( empty( $this->order_email ) || strtolower( $wdn_order_billing_id ) != $this->order_email ) ) {
408
$this->orders = null;
409
return false;
410
}
411
+
412
// Save the order to get it without an additional database call
413
$this->orders[$post->ID] = $order;
414
}
415
return true;
416
}
417
+
418
/**
419
* Get the order
420
*/
421
+ public function get_order( $order_id ) {
422
if( isset( $this->orders[$order_id] ) ) {
423
return $this->orders[$order_id];
424
}
425
+ return;
426
+ }
427
+
428
/**
429
* Get the order invoice number
430
*/
431
+ public function get_order_invoice_number( $order_id ) {
432
$invoice_count = intval( get_option( 'wcdn_invoice_number_count', 1 ) );
433
$invoice_prefix = get_option( 'wcdn_invoice_number_prefix' );
434
$invoice_suffix = get_option( 'wcdn_invoice_number_suffix' );
435
+
436
// Add the invoice number to the order when it doesn't yet exist
437
$meta_key = '_wcdn_invoice_number';
438
$meta_added = add_post_meta( $order_id, $meta_key, $invoice_prefix . $invoice_count . $invoice_suffix, true );
439
+
440
// Update the total count
441
if( $meta_added ) {
442
update_option( 'wcdn_invoice_number_count', $invoice_count + 1 );
443
}
444
+
445
// Get the invoice number
446
return apply_filters( 'wcdn_order_invoice_number', get_post_meta( $order_id, $meta_key, true ) );
447
+ }
448
+
449
/**
450
* Get the order invoice date
451
*/
452
+ public function get_order_invoice_date( $order_id ) {
453
// Add the invoice date to the order when it doesn't yet exist
454
$meta_key = '_wcdn_invoice_date';
455
$meta_added = add_post_meta( $order_id, $meta_key, time(), true );
456
+
457
// Get the invoice date
458
$meta_date = get_post_meta( $order_id, $meta_key, true );
459
$formatted_date = date_i18n( get_option('date_format'), $meta_date );
460
return apply_filters( 'wcdn_order_invoice_date', $formatted_date, $meta_date );
461
}
462
+
463
}
464
465
}
includes/class-wcdn-settings.php CHANGED
@@ -4,7 +4,7 @@
4
* Exit if accessed directly
5
*/
6
if ( !defined( 'ABSPATH' ) ) {
7
- exit;
8
}
9
10
/**
@@ -13,16 +13,16 @@ if ( !defined( 'ABSPATH' ) ) {
13
if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
14
15
class WooCommerce_Delivery_Notes_Settings {
16
-
17
public $id;
18
-
19
/**
20
* Constructor
21
*/
22
- public function __construct() {
23
// Define default variables
24
- $this->id = 'wcdn-settings';
25
-
26
// Load the hooks
27
add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 200 );
28
add_action( 'woocommerce_settings_start', array( $this, 'add_assets' ) );
@@ -33,14 +33,14 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
33
add_action( 'wp_ajax_wcdn_settings_load_image', array( $this, 'load_image_ajax' ) );
34
add_filter( 'wcdn_get_settings', array( $this, 'generate_template_type_fields' ), 10, 2 );
35
}
36
-
37
/**
38
* Add the scripts
39
*/
40
- public function add_assets() {
41
- // Styles
42
wp_enqueue_style( 'woocommerce-delivery-notes-admin', WooCommerce_Delivery_Notes::$plugin_url . 'css/admin.css' );
43
-
44
// Scripts
45
wp_enqueue_media();
46
wp_enqueue_script( 'woocommerce-delivery-notes-print-link', WooCommerce_Delivery_Notes::$plugin_url . 'js/jquery.print-link.js', array( 'jquery' ) );
@@ -50,7 +50,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
50
$translation = array( 'resetCounter' => __( 'Do you really want to reset the counter to zero? This process can\'t be undone.', 'woocommerce-delivery-notes' ) );
51
wp_localize_script( 'woocommerce-delivery-notes-admin', 'WCDNText', $translation );
52
}
53
-
54
/**
55
* Create a new settings tab
56
*/
@@ -58,7 +58,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
58
$settings_tabs[$this->id] = __( 'Print', 'woocommerce-delivery-notes' );
59
return $settings_tabs;
60
}
61
-
62
/**
63
* Output the settings fields into the tab
64
*/
@@ -67,7 +67,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
67
$settings = $this->get_settings( $current_section );
68
woocommerce_admin_fields( $settings );
69
}
70
-
71
/**
72
* Save the settings
73
*/
@@ -81,16 +81,16 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
81
/**
82
* Get the settings fields
83
*/
84
- public function get_settings( $section = '' ) {
85
- $settings = apply_filters( 'wcdn_get_settings_no_section',
86
array(
87
- array(
88
- 'title' => __( 'Template', 'woocommerce-delivery-notes' ),
89
- 'type' => 'title',
90
- 'desc' => $this->get_template_description(),
91
- 'id' => 'general_options'
92
),
93
-
94
array(
95
'title' => __( 'Style', 'woocommerce-delivery-notes' ),
96
'desc' => sprintf( __( 'The default print style. Read the <a href="%1$s">FAQ</a> to learn how to customize it or get more styles with <a href="%2$s">WooCommerce Print Invoice & Delivery Note Pro</a>.', 'woocommerce-delivery-notes' ), 'https://wordpress.org/plugins/woocommerce-delivery-notes/faq/', '#' ),
@@ -101,7 +101,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
101
'options' => $this->get_options_styles(),
102
'desc_tip' => false,
103
),
104
-
105
array(
106
'title' => __( 'Shop Logo', 'woocommerce-delivery-notes' ),
107
'desc' => '',
@@ -111,7 +111,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
111
'type' => 'wcdn_image_select',
112
'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' )
113
),
114
-
115
array(
116
'title' => __( 'Shop Name', 'woocommerce-delivery-notes' ),
117
'desc' => '',
@@ -121,7 +121,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
121
'type' => 'text',
122
'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' ),
123
),
124
-
125
array(
126
'title' => __( 'Shop Address', 'woocommerce-delivery-notes' ),
127
'desc' => __( 'The postal address of the shop or even e-mail or telephone.', 'woocommerce-delivery-notes' ),
@@ -131,7 +131,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
131
'type' => 'textarea',
132
'desc_tip' => true,
133
),
134
-
135
array(
136
'title' => __( 'Complimentary Close', 'woocommerce-delivery-notes' ),
137
'desc' => __( 'Add a personal close, notes or season greetings.', 'woocommerce-delivery-notes' ),
@@ -141,7 +141,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
141
'type' => 'textarea',
142
'desc_tip' => true,
143
),
144
-
145
array(
146
'title' => __( 'Policies', 'woocommerce-delivery-notes' ),
147
'desc' => __( 'Add the shop policies, conditions, etc.', 'woocommerce-delivery-notes' ),
@@ -151,7 +151,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
151
'type' => 'textarea',
152
'desc_tip' => true,
153
),
154
-
155
array(
156
'title' => __( 'Footer', 'woocommerce-delivery-notes' ),
157
'desc' => __( 'Add a footer imprint, instructions, copyright notes, e-mail, telephone, etc.', 'woocommerce-delivery-notes' ),
@@ -161,19 +161,19 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
161
'type' => 'textarea',
162
'desc_tip' => true,
163
),
164
-
165
array(
166
'type' => 'sectionend',
167
'id' => 'general_options'
168
),
169
-
170
- array(
171
- 'title' => __( 'Pages & Buttons', 'woocommerce-delivery-notes' ),
172
- 'type' => 'title',
173
- 'desc' => '',
174
- 'id' => 'display_options'
175
),
176
-
177
array(
178
'title' => __( 'Print Page Endpoint', 'woocommerce-delivery-notes' ),
179
'desc' => '',
@@ -183,7 +183,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
183
'type' => 'text',
184
'desc_tip' => __( 'The endpoint is appended to the accounts page URL to print the order. It should be unique.', 'woocommerce-delivery-notes' ),
185
),
186
-
187
array(
188
'title' => __( 'Email', 'woocommerce-delivery-notes' ),
189
'desc' => __( 'Show print link in customer emails', 'woocommerce-delivery-notes' ),
@@ -192,7 +192,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
192
'type' => 'checkbox',
193
'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' )
194
),
195
-
196
array(
197
'title' => __( 'My Account', 'woocommerce-delivery-notes' ),
198
'desc' => __( 'Show print button on the "View Order" page', 'woocommerce-delivery-notes' ),
@@ -201,7 +201,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
201
'type' => 'checkbox',
202
'checkboxgroup' => 'start'
203
),
204
-
205
array(
206
'desc' => __( 'Show print buttons on the "My Account" page', 'woocommerce-delivery-notes' ),
207
'id' => 'wcdn_print_button_on_my_account_page',
@@ -209,19 +209,19 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
209
'type' => 'checkbox',
210
'checkboxgroup' => 'end'
211
),
212
-
213
array(
214
'type' => 'sectionend',
215
'id' => 'display_options'
216
),
217
-
218
- array(
219
- 'title' => __( 'Invoice', 'woocommerce-delivery-notes' ),
220
- 'type' => 'title',
221
- 'desc' => '',
222
- 'id' => 'invoice_options'
223
),
224
-
225
array(
226
'title' => __( 'Numbering', 'woocommerce-delivery-notes' ),
227
'desc' => __( 'Create invoice numbers', 'woocommerce-delivery-notes' ),
@@ -230,7 +230,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
230
'type' => 'checkbox',
231
'desc_tip' => ''
232
),
233
-
234
array(
235
'title' => __( 'Next Number', 'woocommerce-delivery-notes' ),
236
'desc' => '',
@@ -241,7 +241,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
241
'type' => 'number',
242
'desc_tip' => __( 'The next invoice number.', 'woocommerce-delivery-notes' )
243
),
244
-
245
array(
246
'title' => __( 'Number Prefix', 'woocommerce-delivery-notes' ),
247
'desc' => '',
@@ -252,7 +252,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
252
'type' => 'text',
253
'desc_tip' => __( 'This text will be prepended to the invoice number.', 'woocommerce-delivery-notes' )
254
),
255
-
256
array(
257
'title' => __( 'Number Suffix', 'woocommerce-delivery-notes' ),
258
'desc' => '',
@@ -263,27 +263,27 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
263
'type' => 'text',
264
'desc_tip' => __( 'This text will be appended to the invoice number.', 'woocommerce-delivery-notes' )
265
),
266
-
267
array(
268
'type' => 'sectionend',
269
'id' => 'invoice_options'
270
),
271
- )
272
);
273
-
274
return apply_filters( 'wcdn_get_settings', $settings, $section );
275
}
276
-
277
/**
278
* Get the position of a setting inside the array
279
*/
280
- public function get_setting_position( $id, $settings, $type = null ) {
281
foreach( $settings as $key => $value ) {
282
if( isset( $value['id'] ) && $value['id'] == $id ) {
283
return $key;
284
}
285
}
286
-
287
return false;
288
}
289
@@ -294,7 +294,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
294
$position = $this->get_setting_position( 'wcdn_email_print_link', $settings );
295
if( $position !== false ) {
296
$new_settings = array();
297
-
298
// Go through all registrations but remove the default 'order' type
299
$template_registrations = WooCommerce_Delivery_Notes_Print::$template_registrations;
300
array_splice( $template_registrations, 0, 1 );
@@ -303,7 +303,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
303
$title = '';
304
$desc_tip = '';
305
$checkboxgroup = '';
306
-
307
// Define the group settings
308
if( $index == 0 ) {
309
$title = __( 'Admin', 'woocommerce-delivery-notes' );
@@ -312,7 +312,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
312
$desc_tip = __( 'The print buttons are available on the order listing and on the order detail screen.', 'woocommerce-delivery-notes' );
313
$checkboxgroup = 'end';
314
}
315
-
316
// Create the setting
317
$new_settings[] = array(
318
'title' => $title,
@@ -324,18 +324,18 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
324
'desc_tip' => $desc_tip
325
);
326
}
327
-
328
// Add the settings
329
$settings = $this->array_merge_at( $settings, $new_settings, $position );
330
}
331
332
return $settings;
333
}
334
-
335
/**
336
* Generate the description for the template settings
337
*/
338
- public function get_template_description() {
339
$description = '';
340
$args = array(
341
'post_type' => 'shop_order',
@@ -343,35 +343,35 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
343
'posts_per_page' => 1
344
);
345
$query = new WP_Query( $args );
346
-
347
- // show template preview links when an order is available
348
if( $query->have_posts() ) {
349
$results = $query->get_posts();
350
$test_id = $results[0]->ID;
351
$invoice_url = wcdn_get_print_link( $test_id, 'invoice' );
352
$delivery_note_url = wcdn_get_print_link( $test_id, 'delivery-note' );
353
$receipt_url = wcdn_get_print_link( $test_id, 'receipt' );
354
- $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', '' );
355
}
356
-
357
return $description;
358
}
359
-
360
/**
361
* Generate the options for the template styles field
362
*/
363
public function get_options_styles() {
364
$options = array();
365
-
366
foreach( WooCommerce_Delivery_Notes_Print::$template_styles as $template_style ) {
367
if( is_array( $template_style ) && isset( $template_style['type'] ) && isset( $template_style['name'] ) ) {
368
$options[$template_style['type']] = $template_style['name'];
369
}
370
}
371
-
372
return $options;
373
}
374
-
375
/**
376
* Load image with ajax
377
*/
@@ -381,17 +381,18 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
381
die();
382
}
383
384
- // Verify the id
385
- if( empty( $_POST['attachment_id'] ) ) {
386
die();
387
}
388
-
389
// create the image
390
- $this->create_image( $_POST['attachment_id'] );
391
-
392
exit;
393
}
394
-
395
/**
396
* Create image
397
*/
@@ -401,12 +402,12 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
401
if( ( $attachment_src[1] / $attachment_src[2] ) < 1 ) {
402
$orientation = 'portrait';
403
}
404
-
405
?>
406
<img src="<?php echo $attachment_src[0]; ?>" class="<?php echo $orientation; ?>" alt="" />
407
<?php
408
}
409
-
410
/**
411
* Output image select field
412
*/
@@ -415,25 +416,27 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
415
if ( ! isset( $value['title_select'] ) ) {
416
$value['title_select'] = __( 'Select', 'woocommerce-delivery-notes' );
417
}
418
-
419
if ( ! isset( $value['title_remove'] ) ) {
420
$value['title_remove'] = __( 'Remove', 'woocommerce-delivery-notes' );
421
}
422
-
423
// Get additional data fields
424
$field = WC_Admin_Settings::get_field_description( $value );
425
$description = $field['description'];
426
$tooltip_html = $field['tooltip_html'];
427
$option_value = WC_Admin_Settings::get_option( $value['id'], $value['default'] );
428
$class_name = 'wcdn-image-select';
429
-
430
?><tr valign="top">
431
<th scope="row" class="titledesc">
432
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?> <?php echo $tooltip_html; ?></label>
433
</th>
434
<td class="forminp image_width_settings">
435
<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'] ); ?>" />
436
-
437
<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'] ); ?>">
438
<span id="<?php echo esc_attr( $value['id'] ); ?>_spinner" class="<?php echo $class_name; ?>-spinner spinner"></span>
439
<div id="<?php echo esc_attr( $value['id'] ); ?>_attachment" class="<?php echo $class_name; ?>-attachment <?php echo esc_attr( $value['class'] ); ?> ">
@@ -445,7 +448,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
445
</div>
446
</div>
447
</div>
448
-
449
<div id="<?php echo esc_attr( $value['id'] ); ?>_buttons" class="<?php echo $class_name; ?>-buttons <?php echo esc_attr( $value['class'] ); ?>">
450
<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">
451
<?php echo esc_html( $value['title_remove'] ); ?>
@@ -453,17 +456,17 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
453
<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'] ); ?>">
454
<?php echo esc_html( $value['title_select'] ); ?>
455
</a>
456
- </div>
457
</div>
458
-
459
<?php echo $description; ?>
460
</td>
461
</tr><?php
462
}
463
-
464
/**
465
* Merge array at given position
466
- */
467
public function array_merge_at( $array, $insert, $position ) {
468
$new_array = array();
469
// if pos is start, just merge them
@@ -483,7 +486,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
483
return $new_array;
484
}
485
}
486
-
487
}
488
489
- ?>
4
* Exit if accessed directly
5
*/
6
if ( !defined( 'ABSPATH' ) ) {
7
+ exit;
8
}
9
10
/**
13
if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
14
15
class WooCommerce_Delivery_Notes_Settings {
16
+
17
public $id;
18
+
19
/**
20
* Constructor
21
*/
22
+ public function __construct() {
23
// Define default variables
24
+ $this->id = 'wcdn-settings';
25
+
26
// Load the hooks
27
add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 200 );
28
add_action( 'woocommerce_settings_start', array( $this, 'add_assets' ) );
33
add_action( 'wp_ajax_wcdn_settings_load_image', array( $this, 'load_image_ajax' ) );
34
add_filter( 'wcdn_get_settings', array( $this, 'generate_template_type_fields' ), 10, 2 );
35
}
36
+
37
/**
38
* Add the scripts
39
*/
40
+ public function add_assets() {
41
+ // Styles
42
wp_enqueue_style( 'woocommerce-delivery-notes-admin', WooCommerce_Delivery_Notes::$plugin_url . 'css/admin.css' );
43
+
44
// Scripts
45
wp_enqueue_media();
46
wp_enqueue_script( 'woocommerce-delivery-notes-print-link', WooCommerce_Delivery_Notes::$plugin_url . 'js/jquery.print-link.js', array( 'jquery' ) );
50
$translation = array( 'resetCounter' => __( 'Do you really want to reset the counter to zero? This process can\'t be undone.', 'woocommerce-delivery-notes' ) );
51
wp_localize_script( 'woocommerce-delivery-notes-admin', 'WCDNText', $translation );
52
}
53
+
54
/**
55
* Create a new settings tab
56
*/
58
$settings_tabs[$this->id] = __( 'Print', 'woocommerce-delivery-notes' );
59
return $settings_tabs;
60
}
61
+
62
/**
63
* Output the settings fields into the tab
64
*/
67
$settings = $this->get_settings( $current_section );
68
woocommerce_admin_fields( $settings );
69
}
70
+
71
/**
72
* Save the settings
73
*/
81
/**
82
* Get the settings fields
83
*/
84
+ public function get_settings( $section = '' ) {
85
+ $settings = apply_filters( 'wcdn_get_settings_no_section',
86
array(
87
+ array(
88
+ 'title' => __( 'Template', 'woocommerce-delivery-notes' ),
89
+ 'type' => 'title',
90
+ 'desc' => $this->get_template_description(),
91
+ 'id' => 'general_options'
92
),
93
+
94
array(
95
'title' => __( 'Style', 'woocommerce-delivery-notes' ),
96
'desc' => sprintf( __( 'The default print style. Read the <a href="%1$s">FAQ</a> to learn how to customize it or get more styles with <a href="%2$s">WooCommerce Print Invoice & Delivery Note Pro</a>.', 'woocommerce-delivery-notes' ), 'https://wordpress.org/plugins/woocommerce-delivery-notes/faq/', '#' ),
101
'options' => $this->get_options_styles(),
102
'desc_tip' => false,
103
),
104
+
105
array(
106
'title' => __( 'Shop Logo', 'woocommerce-delivery-notes' ),
107
'desc' => '',
111
'type' => 'wcdn_image_select',
112
'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' )
113
),
114
+
115
array(
116
'title' => __( 'Shop Name', 'woocommerce-delivery-notes' ),
117
'desc' => '',
121
'type' => 'text',
122
'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' ),
123
),
124
+
125
array(
126
'title' => __( 'Shop Address', 'woocommerce-delivery-notes' ),
127
'desc' => __( 'The postal address of the shop or even e-mail or telephone.', 'woocommerce-delivery-notes' ),
131
'type' => 'textarea',
132
'desc_tip' => true,
133
),
134
+
135
array(
136
'title' => __( 'Complimentary Close', 'woocommerce-delivery-notes' ),
137
'desc' => __( 'Add a personal close, notes or season greetings.', 'woocommerce-delivery-notes' ),
141
'type' => 'textarea',
142
'desc_tip' => true,
143
),
144
+
145
array(
146
'title' => __( 'Policies', 'woocommerce-delivery-notes' ),
147
'desc' => __( 'Add the shop policies, conditions, etc.', 'woocommerce-delivery-notes' ),
151
'type' => 'textarea',
152
'desc_tip' => true,
153
),
154
+
155
array(
156
'title' => __( 'Footer', 'woocommerce-delivery-notes' ),
157
'desc' => __( 'Add a footer imprint, instructions, copyright notes, e-mail, telephone, etc.', 'woocommerce-delivery-notes' ),
161
'type' => 'textarea',
162
'desc_tip' => true,
163
),
164
+
165
array(
166
'type' => 'sectionend',
167
'id' => 'general_options'
168
),
169
+
170
+ array(
171
+ 'title' => __( 'Pages & Buttons', 'woocommerce-delivery-notes' ),
172
+ 'type' => 'title',
173
+ 'desc' => '',
174
+ 'id' => 'display_options'
175
),
176
+
177
array(
178
'title' => __( 'Print Page Endpoint', 'woocommerce-delivery-notes' ),
179
'desc' => '',
183
'type' => 'text',
184
'desc_tip' => __( 'The endpoint is appended to the accounts page URL to print the order. It should be unique.', 'woocommerce-delivery-notes' ),
185
),
186
+
187
array(
188
'title' => __( 'Email', 'woocommerce-delivery-notes' ),
189
'desc' => __( 'Show print link in customer emails', 'woocommerce-delivery-notes' ),
192
'type' => 'checkbox',
193
'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' )
194
),
195
+
196
array(
197
'title' => __( 'My Account', 'woocommerce-delivery-notes' ),
198
'desc' => __( 'Show print button on the "View Order" page', 'woocommerce-delivery-notes' ),
201
'type' => 'checkbox',
202
'checkboxgroup' => 'start'
203
),
204
+
205
array(
206
'desc' => __( 'Show print buttons on the "My Account" page', 'woocommerce-delivery-notes' ),
207
'id' => 'wcdn_print_button_on_my_account_page',
209
'type' => 'checkbox',
210
'checkboxgroup' => 'end'
211
),
212
+
213
array(
214
'type' => 'sectionend',
215
'id' => 'display_options'
216
),
217
+
218
+ array(
219
+ 'title' => __( 'Invoice', 'woocommerce-delivery-notes' ),
220
+ 'type' => 'title',
221
+ 'desc' => '',
222
+ 'id' => 'invoice_options'
223
),
224
+
225
array(
226
'title' => __( 'Numbering', 'woocommerce-delivery-notes' ),
227
'desc' => __( 'Create invoice numbers', 'woocommerce-delivery-notes' ),
230
'type' => 'checkbox',
231
'desc_tip' => ''
232
),
233
+
234
array(
235
'title' => __( 'Next Number', 'woocommerce-delivery-notes' ),
236
'desc' => '',
241
'type' => 'number',
242
'desc_tip' => __( 'The next invoice number.', 'woocommerce-delivery-notes' )
243
),
244
+
245
array(
246
'title' => __( 'Number Prefix', 'woocommerce-delivery-notes' ),
247
'desc' => '',
252
'type' => 'text',
253
'desc_tip' => __( 'This text will be prepended to the invoice number.', 'woocommerce-delivery-notes' )
254
),
255
+
256
array(
257
'title' => __( 'Number Suffix', 'woocommerce-delivery-notes' ),
258
'desc' => '',
263
'type' => 'text',
264
'desc_tip' => __( 'This text will be appended to the invoice number.', 'woocommerce-delivery-notes' )
265
),
266
+
267
array(
268
'type' => 'sectionend',
269
'id' => 'invoice_options'
270
),
271
+ )
272
);
273
+
274
return apply_filters( 'wcdn_get_settings', $settings, $section );
275
}
276
+
277
/**
278
* Get the position of a setting inside the array
279
*/
280
+ public function get_setting_position( $id, $settings, $type = null ) {
281
foreach( $settings as $key => $value ) {
282
if( isset( $value['id'] ) && $value['id'] == $id ) {
283
return $key;
284
}
285
}
286
+
287
return false;
288
}
289
294
$position = $this->get_setting_position( 'wcdn_email_print_link', $settings );
295
if( $position !== false ) {
296
$new_settings = array();
297
+
298
// Go through all registrations but remove the default 'order' type
299
$template_registrations = WooCommerce_Delivery_Notes_Print::$template_registrations;
300
array_splice( $template_registrations, 0, 1 );
303
$title = '';
304
$desc_tip = '';
305
$checkboxgroup = '';
306
+
307
// Define the group settings
308
if( $index == 0 ) {
309
$title = __( 'Admin', 'woocommerce-delivery-notes' );
312
$desc_tip = __( 'The print buttons are available on the order listing and on the order detail screen.', 'woocommerce-delivery-notes' );
313
$checkboxgroup = 'end';
314
}
315
+
316
// Create the setting
317
$new_settings[] = array(
318
'title' => $title,
324
'desc_tip' => $desc_tip
325
);
326
}
327
+
328
// Add the settings
329
$settings = $this->array_merge_at( $settings, $new_settings, $position );
330
}
331
332
return $settings;
333
}
334
+
335
/**
336
* Generate the description for the template settings
337
*/
338
+ public function get_template_description() {
339
$description = '';
340
$args = array(
341
'post_type' => 'shop_order',
343
'posts_per_page' => 1
344
);
345
$query = new WP_Query( $args );
346
+
347
+ // show template preview links when an order is available
348
if( $query->have_posts() ) {
349
$results = $query->get_posts();
350
$test_id = $results[0]->ID;
351
$invoice_url = wcdn_get_print_link( $test_id, 'invoice' );
352
$delivery_note_url = wcdn_get_print_link( $test_id, 'delivery-note' );
353
$receipt_url = wcdn_get_print_link( $test_id, 'receipt' );
354
+ $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', '' );
355
}
356
+
357
return $description;
358
}
359
+
360
/**
361
* Generate the options for the template styles field
362
*/
363
public function get_options_styles() {
364
$options = array();
365
+
366
foreach( WooCommerce_Delivery_Notes_Print::$template_styles as $template_style ) {
367
if( is_array( $template_style ) && isset( $template_style['type'] ) && isset( $template_style['name'] ) ) {
368
$options[$template_style['type']] = $template_style['name'];
369
}
370
}
371
+
372
return $options;
373
}
374
+
375
/**
376
* Load image with ajax
377
*/
381
die();
382
}
383
384
+ // Verify the id
385
+ if( empty( $_POST['attachment_id'] ) && is_numeric( $_POST['attachment_id'] ) ) {
386
die();
387
}
388
+
389
+ $wdn_image_attachmnet_id = sanitize_text_field( $_POST['attachment_id'] );
390
// create the image
391
+ $this->create_image( $wdn_image_attachmnet_id );
392
+
393
exit;
394
}
395
+
396
/**
397
* Create image
398
*/
402
if( ( $attachment_src[1] / $attachment_src[2] ) < 1 ) {
403
$orientation = 'portrait';
404
}
405
+
406
?>
407
<img src="<?php echo $attachment_src[0]; ?>" class="<?php echo $orientation; ?>" alt="" />
408
<?php
409
}
410
+
411
/**
412
* Output image select field
413
*/
416
if ( ! isset( $value['title_select'] ) ) {
417
$value['title_select'] = __( 'Select', 'woocommerce-delivery-notes' );
418
}
419
+
420
if ( ! isset( $value['title_remove'] ) ) {
421
$value['title_remove'] = __( 'Remove', 'woocommerce-delivery-notes' );
422
}
423
+
424
// Get additional data fields
425
$field = WC_Admin_Settings::get_field_description( $value );
426
$description = $field['description'];
427
$tooltip_html = $field['tooltip_html'];
428
$option_value = WC_Admin_Settings::get_option( $value['id'], $value['default'] );
429
$class_name = 'wcdn-image-select';
430
+
431
?><tr valign="top">
432
+
433
+
434
<th scope="row" class="titledesc">
435
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?> <?php echo $tooltip_html; ?></label>
436
</th>
437
<td class="forminp image_width_settings">
438
<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'] ); ?>" />
439
+
440
<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'] ); ?>">
441
<span id="<?php echo esc_attr( $value['id'] ); ?>_spinner" class="<?php echo $class_name; ?>-spinner spinner"></span>
442
<div id="<?php echo esc_attr( $value['id'] ); ?>_attachment" class="<?php echo $class_name; ?>-attachment <?php echo esc_attr( $value['class'] ); ?> ">
448
</div>
449
</div>
450
</div>
451
+
452
<div id="<?php echo esc_attr( $value['id'] ); ?>_buttons" class="<?php echo $class_name; ?>-buttons <?php echo esc_attr( $value['class'] ); ?>">
453
<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">
454
<?php echo esc_html( $value['title_remove'] ); ?>
456
<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'] ); ?>">
457
<?php echo esc_html( $value['title_select'] ); ?>
458
</a>
459
+ </div>
460
</div>
461
+
462
<?php echo $description; ?>
463
</td>
464
</tr><?php
465
}
466
+
467
/**
468
* Merge array at given position
469
+ */
470
public function array_merge_at( $array, $insert, $position ) {
471
$new_array = array();
472
// if pos is start, just merge them
486
return $new_array;
487
}
488
}
489
+
490
}
491
492
+ ?>
includes/class-wcdn-theme.php CHANGED
@@ -4,7 +4,7 @@
4
* Exit if accessed directly
5
*/
6
if ( !defined( 'ABSPATH' ) ) {
7
- exit;
8
}
9
10
/**
@@ -13,20 +13,20 @@ if ( !defined( 'ABSPATH' ) ) {
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
-
25
/**
26
- * Load the hooks at the end when
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' ) );
@@ -43,49 +43,52 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Theme' ) ) {
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
$actions['print'] = array(
55
- 'url' => wcdn_get_print_link( $order->id, $this->get_template_type( $order ) ),
56
'name' => __( 'Print', 'woocommerce-delivery-notes' )
57
);
58
- }
59
return $actions;
60
}
61
-
62
/**
63
* Create a print button for the 'View Order' page
64
*/
65
public function create_print_button_order_page( $order_id ) {
66
$order = new WC_Order( $order_id );
67
-
68
// Output the button only when the option is enabled
69
- if( get_option( 'wcdn_print_button_on_view_order_page' ) == 'yes' ) {
70
- // Default button for all pages and logged in users
71
$print_url = wcdn_get_print_link( $order_id, $this->get_template_type( $order ) );
72
-
73
- // Pass the email to the url for the tracking
74
// and thank you page. This allows to view the
75
// print page without logging in.
76
if( $this->is_woocommerce_tracking_page() ) {
77
- $print_url = wcdn_get_print_link( $order_id, $this->get_template_type( $order ), $_REQUEST['order_email'] );
78
}
79
-
80
// Thank you page
81
if( is_order_received_page() && !is_user_logged_in() ) {
82
// Don't output the butten when there is no email
83
- if( !$order->billing_email ) {
84
return;
85
}
86
- $print_url = wcdn_get_print_link( $order_id, $this->get_template_type( $order ), $order->billing_email );
87
}
88
-
89
?>
90
<p class="order-print">
91
<a href="<?php echo $print_url; ?>" class="button print"><?php _e( 'Print', 'woocommerce-delivery-notes' ); ?></a>
@@ -93,49 +96,56 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Theme' ) ) {
93
<?php
94
}
95
}
96
-
97
/**
98
* Add a print url to the emails that are sent to the customer
99
- */
100
public function add_email_print_url( $order, $sent_to_admin = true, $plain_text = false ) {
101
- if( get_option( 'wcdn_email_print_link' ) == 'yes' ) {
102
- if( $order->billing_email && !$sent_to_admin ) {
103
- $url = wcdn_get_print_link( $order->id, $this->get_template_type( $order ), $order->billing_email, true );
104
-
105
if( $plain_text ) :
106
echo __( 'Print your order', 'woocommerce-delivery-notes' ) . "\n\n";
107
108
echo $url . "\n";
109
-
110
echo "\n****************************************************\n\n";
111
else : ?>
112
- <p><strong><?php _e( 'Print:', 'woocommerce-delivery-notes' ); ?></strong> <a href="<?php echo $url; ?>"><?php _e( 'Open print view in browser', 'woocommerce-delivery-notes' ); ?></a></p>
113
- <?php endif;
114
}
115
}
116
}
117
-
118
/**
119
* Get the print button template type depnding on order status
120
*/
121
public function get_template_type( $order ) {
122
- if( $order->status == 'completed' ) {
123
$type = apply_filters( 'wcdn_theme_print_button_template_type_complete_status', 'invoice' );
124
} else {
125
$type = apply_filters( 'wcdn_theme_print_button_template_type', 'order' );
126
- }
127
return $type;
128
}
129
-
130
/**
131
* Is WooCommerce 'Order Tracking' page
132
*/
133
public function is_woocommerce_tracking_page() {
134
return ( is_page( wc_get_page_id( 'order_tracking' ) ) && isset( $_REQUEST['order_email'] ) ) ? true : false;
135
}
136
-
137
}
138
139
}
140
141
- ?>
4
* Exit if accessed directly
5
*/
6
if ( !defined( 'ABSPATH' ) ) {
7
+ exit;
8
}
9
10
/**
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
+
25
/**
26
+ * Load the hooks at the end when
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' ) );
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 );
90
}
91
+
92
?>
93
<p class="order-print">
94
<a href="<?php echo $print_url; ?>" class="button print"><?php _e( 'Print', 'woocommerce-delivery-notes' ); ?></a>
96
<?php
97
}
98
}
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
}
123
}
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
+
140
/**
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
+ ?>
includes/class-wcdn-writepanel.php CHANGED
@@ -4,7 +4,7 @@
4
* Exit if accessed directly
5
*/
6
if ( !defined( 'ABSPATH' ) ) {
7
- exit;
8
}
9
10
/**
@@ -13,7 +13,7 @@ if ( !defined( 'ABSPATH' ) ) {
13
if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
14
15
class WooCommerce_Delivery_Notes_Writepanel {
16
-
17
/**
18
* Constructor
19
*/
@@ -25,12 +25,12 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
25
/**
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' ) );
33
-
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' ) );
@@ -47,73 +47,75 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
47
wp_enqueue_style( 'woocommerce-delivery-notes-admin', WooCommerce_Delivery_Notes::$plugin_url . 'css/admin.css' );
48
}
49
}
50
-
51
/**
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
-
62
/**
63
* Is order edit page
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;
71
}
72
- }
73
-
74
/**
75
* Is order edit page
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;
83
}
84
- }
85
-
86
/**
87
* Add print actions to the orders listing
88
*/
89
public function add_listing_actions( $order ) {
90
?>
91
<?php foreach( WooCommerce_Delivery_Notes_Print::$template_registrations as $template_registration ) : ?>
92
<?php if( get_option( 'wcdn_template_type_' . $template_registration['type'] ) == 'yes' && $template_registration['type'] !== 'order' ) : ?>
93
-
94
- <a href="<?php echo wcdn_get_print_link( $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' ) ); ?>">
95
<?php _e( $template_registration['labels']['print'], 'woocommerce-delivery-notes' ); ?>
96
</a>
97
-
98
<?php endif; ?>
99
<?php endforeach; ?>
100
101
<span class="print-preview-loading spinner"></span>
102
<?php
103
}
104
-
105
/**
106
* Add bulk actions with javascript to the dropdown.
107
* This is not so pretty but WordPress does not yet
108
- * offer any better solution. The JS code is inline
109
- * because we can't determine the page without
110
* checking the post_type.
111
* https://core.trac.wordpress.org/ticket/16031
112
*/
113
public function add_bulk_actions() {
114
if( $this->is_order_edit_page() ) : ?>
115
<script type="text/javascript">
116
- jQuery(document).ready(function($) {
117
<?php foreach( WooCommerce_Delivery_Notes_Print::$template_registrations as $template_registration ) : ?>
118
<?php if( get_option( 'wcdn_template_type_' . $template_registration['type'] ) == 'yes' && $template_registration['type'] !== 'order' ) : ?>
119
@@ -126,7 +128,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
126
</script>
127
<?php endif;
128
}
129
-
130
/**
131
* Add bulk print actions to the orders listing
132
*/
@@ -135,12 +137,12 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
135
// get the action staht should be started
136
$wp_list_table = _get_list_table('WP_Posts_List_Table');
137
$action = $wp_list_table->current_action();
138
-
139
// stop if there are no post ids
140
if( !isset( $_REQUEST['post'] ) ) {
141
return;
142
}
143
-
144
// only for specified actions
145
foreach( WooCommerce_Delivery_Notes_Print::$template_registrations as $template_registration ) {
146
if( $action == 'wcdn_print_' . $template_registration['type'] ) {
@@ -152,22 +154,22 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
152
if( !isset( $report_action ) ) {
153
return;
154
}
155
-
156
// security check
157
check_admin_referer('bulk-posts');
158
-
159
// get referrer
160
if( !wp_get_referer() ) {
161
return;
162
}
163
-
164
// filter the referer args
165
$referer_args = array();
166
parse_str( parse_url( wp_get_referer(), PHP_URL_QUERY ), $referer_args );
167
-
168
// set the basic args for the sendback
169
$args = array(
170
- 'post_type' => $referer_args['post_type']
171
);
172
if( isset( $referer_args['post_status'] ) ) {
173
$args = wp_parse_args( array( 'post_status' => $referer_args['post_status'] ), $args );
@@ -186,7 +188,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
186
$post_ids = array_map( 'absint', (array) $_REQUEST['post'] );
187
$total = count( $post_ids );
188
$url = wcdn_get_print_link( $post_ids , $template_type );
189
-
190
// generate more args and the sendback string
191
$args = wp_parse_args( array( $report_action => true, 'total' => $total, 'print_url' => urlencode( $url ) ), $args );
192
$sendback = add_query_arg( $args, '' );
@@ -194,7 +196,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
194
exit;
195
}
196
}
197
-
198
/**
199
* Show confirmation message that orders are printed
200
*/
@@ -209,12 +211,13 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
209
} else {
210
$message = $template_registration['labels']['message_plural'];
211
}
212
?>
213
-
214
<div id="woocommerce-delivery-notes-bulk-print-message" class="updated">
215
- <p><?php _e( $message, 'woocommerce-delivery-notes' ); ?> <a href="<?php echo urldecode( $_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>
216
</div>
217
-
218
<?php
219
break;
220
}
@@ -238,31 +241,31 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
238
<div class="print-actions">
239
<?php foreach( WooCommerce_Delivery_Notes_Print::$template_registrations as $template_registration ) : ?>
240
<?php if( get_option( 'wcdn_template_type_' . $template_registration['type'] ) == 'yes' && $template_registration['type'] !== 'order' ) : ?>
241
-
242
<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>
243
-
244
<?php endif; ?>
245
<?php endforeach; ?>
246
<span class="print-preview-loading spinner"></span>
247
</div>
248
- <?php
249
$create_invoice_number = get_option( 'wcdn_create_invoice_number' );
250
$has_invoice_number = get_post_meta( $post_id, '_wcdn_invoice_number', true );
251
- if( !empty( $create_invoice_number ) && $create_invoice_number == 'yes' && $has_invoice_number ) :
252
$invoice_number = wcdn_get_order_invoice_number( $post_id );
253
$invoice_date = wcdn_get_order_invoice_date( $post_id ); ?>
254
-
255
<ul class="print-info">
256
<li><strong><?php _e( 'Invoice number: ', 'woocommerce-delivery-notes' ); ?></strong> <?php echo $invoice_number; ?></li>
257
<li><strong><?php _e( 'Invoice date: ', 'woocommerce-delivery-notes' ); ?></strong> <?php echo $invoice_date; ?></li>
258
</ul>
259
-
260
<?php endif; ?>
261
<?php
262
}
263
-
264
}
265
-
266
}
267
268
- ?>
4
* Exit if accessed directly
5
*/
6
if ( !defined( 'ABSPATH' ) ) {
7
+ exit;
8
}
9
10
/**
13
if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
14
15
class WooCommerce_Delivery_Notes_Writepanel {
16
+
17
/**
18
* Constructor
19
*/
25
/**
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' ) );
33
+
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' ) );
47
wp_enqueue_style( 'woocommerce-delivery-notes-admin', WooCommerce_Delivery_Notes::$plugin_url . 'css/admin.css' );
48
}
49
}
50
+
51
/**
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
+
62
/**
63
* Is order edit page
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;
71
}
72
+ }
73
+
74
/**
75
* Is order edit page
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;
83
}
84
+ }
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
103
<span class="print-preview-loading spinner"></span>
104
<?php
105
}
106
+
107
/**
108
* Add bulk actions with javascript to the dropdown.
109
* This is not so pretty but WordPress does not yet
110
+ * offer any better solution. The JS code is inline
111
+ * because we can't determine the page without
112
* checking the post_type.
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
128
</script>
129
<?php endif;
130
}
131
+
132
/**
133
* Add bulk print actions to the orders listing
134
*/
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'] ) {
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 );
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, '' );
196
exit;
197
}
198
}
199
+
200
/**
201
* Show confirmation message that orders are printed
202
*/
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
222
break;
223
}
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; ?>
264
<?php
265
}
266
+
267
}
268
+
269
}
270
271
+ ?>
includes/wcdn-template-functions.php CHANGED
@@ -1,530 +1,551 @@
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
- }
20
-
21
- /**
22
- * Return Type of the print template
23
- */
24
- function wcdn_get_template_type() {
25
- global $wcdn;
26
- return apply_filters( 'wcdn_template_type', $wcdn->print->template['type'] );
27
- }
28
-
29
- /**
30
- * Return Title of the print template
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;
42
- return $wcdn->print->get_print_page_url( $order_ids, $template_type, $order_email, $permalink );
43
- }
44
-
45
- /**
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
- /**
53
- * Output the print navigation style
54
- */
55
- function wcdn_navigation_style() {
56
- ?>
57
- <style>
58
- #navigation {
59
- font-family: sans-serif;
60
- background-color: #f1f1f1;
61
- z-index: 200;
62
- border-bottom: 1px solid #dfdfdf;
63
- left: 0;
64
- right: 0;
65
- bottom: 0;
66
- position: fixed;
67
- padding: 6px 8px;
68
- text-align: right;
69
- }
70
-
71
- #navigation .button {
72
- transition-property: border, background, color;
73
- display: inline-block;
74
- font-size: 13px;
75
- line-height: 26px;
76
- height: 28px;
77
- margin: 0;
78
- padding: 0 10px 1px;
79
- cursor: pointer;
80
- border-width: 1px;
81
- border-style: solid;
82
- -webkit-border-radius: 3px;
83
- -webkit-appearance: none;
84
- border-radius: 3px;
85
- white-space: nowrap;
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;
110
- color: rgba(255,255,255,0.95);
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;
118
- }
119
- }
120
- </style>
121
- <?php
122
- }
123
-
124
- /**
125
- * Create print navigation
126
- */
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
- }
134
-
135
- /**
136
- * Output template stylesheet
137
- */
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
- /**
163
- * Return logo id
164
- */
165
- function wcdn_get_company_logo_id() {
166
- global $wcdn;
167
- return apply_filters( 'wcdn_company_logo_id', get_option( 'wcdn_company_logo_image_id' ) );
168
- }
169
-
170
- /**
171
- * Show logo html
172
- */
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
-
201
- /**
202
- * Return shop/company info if provided
203
- */
204
- function wcdn_company_info() {
205
- global $wcdn;
206
- echo stripslashes( wpautop( wptexturize( get_option( 'wcdn_company_address' ) ) ) );
207
- }
208
-
209
- /**
210
- * Get orders as array. Every order is a normal WC_Order instance.
211
- */
212
- function wcdn_get_orders() {
213
- global $wcdn;
214
- return $wcdn->print->orders;
215
- }
216
-
217
- /**
218
- * Get an order
219
- */
220
- function wcdn_get_order( $order_id ) {
221
- global $wcdn;
222
- return $wcdn->print->get_order( $order_id );
223
- }
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
- if( wcdn_get_template_type() == 'invoice' && !empty( $create_invoice_number ) && $create_invoice_number == 'yes' ) {
234
- $fields['invoice_number'] = array(
235
- 'label' => __( 'Invoice Number', 'woocommerce-delivery-notes' ),
236
- 'value' => wcdn_get_order_invoice_number( $order->id )
237
- );
238
- }
239
-
240
- if( wcdn_get_template_type() == 'invoice' ) {
241
- $fields['invoice_date'] = array(
242
- 'label' => __( 'Invoice Date', 'woocommerce-delivery-notes' ),
243
- 'value' => wcdn_get_order_invoice_date( $order->id )
244
- );
245
- }
246
-
247
- $fields['order_number'] = array(
248
- 'label' => __( 'Order Number', 'woocommerce-delivery-notes' ),
249
- 'value' => $order->get_order_number()
250
- );
251
-
252
- $fields['order_date'] = array(
253
- 'label' => __( 'Order Date', 'woocommerce-delivery-notes' ),
254
- 'value' => date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) )
255
- );
256
-
257
- $fields['payment_method'] = array(
258
- 'label' => __( 'Payment Method', 'woocommerce-delivery-notes' ),
259
- 'value' => __( $order->payment_method_title, 'woocommerce' )
260
- );
261
-
262
- if( $order->billing_email ) {
263
- $fields['billing_email'] = array(
264
- 'label' => __( 'Email', 'woocommerce-delivery-notes' ),
265
- 'value' => $order->billing_email
266
- );
267
- }
268
-
269
- if( $order->billing_phone ) {
270
- $fields['billing_phone'] = array(
271
- 'label' => __( 'Telephone', 'woocommerce-delivery-notes' ),
272
- 'value' => $order->billing_phone
273
- );
274
- }
275
-
276
- return $fields;
277
- }
278
-
279
- /**
280
- * Get the invoice number of an order
281
- */
282
- function wcdn_get_order_invoice_number( $order_id ) {
283
- global $wcdn;
284
- return $wcdn->print->get_order_invoice_number( $order_id );
285
- }
286
-
287
- /**
288
- * Get the invoice date of an order
289
- */
290
- function wcdn_get_order_invoice_date( $order_id ) {
291
- global $wcdn;
292
- return $wcdn->print->get_order_invoice_date( $order_id );
293
- }
294
-
295
- /**
296
- * Additional fields for the product
297
- */
298
- function wcdn_additional_product_fields( $fields = null, $product = null, $order ) {
299
- $new_fields = array();
300
-
301
- // Stock keeping unit
302
- if( $product && $product->exists() && $product->get_sku() ) {
303
- $fields['sku'] = array(
304
- 'label' => __( 'SKU:', 'woocommerce-delivery-notes' ),
305
- 'value' => $product->get_sku()
306
- );
307
- }
308
- return array_merge( $fields, $new_fields );
309
- }
310
-
311
- /**
312
- * Check if a shipping address is enabled
313
- */
314
- function wcdn_has_shipping_address( $order ) {
315
- // Works only with WooCommerce 2.2 and higher
316
- if( version_compare( WC_VERSION, '2.2.0', '>=' ) ) {
317
- if( ! wc_ship_to_billing_address_only() && $order->needs_shipping_address() && get_option( 'woocommerce_calc_shipping' ) !== 'no' ) {
318
- return true;
319
- } else {
320
- return false;
321
- }
322
- }
323
- return true;
324
- }
325
-
326
- /**
327
- * Check if an order contains a refund
328
- */
329
- function wcdn_has_refund( $order ) {
330
- // Works only with WooCommerce 2.2 and higher
331
- if( version_compare( WC_VERSION, '2.2.0', '>=' ) ) {
332
- if( $order->get_total_refunded() ) {
333
- return true;
334
- }
335
- }
336
- return false;
337
- }
338
-
339
- /**
340
- * Gets formatted item subtotal for display.
341
- */
342
- function wcdn_get_formatted_item_price( $order, $item, $tax_display = '' ) {
343
-
344
- if ( ! $tax_display ) {
345
- $tax_display = $order->tax_display_cart;
346
- }
347
-
348
- if ( ! isset( $item['line_subtotal'] ) || ! isset( $item['line_subtotal_tax'] ) ) {
349
- return '';
350
- }
351
-
352
- if ( 'excl' == $tax_display ) {
353
- $ex_tax_label = $order->prices_include_tax ? 1 : 0;
354
-
355
- $subtotal = wc_price( $order->get_item_subtotal( $item ), array( 'ex_tax_label' => $ex_tax_label, 'currency' => $order->get_order_currency() ) );
356
- } else {
357
- $subtotal = wc_price( $order->get_item_subtotal( $item, true ), array('currency' => $order->get_order_currency()) );
358
- }
359
-
360
- return apply_filters( 'wcdn_formatted_item_price', $subtotal, $item, $order );
361
- }
362
-
363
- /**
364
- * Add refund totals
365
- */
366
- function wcdn_add_refunded_order_totals( $total_rows, $order ) {
367
- if( wcdn_has_refund( $order ) ) {
368
- if( version_compare( WC_VERSION, '2.3.0', '>=' ) ) {
369
- $refunded_tax_del = '';
370
- $refunded_tax_ins = '';
371
-
372
- // Tax for inclusive prices
373
- if ( wc_tax_enabled() && 'incl' == $order->tax_display_cart ) {
374
- $tax_del_array = array();
375
- $tax_ins_array = array();
376
-
377
- if ( 'itemized' == get_option( 'woocommerce_tax_total_display' ) ) {
378
-
379
- foreach ( $order->get_tax_totals() as $code => $tax ) {
380
- $tax_del_array[] = sprintf( '%s %s', $tax->formatted_amount, $tax->label );
381
- $tax_ins_array[] = sprintf( '%s %s', wc_price( $tax->amount - $order->get_total_tax_refunded_by_rate_id( $tax->rate_id ), array( 'currency' => $order->get_order_currency() ) ), $tax->label );
382
- }
383
-
384
- } else {
385
- $tax_del_array[] = sprintf( '%s %s', wc_price( $order->get_total_tax(), array( 'currency' => $order->get_order_currency() ) ), WC()->countries->tax_or_vat() );
386
- $tax_ins_array[] = sprintf( '%s %s', wc_price( $order->get_total_tax() - $order->get_total_tax_refunded(), array( 'currency' => $order->get_order_currency() ) ), WC()->countries->tax_or_vat() );
387
- }
388
-
389
- if ( ! empty( $tax_del_array ) ) {
390
- $refunded_tax_del .= ' ' . sprintf( __( '(Includes %s)', 'woocommerce' ), implode( ', ', $tax_del_array ) );
391
- }
392
-
393
- if ( ! empty( $tax_ins_array ) ) {
394
- $refunded_tax_ins .= ' ' . sprintf( __( '(Includes %s)', 'woocommerce' ), implode( ', ', $tax_ins_array ) );
395
- }
396
- }
397
-
398
- // use only the number for new wc versions
399
- $order_subtotal = wc_price( $order->get_total(), array( 'currency' => $order->get_order_currency() ) );
400
- } else {
401
- $refunded_tax_del = '';
402
- $refunded_tax_ins = '';
403
-
404
- // use the normal total for older wc versions
405
- $order_subtotal = $total_rows['order_total']['value'];
406
- }
407
-
408
- // Add refunded totals row
409
- $total_rows['wcdn_refunded_total'] = array(
410
- 'label' => __( 'Refund', 'woocommerce-delivery-notes' ),
411
- 'value' => wc_price( -$order->get_total_refunded(), array( 'currency' => $order->get_order_currency() ) )
412
- );
413
-
414
- // Add new order totals row
415
- $total_rows['wcdn_order_total'] = array(
416
- 'label' => $total_rows['order_total']['label'],
417
- 'value' => wc_price( $order->get_total() - $order->get_total_refunded(), array( 'currency' => $order->get_order_currency() ) ) . $refunded_tax_ins
418
- );
419
-
420
- // Edit the original order total row
421
- $total_rows['order_total'] = array(
422
- 'label' => __( 'Order Subtotal', 'woocommerce-delivery-notes' ),
423
- 'value' => $order_subtotal
424
- );
425
- }
426
-
427
- return $total_rows;
428
- }
429
-
430
- /**
431
- * Remove the semicolon from the totals
432
- */
433
- function wcdn_remove_semicolon_from_totals( $total_rows, $order ) {
434
- foreach( $total_rows as $key => $row ) {
435
- $label = $row['label'];
436
- $colon = strrpos( $label, ':' );
437
- if( $colon !== false ) {
438
- $label = substr_replace( $label, '', $colon, 1 );
439
- }
440
- $total_rows[$key]['label'] = $label;
441
- }
442
- return $total_rows;
443
- }
444
-
445
- /**
446
- * Remove the payment method text from the totals
447
- */
448
- function wcdn_remove_payment_method_from_totals( $total_rows, $order ) {
449
- unset($total_rows['payment_method']);
450
- return $total_rows;
451
- }
452
-
453
- /**
454
- * Return customer notes
455
- */
456
- function wcdn_get_customer_notes( $order ) {
457
- global $wcdn;
458
- return stripslashes( wpautop( wptexturize( $order->customer_note ) ) );
459
- }
460
-
461
- /**
462
- * Show customer notes
463
- */
464
- function wcdn_customer_notes( $order ) {
465
- global $wcdn;
466
- echo wcdn_get_customer_notes( $order );
467
- }
468
-
469
- /**
470
- * Return has customer notes
471
- */
472
- function wcdn_has_customer_notes( $order ) {
473
- global $wcdn;
474
- if( wcdn_get_customer_notes( $order ) ) {
475
- return true;
476
- } else {
477
- return false;
478
- }
479
- }
480
-
481
- /**
482
- * Return personal notes, season greetings etc.
483
- */
484
- function wcdn_get_personal_notes() {
485
- global $wcdn;
486
- return stripslashes( wpautop( wptexturize( get_option( 'wcdn_personal_notes' ) ) ) );
487
- }
488
-
489
- /**
490
- * Show personal notes, season greetings etc.
491
- */
492
- function wcdn_personal_notes() {
493
- global $wcdn;
494
- echo wcdn_get_personal_notes();
495
- }
496
-
497
- /**
498
- * Return policy for returns
499
- */
500
- function wcdn_get_policies_conditions() {
501
- global $wcdn;
502
- return stripslashes( wpautop( wptexturize( get_option( 'wcdn_policies_conditions' ) ) ) );
503
- }
504
-
505
- /**
506
- * Show policy for returns
507
- */
508
- function wcdn_policies_conditions() {
509
- global $wcdn;
510
- echo wcdn_get_policies_conditions();
511
- }
512
-
513
- /**
514
- * Return shop/company footer imprint, copyright etc.
515
- */
516
- function wcdn_get_imprint() {
517
- global $wcdn;
518
- return stripslashes( wpautop( wptexturize( get_option( 'wcdn_footer_imprint' ) ) ) );
519
- }
520
-
521
- /**
522
- * Show shop/company footer imprint, copyright etc.
523
- */
524
- function wcdn_imprint() {
525
- global $wcdn;
526
- echo wcdn_get_imprint();
527
- }
528
-
529
-
530
?>
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
+ }
20
+
21
+ /**
22
+ * Return Type of the print template
23
+ */
24
+ function wcdn_get_template_type() {
25
+ global $wcdn;
26
+ return apply_filters( 'wcdn_template_type', $wcdn->print->template['type'] );
27
+ }
28
+
29
+ /**
30
+ * Return Title of the print template
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;
42
+ return $wcdn->print->get_print_page_url( $order_ids, $template_type, $order_email, $permalink );
43
+ }
44
+
45
+ /**
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
+ /**
53
+ * Output the print navigation style
54
+ */
55
+ function wcdn_navigation_style() {
56
+ ?>
57
+ <style>
58
+ #navigation {
59
+ font-family: sans-serif;
60
+ background-color: #f1f1f1;
61
+ z-index: 200;
62
+ border-bottom: 1px solid #dfdfdf;
63
+ left: 0;
64
+ right: 0;
65
+ bottom: 0;
66
+ position: fixed;
67
+ padding: 6px 8px;
68
+ text-align: right;
69
+ }
70
+
71
+ #navigation .button {
72
+ transition-property: border, background, color;
73
+ display: inline-block;
74
+ font-size: 13px;
75
+ line-height: 26px;
76
+ height: 28px;
77
+ margin: 0;
78
+ padding: 0 10px 1px;
79
+ cursor: pointer;
80
+ border-width: 1px;
81
+ border-style: solid;
82
+ -webkit-border-radius: 3px;
83
+ -webkit-appearance: none;
84
+ border-radius: 3px;
85
+ white-space: nowrap;
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;
110
+ color: rgba(255,255,255,0.95);
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;
118
+ }
119
+ }
120
+ </style>
121
+ <?php
122
+ }
123
+
124
+ /**
125
+ * Create print navigation
126
+ */
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
+ }
134
+
135
+ /**
136
+ * Output template stylesheet
137
+ */
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
+ /**
163
+ * Return logo id
164
+ */
165
+ function wcdn_get_company_logo_id() {
166
+ global $wcdn;
167
+ return apply_filters( 'wcdn_company_logo_id', get_option( 'wcdn_company_logo_image_id' ) );
168
+ }
169
+
170
+ /**
171
+ * Show logo html
172
+ */
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
+
201
+ /**
202
+ * Return shop/company info if provided
203
+ */
204
+ function wcdn_company_info() {
205
+ global $wcdn;
206
+ echo stripslashes( wpautop( wptexturize( get_option( 'wcdn_company_address' ) ) ) );
207
+ }
208
+
209
+ /**
210
+ * Get orders as array. Every order is a normal WC_Order instance.
211
+ */
212
+ function wcdn_get_orders() {
213
+ global $wcdn;
214
+ return $wcdn->print->orders;
215
+ }
216
+
217
+ /**
218
+ * Get an order
219
+ */
220
+ function wcdn_get_order( $order_id ) {
221
+ global $wcdn;
222
+ return $wcdn->print->get_order( $order_id );
223
+ }
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;
295
+ return $wcdn->print->get_order_invoice_number( $order_id );
296
+ }
297
+
298
+ /**
299
+ * Get the invoice date of an order
300
+ */
301
+ function wcdn_get_order_invoice_date( $order_id ) {
302
+ global $wcdn;
303
+ return $wcdn->print->get_order_invoice_