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 | 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 +90 -81
- includes/class-wcdn-settings.php +91 -88
- includes/class-wcdn-theme.php +48 -38
- includes/class-wcdn-writepanel.php +46 -43
- includes/wcdn-template-functions.php +550 -529
- readme.md +0 -2
- readme.txt +71 -17
- templates/print-order/print-content.php +211 -172
- woocommerce-delivery-notes.php +6 -6
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 |
-
|
|
|
|
|
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 |
-
|
|
|
|
|
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 |
-
|
392 |
-
|
|
|
393 |
$this->orders = null;
|
394 |
return false;
|
395 |
-
}
|
|
|
|
|
396 |
|
397 |
-
|
398 |
-
|
|
|
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( $
|
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( $
|
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 |
-
|
|
|
|
|
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( !$
|
84 |
return;
|
85 |
}
|
86 |
-
$print_url = wcdn_get_print_link( $order_id, $this->get_template_type( $order ), $
|
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 |
-
|
103 |
-
|
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 |
-
|
113 |
-
|
|
|
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 |
-
|
|
|
|
|
|
|
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( $
|
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 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
'
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
}
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
}
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
$
|
356 |
-
}
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
$total_rows[
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
530 |
?>
|
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_date( $order_id );
|
304 |
+
}
|
305 |
+
|
306 |
+
/**
|
307 |
+
* Additional fields for the product
|
308 |
+
*/
|
309 |
+
function wcdn_additional_product_fields( $fields = null, $product = null, $order ) {
|
310 |
+
$new_fields = array();
|
311 |
+
|
312 |
+
// Stock keeping unit
|
313 |
+
if( $product && $product->exists() && $product->get_sku() ) {
|
314 |
+
$fields['sku'] = array(
|
315 |
+
'label' => __( 'SKU:', 'woocommerce-delivery-notes' ),
|
316 |
+
'value' => $product->get_sku()
|
317 |
+
);
|
318 |
+
}
|
319 |
+
return array_merge( $fields, $new_fields );
|
320 |
+
}
|
321 |
+
|
322 |
+
/**
|
323 |
+
* Check if a shipping address is enabled
|
324 |
+
*/
|
325 |
+
function wcdn_has_shipping_address( $order ) {
|
326 |
+
// Works only with WooCommerce 2.2 and higher
|
327 |
+
if( version_compare( WC_VERSION, '2.2.0', '>=' ) ) {
|
328 |
+
if( ! wc_ship_to_billing_address_only() && $order->needs_shipping_address() && get_option( 'woocommerce_calc_shipping' ) !== 'no' ) {
|
329 |
+
return true;
|
330 |
+
} else {
|
331 |
+
return false;
|
332 |
+
}
|
333 |
+
}
|
334 |
+
return true;
|
335 |
+
}
|
336 |
+
|
337 |
+
/**
|
338 |
+
* Check if an order contains a refund
|
339 |
+
*/
|
340 |
+
function wcdn_has_refund( $order ) {
|
341 |
+
// Works only with WooCommerce 2.2 and higher
|
342 |
+
if( version_compare( WC_VERSION, '2.2.0', '>=' ) ) {
|
343 |
+
if( $order->get_total_refunded() ) {
|
344 |
+
return true;
|
345 |
+
}
|
346 |
+
}
|
347 |
+
return false;
|
348 |
+
}
|
349 |
+
|
350 |
+
/**
|
351 |
+
* Gets formatted item subtotal for display.
|
352 |
+
*/
|
353 |
+
function wcdn_get_formatted_item_price( $order, $item, $tax_display = '' ) {
|
354 |
+
if ( ! $tax_display ) {
|
355 |
+
$tax_display = get_option( 'woocommerce_tax_display_cart' );
|
356 |
+
}
|
357 |
+
|
358 |
+
if ( ! isset( $item['line_subtotal'] ) || ! isset( $item['line_subtotal_tax'] ) ) {
|
359 |
+
return '';
|
360 |
+
}
|
361 |
+
|
362 |
+
$wdn_order_currency = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_currency() : $order->get_order_currency();
|
363 |
+
|
364 |
+
if ( 'excl' == $tax_display ) {
|
365 |
+
if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ){
|
366 |
+
$ex_tax_label = wc_prices_include_tax() ? 1 : 0;
|
367 |
+
}else{
|
368 |
+
$ex_tax_label = $order->prices_include_tax ? 1 : 0;
|
369 |
+
}
|
370 |
+
|
371 |
+
|
372 |
+
$subtotal = wc_price( $order->get_item_subtotal( $item ), array( 'ex_tax_label' => $ex_tax_label, 'currency' => $wdn_order_currency ) );
|
373 |
+
} else {
|
374 |
+
$subtotal = wc_price( $order->get_item_subtotal( $item, true ), array('currency' => $wdn_order_currency ) );
|
375 |
+
}
|
376 |
+
|
377 |
+
return apply_filters( 'wcdn_formatted_item_price', $subtotal, $item, $order );
|
378 |
+
}
|
379 |
+
|
380 |
+
/**
|
381 |
+
* Add refund totals
|
382 |
+
*/
|
383 |
+
function wcdn_add_refunded_order_totals( $total_rows, $order ) {
|
384 |
+
if( wcdn_has_refund( $order ) ) {
|
385 |
+
$wdn_order_currency = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_currency() : $order->get_order_currency();
|
386 |
+
|
387 |
+
if( version_compare( WC_VERSION, '2.3.0', '>=' ) ) {
|
388 |
+
$refunded_tax_del = '';
|
389 |
+
$refunded_tax_ins = '';
|
390 |
+
|
391 |
+
// Tax for inclusive prices
|
392 |
+
if ( wc_tax_enabled() && 'incl' == $order->tax_display_cart ) {
|
393 |
+
$tax_del_array = array();
|
394 |
+
$tax_ins_array = array();
|
395 |
+
|
396 |
+
if ( 'itemized' == get_option( 'woocommerce_tax_total_display' ) ) {
|
397 |
+
|
398 |
+
foreach ( $order->get_tax_totals() as $code => $tax ) {
|
399 |
+
$tax_del_array[] = sprintf( '%s %s', $tax->formatted_amount, $tax->label );
|
400 |
+
$tax_ins_array[] = sprintf( '%s %s', wc_price( $tax->amount - $order->get_total_tax_refunded_by_rate_id( $tax->rate_id ), array( 'currency' => $wdn_order_currency ) ), $tax->label );
|
401 |
+
}
|
402 |
+
|
403 |
+
} else {
|
404 |
+
$tax_del_array[] = sprintf( '%s %s', wc_price( $order->get_total_tax(), array( 'currency' => $wdn_order_currency ) ), WC()->countries->tax_or_vat() );
|
405 |
+
$tax_ins_array[] = sprintf( '%s %s', wc_price( $order->get_total_tax() - $order->get_total_tax_refunded(), array( 'currency' => $wdn_order_currency ) ), WC()->countries->tax_or_vat() );
|
406 |
+
}
|
407 |
+
|
408 |
+
if ( ! empty( $tax_del_array ) ) {
|
409 |
+
$refunded_tax_del .= ' ' . sprintf( __( '(Includes %s)', 'woocommerce' ), implode( ', ', $tax_del_array ) );
|
410 |
+
}
|
411 |
+
|
412 |
+
if ( ! empty( $tax_ins_array ) ) {
|
413 |
+
$refunded_tax_ins .= ' ' . sprintf( __( '(Includes %s)', 'woocommerce' ), implode( ', ', $tax_ins_array ) );
|
414 |
+
}
|
415 |
+
}
|
416 |
+
|
417 |
+
// use only the number for new wc versions
|
418 |
+
$order_subtotal = wc_price( $order->get_total(), array( 'currency' => $wdn_order_currency ) );
|
419 |
+
} else {
|
420 |
+
$refunded_tax_del = '';
|
421 |
+
$refunded_tax_ins = '';
|
422 |
+
|
423 |
+
// use the normal total for older wc versions
|
424 |
+
$order_subtotal = $total_rows['order_total']['value'];
|
425 |
+
}
|
426 |
+
|
427 |
+
// Add refunded totals row
|
428 |
+
$total_rows['wcdn_refunded_total'] = array(
|
429 |
+
'label' => __( 'Refund', 'woocommerce-delivery-notes' ),
|
430 |
+
'value' => wc_price( -$order->get_total_refunded(), array( 'currency' => $wdn_order_currency ) )
|
431 |
+
);
|
432 |
+
|
433 |
+
// Add new order totals row
|
434 |
+
$total_rows['wcdn_order_total'] = array(
|
435 |
+
'label' => $total_rows['order_total']['label'],
|
436 |
+
'value' => wc_price( $order->get_total() - $order->get_total_refunded(), array( 'currency' => $wdn_order_currency ) ) . $refunded_tax_ins
|
437 |
+
);
|
438 |
+
|
439 |
+
// Edit the original order total row
|
440 |
+
$total_rows['order_total'] = array(
|
441 |
+
'label' => __( 'Order Subtotal', 'woocommerce-delivery-notes' ),
|
442 |
+
'value' => $order_subtotal
|
443 |
+
);
|
444 |
+
}
|
445 |
+
|
446 |
+
return $total_rows;
|
447 |
+
}
|
448 |
+
|
449 |
+
/**
|
450 |
+
* Remove the semicolon from the totals
|
451 |
+
*/
|
452 |
+
function wcdn_remove_semicolon_from_totals( $total_rows, $order ) {
|
453 |
+
foreach( $total_rows as $key => $row ) {
|
454 |
+
$label = $row['label'];
|
455 |
+
$colon = strrpos( $label, ':' );
|
456 |
+
if( $colon !== false ) {
|
457 |
+
$label = substr_replace( $label, '', $colon, 1 );
|
458 |
+
}
|
459 |
+
$total_rows[$key]['label'] = $label;
|
460 |
+
}
|
461 |
+
return $total_rows;
|
462 |
+
}
|
463 |
+
|
464 |
+
/**
|
465 |
+
* Remove the payment method text from the totals
|
466 |
+
*/
|
467 |
+
function wcdn_remove_payment_method_from_totals( $total_rows, $order ) {
|
468 |
+
unset($total_rows['payment_method']);
|
469 |
+
return $total_rows;
|
470 |
+
}
|
471 |
+
|
472 |
+
/**
|
473 |
+
* Return customer notes
|
474 |
+
*/
|
475 |
+
function wcdn_get_customer_notes( $order ) {
|
476 |
+
global $wcdn;
|
477 |
+
|
478 |
+
$wdn_order_customer_notes = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_customer_note() : $order->customer_note;
|
479 |
+
return stripslashes( wpautop( wptexturize( $wdn_order_customer_notes ) ) );
|
480 |
+
}
|
481 |
+
|
482 |
+
/**
|
483 |
+
* Show customer notes
|
484 |
+
*/
|
485 |
+
function wcdn_customer_notes( $order ) {
|
486 |
+
global $wcdn;
|
487 |
+
echo wcdn_get_customer_notes( $order );
|
488 |
+
}
|
489 |
+
|
490 |
+
/**
|
491 |
+
* Return has customer notes
|
492 |
+
*/
|
493 |
+
function wcdn_has_customer_notes( $order ) {
|
494 |
+
global $wcdn;
|
495 |
+
if( wcdn_get_customer_notes( $order ) ) {
|
496 |
+
return true;
|
497 |
+
} else {
|
498 |
+
return false;
|
499 |
+
}
|
500 |
+
}
|
501 |
+
|
502 |
+
/**
|
503 |
+
* Return personal notes, season greetings etc.
|
504 |
+
*/
|
505 |
+
function wcdn_get_personal_notes() {
|
506 |
+
global $wcdn;
|
507 |
+
return stripslashes( wpautop( wptexturize( get_option( 'wcdn_personal_notes' ) ) ) );
|
508 |
+
}
|
509 |
+
|
510 |
+
/**
|
511 |
+
* Show personal notes, season greetings etc.
|
512 |
+
*/
|
513 |
+
function wcdn_personal_notes() {
|
514 |
+
global $wcdn;
|
515 |
+
echo wcdn_get_personal_notes();
|
516 |
+
}
|
517 |
+
|
518 |
+
/**
|
519 |
+
* Return policy for returns
|
520 |
+
*/
|
521 |
+
function wcdn_get_policies_conditions() {
|
522 |
+
global $wcdn;
|
523 |
+
return stripslashes( wpautop( wptexturize( get_option( 'wcdn_policies_conditions' ) ) ) );
|
524 |
+
}
|
525 |
+
|
526 |
+
/**
|
527 |
+
* Show policy for returns
|
528 |
+
*/
|
529 |
+
function wcdn_policies_conditions() {
|
530 |
+
global $wcdn;
|
531 |
+
echo wcdn_get_policies_conditions();
|
532 |
+
}
|
533 |
+
|
534 |
+
/**
|
535 |
+
* Return shop/company footer imprint, copyright etc.
|
536 |
+
*/
|
537 |
+
function wcdn_get_imprint() {
|
538 |
+
global $wcdn;
|
539 |
+
return stripslashes( wpautop( wptexturize( get_option( 'wcdn_footer_imprint' ) ) ) );
|
540 |
+
}
|
541 |
+
|
542 |
+
/**
|
543 |
+
* Show shop/company footer imprint, copyright etc.
|
544 |
+
*/
|
545 |
+
function wcdn_imprint() {
|
546 |
+
global $wcdn;
|
547 |
+
echo wcdn_get_imprint();
|
548 |
+
}
|
549 |
+
|
550 |
+
|
551 |
?>
|
readme.md
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
-
> Announcement: The development of this plugin has been ceased. Thanks to everybody for their support throughout the years. Please contact me on GitHub if you want to take over the project.
|
2 |
-
|
3 |
# WooCommerce Print Invoice & Delivery Note
|
4 |
|
5 |
This is the WooCommerce Print Invoice & Delivery Note repository on GitHub. Here you can browse the source, look at open issues and keep track of development.
|
|
|
|
|
1 |
# WooCommerce Print Invoice & Delivery Note
|
2 |
|
3 |
This is the WooCommerce Print Invoice & Delivery Note repository on GitHub. Here you can browse the source, look at open issues and keep track of development.
|
readme.txt
CHANGED
@@ -1,11 +1,12 @@
|
|
1 |
-
=== WooCommerce Print Invoice & Delivery Note ===
|
2 |
|
3 |
-
Contributors:
|
4 |
-
Donate link: https://www.paypal.
|
5 |
Tags: delivery note, packing slip, invoice, delivery, shipping, print, order, woocommerce, woothemes, shop
|
6 |
Requires at least: 4.0
|
7 |
-
Tested up to: 4.
|
8 |
-
|
|
|
9 |
License: GPLv3 or later
|
10 |
License URI: http://www.opensource.org/licenses/gpl-license.php
|
11 |
|
@@ -13,16 +14,13 @@ Print invoices and delivery notes for WooCommerce orders.
|
|
13 |
|
14 |
== Description ==
|
15 |
|
16 |
-
= Announcement:
|
17 |
|
18 |
|
19 |
-
|
20 |
-
You can print out invoices and delivery notes for the [WooCommerce](http://wordpress.org/plugins/woocommerce/) orders. You can also edit the Company/Shop name, Company/Shop postal address and also add personal notes, conditions/policies (like a refund policy) and a footer imprint.
|
21 |
|
22 |
The plugin adds a new side panel on the order page to allow shop administrators to print out the invoice or delivery note. Registered customers can also print their order with a button that is added to the order screen.
|
23 |
|
24 |
-
Check out [WooCommerce Print Invoice & Delivery Note Pro](#) for more advanced features.
|
25 |
-
|
26 |
|
27 |
= Features =
|
28 |
|
@@ -37,7 +35,6 @@ Check out [WooCommerce Print Invoice & Delivery Note Pro](#) for more advanced f
|
|
37 |
* Supports sequential order numbers
|
38 |
* Supports the WooCommerce refund system
|
39 |
* Intelligent invoice and delivery note template system with hooks and functions.php support
|
40 |
-
* Get even more features with [WooCommerce Print Invoice & Delivery Note Pro](#)
|
41 |
|
42 |
= Support =
|
43 |
|
@@ -45,11 +42,48 @@ Support can take place in the [public support forums](http://wordpress.org/suppo
|
|
45 |
|
46 |
= Contributing =
|
47 |
|
48 |
-
If you have a patch, or stumbled upon an issue with the source code that isn't a [WooCommerce issue](https://github.com/woothemes/woocommerce/issues?labels=Bug&milestone=22&state=open), you can contribute this back [on GitHub](https://github.com/
|
49 |
|
50 |
= Translating =
|
51 |
|
52 |
-
When your language is missing you can contribute a translation to the [GitHub repository](https://github.com/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
== Installation ==
|
55 |
|
@@ -97,8 +131,8 @@ An example that changes the font and makes the addresses very large. Paste the c
|
|
97 |
`
|
98 |
function example_serif_font_and_large_address() {
|
99 |
?>
|
100 |
-
<style>
|
101 |
-
|
102 |
font-size: 1em;
|
103 |
font-family: Georgia, serif;
|
104 |
}
|
@@ -109,7 +143,7 @@ function example_serif_font_and_large_address() {
|
|
109 |
}
|
110 |
</style>
|
111 |
<?php
|
112 |
-
}
|
113 |
add_action( 'wcdn_head', 'example_serif_font_and_large_address', 20 );
|
114 |
`
|
115 |
|
@@ -281,7 +315,7 @@ The plugin uses the exact same content as WooCommerce. If the content isn't avai
|
|
281 |
|
282 |
Upload your language file to `/wp-content/languages/plugins/` (create this folder if it doesn't exist). WordPress will then load the language. Make sure you use the same locale as in your configuration and the correct plugin locale i.e. `woocommerce-delivery-notes-it_IT.mo/.po`.
|
283 |
|
284 |
-
Please [contribute your translation](https://github.com/
|
285 |
|
286 |
== Screenshots ==
|
287 |
|
@@ -296,6 +330,26 @@ Please [contribute your translation](https://github.com/piffpaffpuff/woocommerce
|
|
296 |
|
297 |
= Minimum Requirements: WooCommerce 2.2 =
|
298 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
299 |
= 4.2.0 =
|
300 |
|
301 |
* Tweak - Refactored settings screen
|
1 |
+
=== WooCommerce Print Invoice & Delivery Note ===
|
2 |
|
3 |
+
Contributors: ashokrane, bhavik.kiri, tychesoftwares, chabis
|
4 |
+
Donate link: https://www.paypal.me/TycheSoftwares
|
5 |
Tags: delivery note, packing slip, invoice, delivery, shipping, print, order, woocommerce, woothemes, shop
|
6 |
Requires at least: 4.0
|
7 |
+
Tested up to: 4.8.1
|
8 |
+
Author URI: https://www.tychesoftwares.com/
|
9 |
+
Stable tag: 4.3.2
|
10 |
License: GPLv3 or later
|
11 |
License URI: http://www.opensource.org/licenses/gpl-license.php
|
12 |
|
14 |
|
15 |
== Description ==
|
16 |
|
17 |
+
= Announcement: TYCHE SOFTWARES TEAM HAS TAKEN OVER THE OWNERSHIP & DEVELOPMENT OF THIS PLUGIN. THE ORIGINAL AUTHOR OF THIS PLUGIN IS TRIGGVY GUNDERSON. =
|
18 |
|
19 |
|
20 |
+
You can print out invoices and delivery notes for the WooCommerce orders. You can also edit the Company/Shop name, Company/Shop postal address and also add personal notes, conditions/policies (like a refund policy) and a footer imprint.
|
|
|
21 |
|
22 |
The plugin adds a new side panel on the order page to allow shop administrators to print out the invoice or delivery note. Registered customers can also print their order with a button that is added to the order screen.
|
23 |
|
|
|
|
|
24 |
|
25 |
= Features =
|
26 |
|
35 |
* Supports sequential order numbers
|
36 |
* Supports the WooCommerce refund system
|
37 |
* Intelligent invoice and delivery note template system with hooks and functions.php support
|
|
|
38 |
|
39 |
= Support =
|
40 |
|
42 |
|
43 |
= Contributing =
|
44 |
|
45 |
+
If you have a patch, or stumbled upon an issue with the source code that isn't a [WooCommerce issue](https://github.com/woothemes/woocommerce/issues?labels=Bug&milestone=22&state=open), you can contribute this back [on GitHub](https://github.com/TycheSoftwares/woocommerce-delivery-notes).
|
46 |
|
47 |
= Translating =
|
48 |
|
49 |
+
When your language is missing you can contribute a translation to the [GitHub repository](https://github.com/TycheSoftwares/woocommerce-delivery-notes#translating).
|
50 |
+
|
51 |
+
**Some of our Pro plugins:**
|
52 |
+
|
53 |
+
1. **[Abandoned Cart Pro for WooCommerce](https://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro/?utm_source=wprepo&utm_medium=otherprolink&utm_campaign=WCDeliveryNotes "Abandoned Cart Pro for WooCommerce")**
|
54 |
+
|
55 |
+
2. **[Booking & Appointment Plugin for WooCommerce](https://www.tychesoftwares.com/store/premium-plugins/woocommerce-booking-plugin/?utm_source=wprepo&utm_medium=link&utm_campaign=WCDeliveryNotes "Booking & Appointment Plugin for WooCommerce")**
|
56 |
+
|
57 |
+
3. **[Order Delivery Date Pro for WooCommerce](https://www.tychesoftwares.com/store/premium-plugins/order-delivery-date-for-woocommerce-pro-21/?utm_source=wprepo&utm_medium=link&utm_campaign=WCDeliveryNotes "Order Delivery Date Pro for WooCommerce")**
|
58 |
+
|
59 |
+
4. **[Product Delivery Date Pro for WooCommerce](https://www.tychesoftwares.com/store/premium-plugins/product-delivery-date-pro-for-woocommerce/?utm_source=wprepo&utm_medium=link&utm_campaign=WCDeliveryNotes "Product Delivery Date Pro for WooCommerce")**
|
60 |
+
|
61 |
+
|
62 |
+
**Some of our other free plugins:**
|
63 |
+
|
64 |
+
1. **[Order Delivery Date for WooCommerce - Lite](https://wordpress.org/plugins/order-delivery-date-for-woocommerce/ "Order Delivery Date for WooCommerce - Lite")**
|
65 |
+
|
66 |
+
2. **[Abandoned Cart for WooCommerce](https://wordpress.org/plugins/woocommerce-abandoned-cart/ "Abandoned Cart for WooCommerce")**
|
67 |
+
|
68 |
+
3. **[Product Delivery Date for WooCommerce – Lite](https://wordpress.org/plugins/product-delivery-date-for-woocommerce-lite/ "Product Delivery Date for WooCommerce – Lite")**
|
69 |
+
|
70 |
+
4. **[Order Delivery Date for WP e-Commerce](https://wordpress.org/plugins/order-delivery-date/ "Order Delivery Date for WP e-Commerce")**
|
71 |
+
|
72 |
+
5. **[Prevent Customers To Cancel WooCommerce Orders](https://wordpress.org/plugins/woo-prevent-cancel-order/ "Prevent Customers To Cancel WooCommerce Orders")**
|
73 |
+
|
74 |
+
6. **[WooCommerce Coupons by Categories and Tags](https://wordpress.org/plugins/woo-coupons-by-categories-and-tags/ "WooCommerce Coupons by Categories and Tags")**
|
75 |
+
|
76 |
+
7. **[Arconix FAQ](https://wordpress.org/plugins/arconix-faq/ "Arconix FAQ")**
|
77 |
+
|
78 |
+
8. **[Arconix Shortcodes](https://wordpress.org/plugins/arconix-shortcodes/ "Arconix Shortcodes")**
|
79 |
+
|
80 |
+
9. **[Arconix Flexslider](https://wordpress.org/plugins/arconix-flexslider/ "Arconix Flexslider")**
|
81 |
+
|
82 |
+
10. **[Arconix Portfolio](https://wordpress.org/plugins/arconix-portfolio/ "Arconix Portfolio")**
|
83 |
+
|
84 |
+
11. **[Arconix Testimonials](https://wordpress.org/plugins/arconix-testimonials/ "Arconix Testimonials")**
|
85 |
+
|
86 |
+
12. **[Export WordPress Menus](https://wordpress.org/plugins/wp-export-menus/ "Export WordPress Menus")**
|
87 |
|
88 |
== Installation ==
|
89 |
|
131 |
`
|
132 |
function example_serif_font_and_large_address() {
|
133 |
?>
|
134 |
+
<style>
|
135 |
+
`#page {
|
136 |
font-size: 1em;
|
137 |
font-family: Georgia, serif;
|
138 |
}
|
143 |
}
|
144 |
</style>
|
145 |
<?php
|
146 |
+
`}
|
147 |
add_action( 'wcdn_head', 'example_serif_font_and_large_address', 20 );
|
148 |
`
|
149 |
|
315 |
|
316 |
Upload your language file to `/wp-content/languages/plugins/` (create this folder if it doesn't exist). WordPress will then load the language. Make sure you use the same locale as in your configuration and the correct plugin locale i.e. `woocommerce-delivery-notes-it_IT.mo/.po`.
|
317 |
|
318 |
+
Please [contribute your translation](https://github.com/TycheSoftwares/woocommerce-delivery-notes#translating) to include it in the distribution.
|
319 |
|
320 |
== Screenshots ==
|
321 |
|
330 |
|
331 |
= Minimum Requirements: WooCommerce 2.2 =
|
332 |
|
333 |
+
= 4.3.2 (05.09.2017) =
|
334 |
+
|
335 |
+
* 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.
|
336 |
+
|
337 |
+
* Fix - There was no line break before SKU element for variable products on Invoice page. This has been fixed.
|
338 |
+
|
339 |
+
* Fix - The deprecated function WC_Order::get_order_currency has been removed and replaced with get_currency().
|
340 |
+
|
341 |
+
= 4.3.1 (23.08.2017) =
|
342 |
+
|
343 |
+
* This version has 1 bug fix.
|
344 |
+
|
345 |
+
* Fix - The attributes of variable product were not displayed with the variation name in the Print screen. This has been fixed.
|
346 |
+
|
347 |
+
= 4.3 (19.08.2017) =
|
348 |
+
|
349 |
+
* This version has 1 bug fix.
|
350 |
+
|
351 |
+
* Fix - Warnings were displayed on My Account, Checkout, Orders page with WooCommerce version 3.0.x. This has been fixed.
|
352 |
+
|
353 |
= 4.2.0 =
|
354 |
|
355 |
* Tweak - Refactored settings screen
|
templates/print-order/print-content.php
CHANGED
@@ -1,173 +1,212 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Print order content. Copy this file to your themes
|
4 |
-
* directory /woocommerce/print-order to customize it.
|
5 |
-
*
|
6 |
-
* @package WooCommerce Print Invoice & Delivery Note/Templates
|
7 |
-
*/
|
8 |
-
|
9 |
-
if ( !defined( 'ABSPATH' ) ) exit;
|
10 |
-
?>
|
11 |
-
|
12 |
-
<div class="order-branding">
|
13 |
-
<div class="company-logo">
|
14 |
-
<?php if( wcdn_get_company_logo_id() ) : ?><?php wcdn_company_logo(); ?><?php endif; ?>
|
15 |
-
</div>
|
16 |
-
|
17 |
-
<div class="company-info">
|
18 |
-
<?php if( !wcdn_get_company_logo_id() ) : ?><h1 class="company-name"><?php wcdn_company_name(); ?></h1><?php endif; ?>
|
19 |
-
<div class="company-address"><?php wcdn_company_info(); ?></div>
|
20 |
-
</div>
|
21 |
-
|
22 |
-
<?php do_action( 'wcdn_after_branding', $order ); ?>
|
23 |
-
</div><!-- .order-branding -->
|
24 |
-
|
25 |
-
|
26 |
-
<div class="order-addresses<?php if( !wcdn_has_shipping_address( $order ) ) : ?> no-shipping-address<?php endif; ?>">
|
27 |
-
<div class="billing-address">
|
28 |
-
<h3><?php _e( 'Billing Address', 'woocommerce-delivery-notes' ); ?></h3>
|
29 |
-
<address>
|
30 |
-
|
31 |
-
<?php if( !$order->get_formatted_billing_address() ) _e( 'N/A', 'woocommerce-delivery-notes' ); else echo apply_filters( 'wcdn_address_billing', $order->get_formatted_billing_address(), $order ); ?>
|
32 |
-
|
33 |
-
</address>
|
34 |
-
</div>
|
35 |
-
|
36 |
-
<div class="shipping-address">
|
37 |
-
<h3><?php _e( 'Shipping Address', 'woocommerce-delivery-notes' ); ?></h3>
|
38 |
-
<address>
|
39 |
-
|
40 |
-
<?php if( !$order->get_formatted_shipping_address() ) _e( 'N/A', 'woocommerce-delivery-notes' ); else echo apply_filters( 'wcdn_address_shipping', $order->get_formatted_shipping_address(), $order ); ?>
|
41 |
-
|
42 |
-
</address>
|
43 |
-
</div>
|
44 |
-
|
45 |
-
<?php do_action( 'wcdn_after_addresses', $order ); ?>
|
46 |
-
</div><!-- .order-addresses -->
|
47 |
-
|
48 |
-
|
49 |
-
<div class="order-info">
|
50 |
-
<h2><?php wcdn_document_title(); ?></h2>
|
51 |
-
|
52 |
-
<ul class="info-list">
|
53 |
-
<?php $fields = apply_filters( 'wcdn_order_info_fields', wcdn_get_order_info( $order ), $order ); ?>
|
54 |
-
<?php foreach( $fields as $field ) : ?>
|
55 |
-
<li>
|
56 |
-
<strong><?php echo apply_filters( 'wcdn_order_info_name', $field['label'], $field ); ?></strong>
|
57 |
-
<span><?php echo apply_filters( 'wcdn_order_info_content', $field['value'], $field ); ?></span>
|
58 |
-
</li>
|
59 |
-
<?php endforeach; ?>
|
60 |
-
</ul>
|
61 |
-
|
62 |
-
<?php do_action( 'wcdn_after_info', $order ); ?>
|
63 |
-
</div><!-- .order-info -->
|
64 |
-
|
65 |
-
|
66 |
-
<div class="order-items">
|
67 |
-
<table>
|
68 |
-
<thead>
|
69 |
-
<tr>
|
70 |
-
<th class="head-name"><span><?php _e('Product', 'woocommerce-delivery-notes'); ?></span></th>
|
71 |
-
<th class="head-item-price"><span><?php _e('Price', 'woocommerce-delivery-notes'); ?></span></th>
|
72 |
-
<th class="head-quantity"><span><?php _e('Quantity', 'woocommerce-delivery-notes'); ?></span></th>
|
73 |
-
<th class="head-price"><span><?php _e('Total', 'woocommerce-delivery-notes'); ?></span></th>
|
74 |
-
</tr>
|
75 |
-
</thead>
|
76 |
-
|
77 |
-
<tbody>
|
78 |
-
<?php if( sizeof( $order->get_items() ) > 0 ) : ?>
|
79 |
-
<?php foreach( $order->get_items() as $item ) : ?>
|
80 |
-
|
81 |
-
<?php
|
82 |
-
$product = apply_filters( 'wcdn_order_item_product', $order->get_product_from_item( $item ), $item );
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Print order content. Copy this file to your themes
|
4 |
+
* directory /woocommerce/print-order to customize it.
|
5 |
+
*
|
6 |
+
* @package WooCommerce Print Invoice & Delivery Note/Templates
|
7 |
+
*/
|
8 |
+
|
9 |
+
if ( !defined( 'ABSPATH' ) ) exit;
|
10 |
+
?>
|
11 |
+
|
12 |
+
<div class="order-branding">
|
13 |
+
<div class="company-logo">
|
14 |
+
<?php if( wcdn_get_company_logo_id() ) : ?><?php wcdn_company_logo(); ?><?php endif; ?>
|
15 |
+
</div>
|
16 |
+
|
17 |
+
<div class="company-info">
|
18 |
+
<?php if( !wcdn_get_company_logo_id() ) : ?><h1 class="company-name"><?php wcdn_company_name(); ?></h1><?php endif; ?>
|
19 |
+
<div class="company-address"><?php wcdn_company_info(); ?></div>
|
20 |
+
</div>
|
21 |
+
|
22 |
+
<?php do_action( 'wcdn_after_branding', $order ); ?>
|
23 |
+
</div><!-- .order-branding -->
|
24 |
+
|
25 |
+
|
26 |
+
<div class="order-addresses<?php if( !wcdn_has_shipping_address( $order ) ) : ?> no-shipping-address<?php endif; ?>">
|
27 |
+
<div class="billing-address">
|
28 |
+
<h3><?php _e( 'Billing Address', 'woocommerce-delivery-notes' ); ?></h3>
|
29 |
+
<address>
|
30 |
+
|
31 |
+
<?php if( !$order->get_formatted_billing_address() ) _e( 'N/A', 'woocommerce-delivery-notes' ); else echo apply_filters( 'wcdn_address_billing', $order->get_formatted_billing_address(), $order ); ?>
|
32 |
+
|
33 |
+
</address>
|
34 |
+
</div>
|
35 |
+
|
36 |
+
<div class="shipping-address">
|
37 |
+
<h3><?php _e( 'Shipping Address', 'woocommerce-delivery-notes' ); ?></h3>
|
38 |
+
<address>
|
39 |
+
|
40 |
+
<?php if( !$order->get_formatted_shipping_address() ) _e( 'N/A', 'woocommerce-delivery-notes' ); else echo apply_filters( 'wcdn_address_shipping', $order->get_formatted_shipping_address(), $order ); ?>
|
41 |
+
|
42 |
+
</address>
|
43 |
+
</div>
|
44 |
+
|
45 |
+
<?php do_action( 'wcdn_after_addresses', $order ); ?>
|
46 |
+
</div><!-- .order-addresses -->
|
47 |
+
|
48 |
+
|
49 |
+
<div class="order-info">
|
50 |
+
<h2><?php wcdn_document_title(); ?></h2>
|
51 |
+
|
52 |
+
<ul class="info-list">
|
53 |
+
<?php $fields = apply_filters( 'wcdn_order_info_fields', wcdn_get_order_info( $order ), $order ); ?>
|
54 |
+
<?php foreach( $fields as $field ) : ?>
|
55 |
+
<li>
|
56 |
+
<strong><?php echo apply_filters( 'wcdn_order_info_name', $field['label'], $field ); ?></strong>
|
57 |
+
<span><?php echo apply_filters( 'wcdn_order_info_content', $field['value'], $field ); ?></span>
|
58 |
+
</li>
|
59 |
+
<?php endforeach; ?>
|
60 |
+
</ul>
|
61 |
+
|
62 |
+
<?php do_action( 'wcdn_after_info', $order ); ?>
|
63 |
+
</div><!-- .order-info -->
|
64 |
+
|
65 |
+
|
66 |
+
<div class="order-items">
|
67 |
+
<table>
|
68 |
+
<thead>
|
69 |
+
<tr>
|
70 |
+
<th class="head-name"><span><?php _e('Product', 'woocommerce-delivery-notes'); ?></span></th>
|
71 |
+
<th class="head-item-price"><span><?php _e('Price', 'woocommerce-delivery-notes'); ?></span></th>
|
72 |
+
<th class="head-quantity"><span><?php _e('Quantity', 'woocommerce-delivery-notes'); ?></span></th>
|
73 |
+
<th class="head-price"><span><?php _e('Total', 'woocommerce-delivery-notes'); ?></span></th>
|
74 |
+
</tr>
|
75 |
+
</thead>
|
76 |
+
|
77 |
+
<tbody>
|
78 |
+
<?php if( sizeof( $order->get_items() ) > 0 ) : ?>
|
79 |
+
<?php foreach( $order->get_items() as $item ) : ?>
|
80 |
+
|
81 |
+
<?php
|
82 |
+
$product = apply_filters( 'wcdn_order_item_product', $order->get_product_from_item( $item ), $item );
|
83 |
+
|
84 |
+
if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) {
|
85 |
+
$item_meta = new WC_Order_Item_Product( $item['item_meta'], $product );
|
86 |
+
}else{
|
87 |
+
$item_meta = new WC_Order_Item_Meta( $item['item_meta'], $product );
|
88 |
+
}
|
89 |
+
|
90 |
+
?>
|
91 |
+
|
92 |
+
<tr>
|
93 |
+
<td class="product-name">
|
94 |
+
<?php do_action( 'wcdn_order_item_before', $product, $order ); ?>
|
95 |
+
|
96 |
+
<span class="name"><?php
|
97 |
+
$product_id = $item['product_id'];
|
98 |
+
$prod_name = get_post( $product_id );
|
99 |
+
$product_name = $prod_name->post_title;
|
100 |
+
|
101 |
+
|
102 |
+
echo apply_filters( 'wcdn_order_item_name', $product_name, $item ); ?></span>
|
103 |
+
|
104 |
+
<?php
|
105 |
+
// if ( version_compare( get_option( 'woocommerce_version' ), '3.1.0', ">=" ) ) {
|
106 |
+
// $item_meta->get_product();
|
107 |
+
|
108 |
+
// }else {
|
109 |
+
|
110 |
+
// $item_meta->display();
|
111 |
+
// }
|
112 |
+
|
113 |
+
if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) {
|
114 |
+
if(isset($item['variation_id'])){
|
115 |
+
$variation = wc_get_product($item['variation_id']);
|
116 |
+
foreach ($item['item_meta'] as $key => $value) {
|
117 |
+
$term = get_term_by('slug', $value, $key);
|
118 |
+
$attribute_name = wc_attribute_label( $key, $variation );
|
119 |
+
if(isset($term->name)){
|
120 |
+
echo '<br>'.$attribute_name.':'.$term->name;
|
121 |
+
}else{
|
122 |
+
echo '<br>'.$attribute_name.':'.$value;
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
}else{
|
127 |
+
$item_meta_new = new WC_Order_Item_Meta( $item['item_meta'], $product );
|
128 |
+
$item_meta_new->display( );
|
129 |
+
|
130 |
+
}
|
131 |
+
?>
|
132 |
+
<br>
|
133 |
+
<dl class="extras">
|
134 |
+
<?php if( $product && $product->exists() && $product->is_downloadable() && $order->is_download_permitted() ) : ?>
|
135 |
+
|
136 |
+
<dt><?php _e( 'Download:', 'woocommerce-delivery-notes' ); ?></dt>
|
137 |
+
<dd><?php printf( __( '%s Files', 'woocommerce-delivery-notes' ), count( $order->get_item_downloads( $item ) ) ); ?></dd>
|
138 |
+
|
139 |
+
<?php endif; ?>
|
140 |
+
|
141 |
+
<?php
|
142 |
+
$fields = apply_filters( 'wcdn_order_item_fields', array(), $product, $order );
|
143 |
+
foreach ( $fields as $field ) :
|
144 |
+
?>
|
145 |
+
|
146 |
+
<dt><?php echo $field['label']; ?></dt>
|
147 |
+
<dd><?php echo $field['value']; ?></dd>
|
148 |
+
|
149 |
+
<?php endforeach; ?>
|
150 |
+
</dl>
|
151 |
+
</td>
|
152 |
+
<td class="product-item-price">
|
153 |
+
<span><?php echo wcdn_get_formatted_item_price( $order, $item ); ?></span>
|
154 |
+
</td>
|
155 |
+
<td class="product-quantity">
|
156 |
+
<span><?php echo apply_filters( 'wcdn_order_item_quantity', $item['qty'], $item ); ?></span>
|
157 |
+
</td>
|
158 |
+
<td class="product-price">
|
159 |
+
<span><?php echo $order->get_formatted_line_subtotal( $item ); ?></span>
|
160 |
+
</td>
|
161 |
+
</tr>
|
162 |
+
<?php endforeach; ?>
|
163 |
+
<?php endif; ?>
|
164 |
+
</tbody>
|
165 |
+
|
166 |
+
<tfoot>
|
167 |
+
<?php if( $totals = $order->get_order_item_totals() ) : ?>
|
168 |
+
<?php foreach( $totals as $total ) : ?>
|
169 |
+
<tr>
|
170 |
+
<td class="total-name"><span><?php echo $total['label']; ?></span></td>
|
171 |
+
<td class="total-item-price"></td>
|
172 |
+
<td class="total-quantity"></td>
|
173 |
+
<td class="total-price"><span><?php echo $total['value']; ?></span></td>
|
174 |
+
</tr>
|
175 |
+
<?php endforeach; ?>
|
176 |
+
<?php endif; ?>
|
177 |
+
</tfoot>
|
178 |
+
</table>
|
179 |
+
|
180 |
+
<?php do_action( 'wcdn_after_items', $order ); ?>
|
181 |
+
</div><!-- .order-items -->
|
182 |
+
|
183 |
+
|
184 |
+
<div class="order-notes">
|
185 |
+
<?php if( wcdn_has_customer_notes( $order ) ) : ?>
|
186 |
+
<h4><?php _e( 'Customer Note', 'woocommerce-delivery-notes' ); ?></h4>
|
187 |
+
<?php wcdn_customer_notes( $order ); ?>
|
188 |
+
<?php endif; ?>
|
189 |
+
|
190 |
+
<?php do_action( 'wcdn_after_notes', $order ); ?>
|
191 |
+
</div><!-- .order-notes -->
|
192 |
+
|
193 |
+
|
194 |
+
<div class="order-thanks">
|
195 |
+
<?php wcdn_personal_notes(); ?>
|
196 |
+
|
197 |
+
<?php do_action( 'wcdn_after_thanks', $order ); ?>
|
198 |
+
</div><!-- .order-thanks -->
|
199 |
+
|
200 |
+
|
201 |
+
<div class="order-colophon">
|
202 |
+
<div class="colophon-policies">
|
203 |
+
<?php wcdn_policies_conditions(); ?>
|
204 |
+
</div>
|
205 |
+
|
206 |
+
<div class="colophon-imprint">
|
207 |
+
<?php wcdn_imprint(); ?>
|
208 |
+
</div>
|
209 |
+
|
210 |
+
<?php do_action( 'wcdn_after_colophon', $order ); ?>
|
211 |
+
</div><!-- .order-colophon -->
|
212 |
|
woocommerce-delivery-notes.php
CHANGED
@@ -3,17 +3,17 @@
|
|
3 |
* Print invoices & delivery notes for WooCommerce orders.
|
4 |
*
|
5 |
* Plugin Name: WooCommerce Print Invoice & Delivery Note
|
6 |
-
* Plugin URI: https://
|
7 |
* Description: Print Invoices & Delivery Notes for WooCommerce Orders.
|
8 |
-
* Version: 4.2
|
9 |
-
* Author:
|
10 |
-
* Author URI: https://
|
11 |
* License: GPLv3 or later
|
12 |
* License URI: http://www.opensource.org/licenses/gpl-license.php
|
13 |
* Text Domain: woocommerce-delivery-notes
|
14 |
* Domain Path: /languages
|
15 |
*
|
16 |
-
* Copyright 2015
|
17 |
*
|
18 |
* This file is part of WooCommerce Print Invoices & Delivery Notes,
|
19 |
* a plugin for WordPress.
|
@@ -55,7 +55,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes' ) ) {
|
|
55 |
/**
|
56 |
* Default properties
|
57 |
*/
|
58 |
-
public static $plugin_version = '4.2
|
59 |
public static $plugin_url;
|
60 |
public static $plugin_path;
|
61 |
public static $plugin_basefile;
|
3 |
* Print invoices & delivery notes for WooCommerce orders.
|
4 |
*
|
5 |
* Plugin Name: WooCommerce Print Invoice & Delivery Note
|
6 |
+
* Plugin URI: https://www.tychesoftwares.com/
|
7 |
* Description: Print Invoices & Delivery Notes for WooCommerce Orders.
|
8 |
+
* Version: 4.3.2
|
9 |
+
* Author: Tyche Softwares
|
10 |
+
* Author URI: https://www.tychesoftwares.com/
|
11 |
* License: GPLv3 or later
|
12 |
* License URI: http://www.opensource.org/licenses/gpl-license.php
|
13 |
* Text Domain: woocommerce-delivery-notes
|
14 |
* Domain Path: /languages
|
15 |
*
|
16 |
+
* Copyright 2015 Tyche Softwares
|
17 |
*
|
18 |
* This file is part of WooCommerce Print Invoices & Delivery Notes,
|
19 |
* a plugin for WordPress.
|
55 |
/**
|
56 |
* Default properties
|
57 |
*/
|
58 |
+
public static $plugin_version = '4.3.2';
|
59 |
public static $plugin_url;
|
60 |
public static $plugin_path;
|
61 |
public static $plugin_basefile;
|