WooCommerce Print Invoice & Delivery Note - Version 4.2

Version Description

Download this release

Release Info

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

Code changes from version 3.1.1 to 4.2

Files changed (56) hide show
  1. css/admin.css +90 -22
  2. fonts/icons.eot +0 -0
  3. fonts/icons.svg +12 -10
  4. fonts/icons.ttf +0 -0
  5. fonts/icons.woff +0 -0
  6. includes/class-wcdn-print.php +206 -79
  7. includes/class-wcdn-settings.php +412 -352
  8. includes/class-wcdn-theme.php +66 -13
  9. includes/class-wcdn-writepanel.php +106 -49
  10. includes/wcdn-template-functions.php +195 -26
  11. includes/wcdn-template-hooks.php +8 -2
  12. js/admin.js +59 -19
  13. js/theme.js +3 -0
  14. languages/woocommerce-delivery-notes-cs_CZ.mo +59 -0
  15. languages/woocommerce-delivery-notes-cs_CZ.po +539 -0
  16. languages/woocommerce-delivery-notes-da_DK.mo +0 -0
  17. languages/woocommerce-delivery-notes-da_DK.po +426 -210
  18. languages/woocommerce-delivery-notes-de_DE.mo +0 -0
  19. languages/woocommerce-delivery-notes-de_DE.po +344 -208
  20. languages/woocommerce-delivery-notes-es_ES.mo +0 -0
  21. languages/woocommerce-delivery-notes-es_ES.po +411 -220
  22. languages/woocommerce-delivery-notes-et.mo +0 -0
  23. languages/woocommerce-delivery-notes-et.po +471 -0
  24. languages/woocommerce-delivery-notes-fa_IR.mo +0 -0
  25. languages/woocommerce-delivery-notes-fa_IR.po +2 -2
  26. languages/woocommerce-delivery-notes-fi.mo +0 -0
  27. languages/woocommerce-delivery-notes-fi.po +0 -295
  28. languages/woocommerce-delivery-notes-fi_FI.mo +0 -0
  29. languages/woocommerce-delivery-notes-fi_FI.po +500 -0
  30. languages/woocommerce-delivery-notes-fr_FR.mo +0 -0
  31. languages/woocommerce-delivery-notes-fr_FR.po +490 -210
  32. languages/woocommerce-delivery-notes-it_IT.mo +0 -0
  33. languages/woocommerce-delivery-notes-it_IT.po +414 -270
  34. languages/woocommerce-delivery-notes-nl_NL.mo +0 -0
  35. languages/woocommerce-delivery-notes-nl_NL.po +130 -94
  36. languages/woocommerce-delivery-notes-pl_PL.mo +0 -0
  37. languages/woocommerce-delivery-notes-pl_PL.po +0 -295
  38. languages/woocommerce-delivery-notes-pt_BR.mo +0 -0
  39. languages/woocommerce-delivery-notes-pt_BR.po +438 -228
  40. languages/woocommerce-delivery-notes-ru_RU.mo +0 -0
  41. languages/woocommerce-delivery-notes-ru_RU.po +0 -295
  42. languages/woocommerce-delivery-notes-sk_SK.mo +0 -0
  43. languages/woocommerce-delivery-notes-sk_SK.po +0 -295
  44. languages/woocommerce-delivery-notes-sv_SE.mo +0 -0
  45. languages/woocommerce-delivery-notes-sv_SE.po +465 -213
  46. languages/woocommerce-delivery-notes-tr_TR.mo +0 -0
  47. languages/woocommerce-delivery-notes-tr_TR.po +0 -295
  48. languages/woocommerce-delivery-notes-vi_VN.mo +0 -0
  49. languages/woocommerce-delivery-notes-vi_VN.po +539 -0
  50. languages/woocommerce-delivery-notes.pot +260 -165
  51. readme.md +6 -2
  52. readme.txt +197 -32
  53. templates/print-order/print-content.php +23 -24
  54. templates/print-order/print-order.php +12 -2
  55. templates/print-order/style.css +52 -18
  56. woocommerce-delivery-notes.php +145 -37
css/admin.css CHANGED
@@ -2,11 +2,11 @@
2
3
@font-face {
4
font-family: 'icons';
5
- src: url('../fonts/icons.eot?99179621');
6
- src: url('../fonts/icons.eot?99179621#iefix') format('embedded-opentype'),
7
- url('../fonts/icons.woff?99179621') format('woff'),
8
- url('../fonts/icons.ttf?99179621') format('truetype'),
9
- url('../fonts/icons.svg?99179621#icons') format('svg');
10
font-weight: normal;
11
font-style: normal;
12
}
@@ -29,13 +29,7 @@
29
#woocommerce-delivery-notes-box span.print-preview-loading {
30
position: absolute;
31
right: 2.5em;
32
- top: -2.35em;
33
- }
34
-
35
- #woocommerce-delivery-notes-box span.print-preview-loading,
36
- .type-shop_order .column-order_actions span.print-preview-loading {
37
- display: none;
38
- vertical-align: middle;
39
}
40
41
#woocommerce-delivery-notes-box .print-actions {
@@ -44,11 +38,14 @@
44
45
#woocommerce-delivery-notes-box .print-info {
46
margin-top: 0.3em;
47
- border-top: 1px solid #eee;
48
padding: 10px 12px;
49
}
50
51
/* All orders */
52
.type-shop_order .column-order_actions .print-preview-button {
53
display: block;
54
text-indent: -9999px;
@@ -77,14 +74,24 @@
77
text-align: center;
78
content: "";
79
line-height: 1.85;
80
}
81
82
.type-shop_order .column-order_actions .print-preview-button.invoice:before {
83
- content: "\e801";
84
}
85
86
.type-shop_order .column-order_actions .print-preview-button.delivery-note:before {
87
- content: "\e800";
88
}
89
90
.type-shop_order .column-order_actions span.print-preview-loading {
@@ -96,21 +103,82 @@
96
display: none;
97
}
98
99
/* Settings */
100
101
- #company-logo-placeholder {
102
}
103
104
- #company-logo-placeholder img {
105
cursor: pointer;
106
- max-width: 200px;
107
- height: auto;
108
}
109
110
- #company-logo-loader.spinner {
111
float: none;
112
}
113
114
- #company-logo-loader.print-preview-loading {
115
- display: inline-block;
116
}
2
3
@font-face {
4
font-family: 'icons';
5
+ src: url('../fonts/icons.eot');
6
+ src: url('../fonts/icons.eot?#iefix') format('embedded-opentype'),
7
+ url('../fonts/icons.woff') format('woff'),
8
+ url('../fonts/icons.ttf') format('truetype'),
9
+ url('../fonts/icons.svg#icons') format('svg');
10
font-weight: normal;
11
font-style: normal;
12
}
29
#woocommerce-delivery-notes-box span.print-preview-loading {
30
position: absolute;
31
right: 2.5em;
32
+ top: -2.1em;
33
}
34
35
#woocommerce-delivery-notes-box .print-actions {
38
39
#woocommerce-delivery-notes-box .print-info {
40
margin-top: 0.3em;
41
+ border-top: 1px solid #ddd;
42
padding: 10px 12px;
43
+ margin-bottom: 0;
44
+ background-color: #f5f5f5;
45
}
46
47
/* All orders */
48
+
49
.type-shop_order .column-order_actions .print-preview-button {
50
display: block;
51
text-indent: -9999px;
74
text-align: center;
75
content: "";
76
line-height: 1.85;
77
+
78
+ content: "\e603";
79
}
80
81
.type-shop_order .column-order_actions .print-preview-button.invoice:before {
82
+ content: "\e602";
83
}
84
85
.type-shop_order .column-order_actions .print-preview-button.delivery-note:before {
86
+ content: "\e601";
87
+ }
88
+
89
+ .type-shop_order .column-order_actions .print-preview-button.receipt:before {
90
+ content: "\e604";
91
+ }
92
+
93
+ .type-shop_order .column-order_actions .print-preview-button.credit-note:before {
94
+ content: "\e600";
95
}
96
97
.type-shop_order .column-order_actions span.print-preview-loading {
103
display: none;
104
}
105
106
+ .print-preview-loading {
107
+ visibility: hidden;
108
+ vertical-align: middle;
109
+ margin: 0;
110
+ }
111
+
112
+ .print-preview-loading.is-active {
113
+ visibility: visible;
114
+ }
115
+
116
/* Settings */
117
118
+ .wcdn-image-select-field {
119
+ position: relative;
120
+ overflow: hidden;
121
+ background-color: white;
122
+ border: 1px solid #ddd;
123
+ width: 125px;
124
+ height: 125px;
125
}
126
127
+ .wcdn-image-select-attachment {
128
+ position: relative;
129
+ width: 100%;
130
+ height: 100%;
131
cursor: pointer;
132
}
133
134
+ .wcdn-image-select-attachment .thumbnail {
135
+ position: absolute;
136
+ top: 0;
137
+ left: 0;
138
+ width: 100%;
139
+ height: 100%;
140
+ -webkit-transform: translate( 50%, 50% );
141
+ -ms-transform: translate(50%,50%);
142
+ transform: translate( 50%, 50% );
143
+ }
144
+
145
+ .wcdn-image-select-attachment img {
146
+ position: absolute;
147
+ top: 0;
148
+ left: 0;
149
+ max-height: 100%;
150
+ max-width: none;
151
+ -webkit-transform: translate( -50%, -50% );
152
+ -ms-transform: translate(-50%,-50%);
153
+ transform: translate( -50%, -50% );
154
+ }
155
+
156
+ .wcdn-image-select-attachment img.portrait {
157
+ max-height: none;
158
+ max-width: 100%;
159
+ }
160
+
161
+ .wcdn-image-select-spinner {
162
float: none;
163
+ position: absolute;
164
+ top: 0;
165
+ left: 0;
166
+ margin: 10px;
167
+ }
168
+
169
+ .wcdn-image-select-buttons {
170
+ position: absolute;
171
+ left: 0;
172
+ bottom: 0;
173
+ padding-left: 10px;
174
+ padding-bottom: 10px;
175
}
176
177
+ .wcdn-image-select-buttons .button {
178
+ max-width: 105px;
179
+ white-space: nowrap;
180
+ overflow: hidden;
181
+ -webkit-text-overflow: ellipsis;
182
+ -ms-text-overflow: ellipsis;
183
+ text-overflow: ellipsis;
184
}
fonts/icons.eot CHANGED
Binary file
fonts/icons.svg CHANGED
@@ -1,13 +1,15 @@
1
<?xml version="1.0" standalone="no"?>
2
- <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
<svg xmlns="http://www.w3.org/2000/svg">
4
- <metadata>Copyright (C) 2014 by original authors @ fontello.com</metadata>
5
<defs>
6
- <font id="icons" horiz-adv-x="1000" >
7
- <font-face font-family="icons" font-weight="400" font-stretch="normal" units-per-em="1000" ascent="850" descent="-150" />
8
- <missing-glyph horiz-adv-x="1000" />
9
- <glyph glyph-name="delivery-note" unicode="&#xe800;" d="m701 850h-581v-1000h760v825l-179 175z m119-940h-640v880h490v-150h150v-730z m-540 500h440v60h-440v-60z m0-160h440v60h-440v-60z m0-160h440v60h-440v-60z" horiz-adv-x="1000" />
10
- <glyph glyph-name="invoice" unicode="&#xe801;" d="m701 850h-581v-1000h760v825l-179 175z m119-940h-640v880h490v-150h150v-730z m-310 449v164c30-9 51-24 66-52l55 32c-26 47-61 76-121 81v66h-30v-66c-70-5-127-69-127-138c0-68 46-100 101-128l26-13v-210c-60 8-89 40-101 99l-63-13c13-81 84-146 164-147v-64h30v64c80 10 137 88 137 164c0 86-67 130-137 161z m-30 16c-40 14-65 35-65 76c0 37 25 67 65 72v-148z m30-275v189c40-20 74-47 74-94c0-45-24-86-74-95z" horiz-adv-x="1000" />
11
- </font>
12
- </defs>
13
- </svg>
1
<?xml version="1.0" standalone="no"?>
2
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
3
<svg xmlns="http://www.w3.org/2000/svg">
4
+ <metadata>Generated by IcoMoon</metadata>
5
<defs>
6
+ <font id="icons" horiz-adv-x="1024">
7
+ <font-face units-per-em="1024" ascent="960" descent="-64" />
8
+ <missing-glyph horiz-adv-x="1024" />
9
+ <glyph unicode="&#x20;" d="" horiz-adv-x="512" />
10
+ <glyph unicode="&#xe600;" d="M717.66 962.56h-594.78v-1024h778.24v844.8l-183.46 179.2zM839.68 0h-655.36v901.12h501.76v-153.6h153.6v-747.52zM512 563.2v-85.125l115.845 115.845-115.845 115.845v-85.125c-129.874 0-235.52-105.656-235.52-235.52 0-54.364 18.555-104.428 49.613-144.343l44.012 43.848c-20.193 28.436-32.184 63.058-32.184 100.495 0 95.99 78.090 174.080 174.080 174.080zM686.080 389.12c0-95.99-78.090-174.080-174.080-174.080v85.125l-115.845-115.845 115.845-115.845v85.125c129.874 0 235.52 105.646 235.52 235.52 0 54.272-18.504 104.274-49.449 144.138l-44.063-43.796c20.122-28.396 32.072-62.976 32.072-100.342z" />
11
+ <glyph unicode="&#xe601;" d="M717.66 962.56h-594.78v-1024h778.24v844.8l-183.46 179.2zM839.68 0h-655.36v901.12h501.76v-153.6h153.6v-747.52zM286.72 512h450.56v61.44h-450.56v-61.44zM286.72 348.16h450.56v61.44h-450.56v-61.44zM286.72 184.32h450.56v61.44h-450.56v-61.44z" />
12
+ <glyph unicode="&#xe602;" d="M717.66 962.56h-594.78v-1024h778.24v844.8l-183.46 179.2zM839.68 0h-655.36v901.12h501.76v-153.6h153.6v-747.52zM522.24 459.397v168.468c30.72-9.318 52.5-24.371 67.553-53.053l55.839 32.256c-25.815 48.036-61.952 78.152-123.392 83.169v67.523h-30.72v-67.523c-71.68-5.734-129.997-70.257-129.997-141.23 0-70.257 47.084-102.513 103.711-131.195l26.286-12.892v-215.060c-61.44 7.885-91.29 40.141-103.475 101.079l-64.031-13.619c12.902-82.442 85.586-149.115 167.506-150.548v-65.331h30.72v65.331c81.92 10.752 139.786 90.327 139.786 167.752 0 88.177-68.106 133.335-139.786 164.874zM491.52 476.6c-40.96 14.336-66.673 35.123-66.673 77.425 0 37.99 25.713 68.096 66.673 73.83v-151.255zM522.24 194.161v194.273c40.96-20.787 75.274-48.026 75.274-96.778 0-45.885-24.074-87.47-75.274-97.495z" />
13
+ <glyph unicode="&#xe603;" d="M717.66 962.56h-594.78v-1024h778.24v844.8l-183.46 179.2zM839.68 0h-655.36v901.12h501.76v-153.6h153.6v-747.52z" />
14
+ <glyph unicode="&#xe604;" d="M122.88 962.56v-1026.478l143.36 143.36 112.64-112.64 112.64 112.64 112.64-112.64 112.64 112.64 143.36-143.36v1026.478h-737.28zM798.72 84.398l-81.92 81.92-112.64-112.64-112.64 112.64-112.64-112.64-112.64 112.64-81.92-81.92v816.722h614.4v-816.722zM286.72 757.76h409.6v-61.44h-409.6v61.44zM286.72 593.92h409.6v-61.44h-409.6v61.44z" />
15
+ </font></defs></svg>
fonts/icons.ttf CHANGED
Binary file
fonts/icons.woff CHANGED
Binary file
includes/class-wcdn-print.php CHANGED
@@ -1,5 +1,12 @@
1
<?php
2
3
/**
4
* Print class
5
*/
@@ -7,15 +14,14 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
7
8
class WooCommerce_Delivery_Notes_Print {
9
10
- public $template_directory_name;
11
- public $template_path_theme;
12
- public $template_path_plugin;
13
- public $template_url_plugin;
14
-
15
public $api_endpoints;
16
public $query_vars;
17
- public $template_types;
18
- public $template_type;
19
20
public $order_ids;
21
public $order_email;
@@ -25,23 +31,88 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
25
* Constructor
26
*/
27
public function __construct() {
28
- // Set the default variables
29
- $this->template_types = array(
30
- 'invoice',
31
- 'delivery-note',
32
- 'order'
33
- );
34
35
- $this->api_endpoints = array(
36
- 'print-order' => get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'print_order_page_endpoint', 'print-order' )
37
38
);
39
-
40
$this->query_vars = array(
41
'print-order-type',
42
'print-order-email'
43
);
44
-
45
// Load the hooks
46
add_action( 'init', array( $this, 'load_hooks' ) );
47
add_filter( 'query_vars', array( $this, 'add_query_vars' ) );
@@ -49,17 +120,11 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
49
add_action( 'template_redirect', array( $this, 'template_redirect_theme' ) );
50
add_action( 'wp_ajax_print_order', array( $this, 'template_redirect_admin' ) );
51
}
52
-
53
/**
54
* Load the init hooks
55
*/
56
public function load_hooks() {
57
- // Define default variables
58
- $this->template_directory_name = 'print-order';
59
- $this->template_path_theme = WC_TEMPLATE_PATH . $this->template_directory_name . '/';
60
- $this->template_path_plugin = WooCommerce_Delivery_Notes::$plugin_path . 'templates/' . $this->template_directory_name . '/';
61
- $this->template_url_plugin = WooCommerce_Delivery_Notes::$plugin_url . 'templates/' . $this->template_directory_name . '/';
62
-
63
// Add the endpoints
64
$this->add_endpoints();
65
}
@@ -76,8 +141,8 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
76
77
// Flush the rules when the transient is set.
78
// This is important to make the endpoint work.
79
- if( get_transient( WooCommerce_Delivery_Notes::$plugin_prefix . 'flush_rewrite_rules' ) == true ) {
80
- delete_transient( WooCommerce_Delivery_Notes::$plugin_prefix . 'flush_rewrite_rules' );
81
flush_rewrite_rules();
82
}
83
}
@@ -105,7 +170,53 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
105
}
106
}
107
}
108
109
/**
110
* Template handling in the front-end
111
*/
@@ -125,7 +236,7 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
125
*/
126
public function template_redirect_admin() {
127
// Let the backend only access the page
128
- if( is_admin() && !empty( $_REQUEST['print-order'] ) && !empty( $_REQUEST['action'] ) ) {
129
$type = !empty( $_REQUEST['print-order-type'] ) ? $_REQUEST['print-order-type'] : null;
130
$email = !empty( $_REQUEST['print-order-email'] ) ? $_REQUEST['print-order-email'] : null;
131
$this->generate_template( $_GET['print-order'], $type, $email );
@@ -145,14 +256,15 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
145
$this->order_ids = array_filter( explode('-', $order_ids ) );
146
}
147
148
- // Default type
149
- if( empty( $template_type ) || !in_array( $template_type, $this->template_types ) ) {
150
- $this->template_type = 'order';
151
- } else {
152
- $this->template_type = $template_type;
153
}
154
155
- // Default email
156
if( empty( $order_email ) ) {
157
$this->order_email = null;
158
} else {
@@ -161,33 +273,57 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
161
162
// Create the orders and check permissions
163
$populated = $this->populate_orders();
164
-
165
// Only continue if the orders are populated
166
if( !$populated ) {
167
die();
168
}
169
-
170
// Load the print template html
171
- wc_get_template( 'print-order.php', null, $this->template_path_theme, $this->template_path_plugin );
172
exit;
173
}
174
-
175
/**
176
* Get print page url
177
*/
178
- public function get_print_page_url( $order_ids, $template_type = 'order', $order_email = null ) {
179
// Explode the ids when needed
180
if( !is_array( $order_ids ) ) {
181
$order_ids = array_filter( explode( '-', $order_ids ) );
182
}
183
-
184
- // Default args
185
$args = array();
186
187
- if( in_array( $template_type, $this->template_types ) && $template_type != 'order' ) {
188
- $args = wp_parse_args( array( 'print-order-type' => $template_type ), $args );
189
}
190
191
if( !empty( $order_email ) ) {
192
$args = wp_parse_args( array( 'print-order-email' => $order_email ), $args );
193
}
@@ -198,7 +334,7 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
198
// Create another url depending on where the user prints. This
199
// prevents some issues with ssl when the my-account page is
200
// secured with ssl but the admin isn't.
201
- if( is_admin() ) {
202
// For the admin we use the ajax.php for better security
203
$args = wp_parse_args( array( 'action' => 'print_order' ), $args );
204
$base_url = admin_url( 'admin-ajax.php' );
@@ -206,11 +342,11 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
206
207
// Add the order ids and create the url
208
$url = add_query_arg( $endpoint, $order_ids_slug, $base_url );
209
- } else {
210
// For the theme
211
- $base_url = get_permalink( wc_get_page_id( 'myaccount' ) );
212
$endpoint = $this->api_endpoints['print-order'];
213
-
214
// Add the order ids and create the url
215
if( get_option( 'permalink_structure' ) ) {
216
$url = trailingslashit( trailingslashit( $base_url ) . $endpoint . '/' . $order_ids_slug );
@@ -222,29 +358,7 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
222
// Add all other args
223
$url = add_query_arg( $args, $url );
224
225
- return $url;
226
- }
227
-
228
- /**
229
- * Get the template url for a file. locate by file existence
230
- * and then return the corresponding url.
231
- */
232
- public function get_template_url( $name ) {
233
- $child_theme_path = get_stylesheet_directory() . '/' . $this->template_path_theme;
234
- $child_theme_uri = get_stylesheet_directory_uri() . '/' . $this->template_path_theme;
235
- $theme_path = get_template_directory() . '/' . $this->template_path_theme;
236
- $theme_uri = get_template_directory_uri() . '/' . $this->template_path_theme;
237
-
238
- // buld the url depenind on where the file is
239
- if( file_exists( $child_theme_path . $name ) ) {
240
- $uri = $child_theme_uri . $name;
241
- } elseif( file_exists( $theme_path . $name ) ) {
242
- $uri = $theme_uri . $name;
243
- } else {
244
- $uri = $this->template_url_plugin . $name;
245
- }
246
-
247
- return $uri;
248
}
249
250
/**
@@ -257,7 +371,7 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
257
$args = array(
258
'posts_per_page' => -1,
259
'post_type' => 'shop_order',
260
- 'post_status' => 'publish',
261
'post__in' => $this->order_ids,
262
'orderby' => 'post__in'
263
);
@@ -306,26 +420,39 @@ if ( ! class_exists( 'WooCommerce_Delivery_Notes_Print' ) ) {
306
* Get the order invoice number
307
*/
308
public function get_order_invoice_number( $order_id ) {
309
- $invoice_start = intval( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'invoice_number_start', 1 ) );
310
- $invoice_counter = intval( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'invoice_number_counter', 0 ) );
311
- $invoice_prefix = get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'invoice_number_prefix' );
312
- $invoice_suffix = get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'invoice_number_suffix' );
313
314
// Add the invoice number to the order when it doesn't yet exist
315
- $meta_key = '_' . WooCommerce_Delivery_Notes::$plugin_prefix . 'invoice_number';
316
- $meta_added = add_post_meta( $order_id, $meta_key, $invoice_prefix . ( $invoice_start + $invoice_counter ) . $invoice_suffix, true );
317
-
318
// Update the total count
319
if( $meta_added ) {
320
- update_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'invoice_number_counter', $invoice_counter + 1 );
321
}
322
323
// Get the invoice number
324
return apply_filters( 'wcdn_order_invoice_number', get_post_meta( $order_id, $meta_key, true ) );
325
}
326
327
}
328
329
}
330
331
- ?>
1
<?php
2
3
+ /**
4
+ * Exit if accessed directly
5
+ */
6
+ if ( !defined( 'ABSPATH' ) ) {
7
+ exit;
8
+ }
9
+
10
/**
11
* Print class
12
*/
14
15
class WooCommerce_Delivery_Notes_Print {
16
17
+ public static $template_registrations;
18
+ public static $template_styles;
19
+
20
+ public $template_locations;
21
+ public $template;
22
+
23
public $api_endpoints;
24
public $query_vars;
25
26
public $order_ids;
27
public $order_email;
31
* Constructor
32
*/
33
public function __construct() {
34
+ // Define the templates
35
+ self::$template_registrations = apply_filters( 'wcdn_template_registration', array(
36
+ apply_filters( 'wcdn_template_registration_invoice', array(
37
+ 'type' => 'invoice',
38
+ 'labels' => array(
39
+ 'name' => __( 'Invoice', 'woocommerce-delivery-notes' ),
40
+ 'name_plural' => __( 'Invoices', 'woocommerce-delivery-notes' ),
41
+ 'print' => __( 'Print Invoice', 'woocommerce-delivery-notes' ),
42
+ 'print_plural' => __( 'Print Invoices', 'woocommerce-delivery-notes' ),
43
+ 'message' => __( 'Invoice created.', 'woocommerce-delivery-notes' ),
44
+ 'message_plural' => __( 'Invoices created.', 'woocommerce-delivery-notes' ),
45
+ 'setting' => __( 'Show "Print Invoice" button', 'woocommerce-delivery-notes' )
46
+ )
47
+ ) ),
48
+ apply_filters( 'wcdn_template_registration_delivery_note', array(
49
+ 'type' => 'delivery-note',
50
+ 'labels' => array(
51
+ 'name' => __( 'Delivery Note', 'woocommerce-delivery-notes' ),
52
+ 'name_plural' => __( 'Delivery Notes', 'woocommerce-delivery-notes' ),
53
+ 'print' => __( 'Print Delivery Note', 'woocommerce-delivery-notes' ),
54
+ 'print_plural' => __( 'Print Delivery Notes', 'woocommerce-delivery-notes' ),
55
+ 'message' => __( 'Delivery Note created.', 'woocommerce-delivery-notes' ),
56
+ 'message_plural' => __( 'Delivery Notes created.', 'woocommerce-delivery-notes' ),
57
+ 'setting' => __( 'Show "Print Delivery Note" button', 'woocommerce-delivery-notes' )
58
+ )
59
+ ) ),
60
+ apply_filters( 'wcdn_template_registration_receipt', array(
61
+ 'type' => 'receipt',
62
+ 'labels' => array(
63
+ 'name' => __( 'Receipt', 'woocommerce-delivery-notes' ),
64
+ 'name_plural' => __( 'Receipts', 'woocommerce-delivery-notes' ),
65
+ 'print' => __( 'Print Receipt', 'woocommerce-delivery-notes' ),
66
+ 'print_plural' => __( 'Print Receipts', 'woocommerce-delivery-notes' ),
67
+ 'message' => __( 'Receipt created.', 'woocommerce-delivery-notes' ),
68
+ 'message_plural' => __( 'Receipts created.', 'woocommerce-delivery-notes' ),
69
+ 'setting' => __( 'Show "Print Receipt" button', 'woocommerce-delivery-notes' )
70
+ )
71
+ ) )
72
+ ) );
73
74
+ // Add the default template as first item after filter hooks passed
75
+ array_unshift( self::$template_registrations, array(
76
+ 'type' => 'order',
77
+ 'labels' => array(
78
+ 'name' => __( 'Order', 'woocommerce-delivery-notes' ),
79
+ 'name_plural' => __( 'Orders', 'woocommerce-delivery-notes' ),
80
+ 'print' => __( 'Print Order', 'woocommerce-delivery-notes' ),
81
+ 'print_plural' => __( 'Print Orders', 'woocommerce-delivery-notes' ),
82
+ 'message' => null,
83
+ 'message_plural' => null,
84
+ 'setting' => null
85
+ )
86
+ ) );
87
88
+ // Template styles
89
+ self::$template_styles = apply_filters( 'wcdn_template_styles', array() );
90
+
91
+ // Add the default style as first item after filter hooks passed
92
+ array_unshift( self::$template_styles, array(
93
+ 'name' => __( 'Default', 'woocommerce-delivery-notes' ),
94
+ 'type' => 'default',
95
+ 'path' => WooCommerce_Delivery_Notes::$plugin_path . 'templates/print-order/',
96
+ 'url' => WooCommerce_Delivery_Notes::$plugin_url . 'templates/print-order/'
97
+ ) );
98
+
99
+ // Default template
100
+ $this->template = self::$template_registrations[0];
101
+
102
+ // Build all template locations
103
+ $this->template_locations = $this->build_template_locations();
104
+
105
+ // Add the endpoint for the frontend
106
+ $this->api_endpoints = array(
107
+ 'print-order' => get_option( 'wcdn_print_order_page_endpoint', 'print-order' )
108
);
109
+
110
+ // Insert the query vars
111
$this->query_vars = array(
112
'print-order-type',
113
'print-order-email'
114
);
115
+
116
// Load the hooks
117
add_action( 'init', array( $this, 'load_hooks' ) );
118
add_filter( 'query_vars', array( $this, 'add_query_vars' ) );
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
}
141
142
// Flush the rules when the transient is set.
143
// This is important to make the endpoint work.
144
+ if( get_transient( 'wcdn_flush_rewrite_rules' ) == true ) {
145
+ delete_transient( 'wcdn_flush_rewrite_rules' );
146
flush_rewrite_rules();
147
}
148
}
170
}
171
}
172
}
173
+
174
+ /**
175
+ * Build the template locations
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;
183
+ $settings_url = null;
184
+ if( isset( $settings_type ) && $settings_type !== 'default' ) {
185
+ foreach( self::$template_styles as $template_style ) {
186
+ if( $settings_type === $template_style['type'] ) {
187
+ $settings_path = $template_style['path'];
188
+ $settings_url = $template_style['url'];
189
+ break;
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
*/
236
*/
237
public function template_redirect_admin() {
238
// Let the backend only access the page
239
+ if( is_admin() && current_user_can( 'edit_shop_orders' ) && !empty( $_REQUEST['print-order'] ) && !empty( $_REQUEST['action'] ) ) {
240
$type = !empty( $_REQUEST['print-order-type'] ) ? $_REQUEST['print-order-type'] : null;
241
$email = !empty( $_REQUEST['print-order-email'] ) ? $_REQUEST['print-order-email'] : null;
242
$this->generate_template( $_GET['print-order'], $type, $email );
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 {
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 = '';
293
+ foreach( $this->template_locations as $template_location ) {
294
+ if( isset( $template_location['path'] ) && file_exists( trailingslashit( $template_location['path'] ) . $name ) ) {
295
+ if( $url_mode ) {
296
+ $found = $template_location['url'];
297
+ } else {
298
+ $found = $template_location['path'];
299
+ }
300
+ break;
301
+ }
302
+ }
303
+ return $found;
304
+ }
305
+
306
/**
307
* Get print page url
308
*/
309
+ public function get_print_page_url( $order_ids, $template_type = 'order', $order_email = null, $permalink = false ) {
310
// Explode the ids when needed
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' ) {
321
+ $args = wp_parse_args( array( 'print-order-type' => $template_type ), $args );
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
}
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' );
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 );
358
// Add all other args
359
$url = add_query_arg( $args, $url );
360
361
+ return esc_url( $url );
362
}
363
364
/**
371
$args = array(
372
'posts_per_page' => -1,
373
'post_type' => 'shop_order',
374
+ 'post_status' => 'any',
375
'post__in' => $this->order_ids,
376
'orderby' => 'post__in'
377
);
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
}
457
458
+ ?>
includes/class-wcdn-settings.php CHANGED
@@ -1,5 +1,12 @@
1
<?php
2
3
/**
4
* Settings class
5
*/
@@ -7,421 +14,474 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Settings' ) ) {
7
8
class WooCommerce_Delivery_Notes_Settings {
9
10
- public $tab_name;
11
- public $hidden_submit;
12
13
/**
14
* Constructor
15
*/
16
- public function __construct() {
17
// Define default variables
18
- $this->tab_name = 'woocommerce-delivery-notes';
19
- $this->hidden_submit = WooCommerce_Delivery_Notes::$plugin_prefix . 'submit';
20
-
21
// Load the hooks
22
- add_action( 'admin_init', array( $this, 'load_admin_hooks' ) );
23
}
24
25
/**
26
- * Load the admin hooks
27
*/
28
- public function load_admin_hooks() {
29
- add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_tab' ), 100 );
30
- add_action( 'woocommerce_settings_tabs_' . $this->tab_name, array( $this, 'create_settings_page' ) );
31
- add_action( 'woocommerce_update_options_' . $this->tab_name, array( $this, 'save_settings_page' ) );
32
- add_action( 'current_screen', array( $this, 'load_screen_hooks' ) );
33
- add_action( 'wp_ajax_load_thumbnail', array( $this, 'load_thumbnail_ajax' ) );
34
}
35
36
/**
37
- * Add the scripts
38
*/
39
- public function load_screen_hooks() {
40
- $screen = get_current_screen();
41
-
42
- if( $this->is_settings_page() ) {
43
- add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts' ) );
44
- add_action( 'admin_enqueue_scripts', array( $this, 'add_styles' ) );
45
- }
46
}
47
48
/**
49
- * Add the styles
50
*/
51
- public function add_styles() {
52
- wp_enqueue_style( 'woocommerce-delivery-notes-admin', WooCommerce_Delivery_Notes::$plugin_url . 'css/admin.css' );
53
}
54
55
/**
56
- * Add the scripts
57
*/
58
- public function add_scripts() {
59
- wp_enqueue_media();
60
- wp_enqueue_script( 'woocommerce-delivery-notes-print-link', WooCommerce_Delivery_Notes::$plugin_url . 'js/jquery.print-link.js', array( 'jquery' ) );
61
- wp_enqueue_script( 'woocommerce-delivery-notes-admin', WooCommerce_Delivery_Notes::$plugin_url . 'js/admin.js', array( 'jquery', 'custom-header', 'woocommerce-delivery-notes-print-link' ) );
62
}
63
-
64
/**
65
- * Check if we are on settings page
66
*/
67
- public function is_settings_page() {
68
- if( isset( $_GET['page'] ) && isset( $_GET['tab'] ) && $_GET['tab'] == $this->tab_name ) {
69
- return true;
70
- } else {
71
- return false;
72
}
73
}
74
75
/**
76
- * Check if sequential order plugin is activated
77
*/
78
- public function is_woocommerce_sequential_order_numbers_activated() {
79
- if ( in_array( 'woocommerce-sequential-order-numbers/woocommerce-sequential-order-numbers.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
80
- return true;
81
- } else {
82
- return false;
83
}
84
- }
85
86
/**
87
- * Add a tab to the settings page
88
*/
89
- public function add_settings_tab( $tabs ) {
90
- $tabs[$this->tab_name] = __( 'Print', 'woocommerce-delivery-notes' );
91
92
- return $tabs;
93
}
94
-
95
/**
96
- * Load thumbnail with ajax
97
*/
98
- public function load_thumbnail_ajax() {
99
- $attachment_id = (int)$_POST['attachment_id'];
100
-
101
- // Verify the id
102
- if( !$attachment_id ) {
103
die();
104
}
105
106
- // create the thumbnail
107
- $this->create_thumbnail( $attachment_id );
108
109
exit;
110
}
111
112
/**
113
- * Create the thumbnail
114
*/
115
- public function create_thumbnail( $attachment_id ) {
116
$attachment_src = wp_get_attachment_image_src( $attachment_id, 'medium', false );
117
118
?>
119
- <img src="<?php echo $attachment_src[0]; ?>" alt="" />
120
<?php
121
}
122
123
/**
124
- * Create the settings page content
125
*/
126
- public function create_settings_page() {
127
- ?>
128
- <h3><?php _e( 'Print Order', 'woocommerce-delivery-notes' ); ?></h3>
129
- <p>
130
- <?php
131
- // show template preview links when an order is available
132
- $args = array(
133
- 'post_type' => 'shop_order',
134
- 'posts_per_page' => 1
135
- );
136
- $query = new WP_Query( $args );
137
-
138
- if($query->have_posts()) : ?>
139
- <?php
140
- $results = $query->get_posts();
141
- $test_id = $results[0]->ID;
142
- $invoice_url = wcdn_get_print_link( $test_id, 'invoice' );
143
- $note_url = wcdn_get_print_link( $test_id, 'delivery-note' );
144
- ?>
145
- <input type="hidden" id="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>show_print_preview" />
146
- <span class="description">
147
- <?php printf( __( 'You can preview the <a href="%1$s" target="%3$s" class="%4$s">invoice template</a> or <a href="%2$s" target="%3$s" class="%4$s">delivery note template</a>.', 'woocommerce-delivery-notes' ), $invoice_url, $note_url, '_blank', '' ); ?>
148
- <?php _e( 'With the FAQ in the readme file you can learn how to customize the template.', 'woocommerce-delivery-notes' ); ?>
149
- </span>
150
- <?php endif; ?>
151
- </p>
152
- <table class="form-table">
153
- <tbody>
154
- <tr class="hide-if-no-js">
155
- <?php
156
- $attachment_id = get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'company_logo_image_id' );
157
- ?>
158
- <th>
159
- <label><?php _e( 'Company/Shop Logo', 'woocommerce-delivery-notes' ); ?></label>
160
- </th>
161
- <td>
162
- <input id="company-logo-image-id" type="hidden" name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>company_logo_image_id" class="regular-text" value="<?php echo $attachment_id ?>" />
163
- <div id="company-logo-placeholder"><?php if( !empty( $attachment_id ) ) : ?><?php $this->create_thumbnail( $attachment_id ); ?><?php endif; ?></div>
164
- <div id="company-logo-buttons">
165
- <a href="#" id="company-logo-remove-button" class="button" <?php if( empty( $attachment_id ) ) : ?>style="display: none;"<?php endif; ?>><?php _e( 'Remove Logo', 'woocommerce-delivery-notes' ); ?></a>
166
- <a href="#" id="company-logo-add-button" class="button" <?php if( !empty( $attachment_id ) ) : ?>style="display: none;"<?php endif; ?> data-uploader-title="<?php echo esc_attr( __( 'Set Logo', 'woocommerce-delivery-notes' ) ); ?>" data-uploader-button-title="<?php echo esc_attr( __( 'Set Logo', 'woocommerce-delivery-notes' ) ); ?>"><?php _e( 'Set Logo', 'woocommerce-delivery-notes' ); ?></a>
167
- <span id="company-logo-loader" class="spinner"></span>
168
- </div>
169
- <span class="description">
170
- <?php _e( 'A company/shop logo representing your business.', 'woocommerce-delivery-notes' ); ?>
171
- <strong><?php _e( 'Note:', 'woocommerce-delivery-notes' ); ?></strong>
172
- <?php _e( '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. Example: an image with a width of 576 pixels and a height of 288 pixels will have a printed size of about 2 inches to 1 inch.', 'woocommerce-delivery-notes' ); ?>
173
- </span>
174
- </td>
175
- </tr>
176
- <tr>
177
- <th>
178
- <label><?php _e( 'Company/Shop Name', 'woocommerce-delivery-notes' ); ?></label>
179
- </th>
180
- <td>
181
- <input type="text" name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>custom_company_name" class="large-text" value="<?php echo stripslashes( wp_kses_stripslashes( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'custom_company_name' ) ) ); ?>" />
182
- <span class="description">
183
- <?php _e( 'Your company/shop name for the Delivery Note.', 'woocommerce-delivery-notes' ); ?>
184
- <strong><?php _e( 'Note:', 'woocommerce-delivery-notes' ); ?></strong>
185
- <?php _e( 'Leave blank to use the default Website/Blog title defined in WordPress settings. The name will be ignored when a Logo is set.', 'woocommerce-delivery-notes' ); ?>
186
- </span>
187
- </td>
188
- </tr>
189
- <tr>
190
- <th>
191
- <label for="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>company_address"><?php _e( 'Company/Shop Address', 'woocommerce-delivery-notes' ); ?></label>
192
- </th>
193
- <td>
194
- <textarea name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>company_address" rows="5" class="large-text"><?php echo stripslashes( wp_kses_stripslashes( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'company_address' ) ) ); ?></textarea>
195
- <span class="description">
196
- <?php _e( 'The postal address of the company/shop or even e-mail or telephone, which gets printed right after the company/shop name.', 'woocommerce-delivery-notes' ); ?>
197
- <strong><?php _e( 'Note:', 'woocommerce-delivery-notes' ); ?></strong>
198
- <?php _e('Leave blank to not print an address.', 'woocommerce-delivery-notes' ); ?>
199
- </span>
200
- </td>
201
- </tr>
202
- <tr>
203
- <th>
204
- <label><?php _e( 'Complimentary Close', 'woocommerce-delivery-notes' ); ?></label>
205
- </th>
206
- <td>
207
- <textarea name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>personal_notes" rows="5" class="large-text"><?php echo stripslashes( wp_kses_stripslashes( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'personal_notes' ) ) ); ?></textarea>
208
- <span class="description">
209
- <?php _e( 'Add some personal notes, or season greetings or whatever (e.g. Thank You for Your Order!, Merry Christmas!, etc.).', 'woocommerce-delivery-notes' ); ?>
210
- <strong><?php _e( 'Note:', 'woocommerce-delivery-notes' ); ?></strong>
211
- <?php _e('Leave blank to not print any personal notes.', 'woocommerce-delivery-notes' ); ?>
212
- </span>
213
- </td>
214
- </tr>
215
- <tr>
216
- <th>
217
- <label><?php _e( 'Returns Policy, Conditions, etc', 'woocommerce-delivery-notes' ); ?></label>
218
- </th>
219
- <td>
220
- <textarea name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>policies_conditions" rows="5" class="large-text"><?php echo stripslashes( wp_kses_stripslashes( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'policies_conditions' ) ) ); ?></textarea>
221
- <span class="description">
222
- <?php _e( 'Here you can add some more policies, conditions etc. For example add a returns policy in case the client would like to send back some goods. In some countries (e.g. in the European Union) this is required so please add any required info in accordance with the statutory regulations.', 'woocommerce-delivery-notes' ); ?>
223
- <strong><?php _e( 'Note:', 'woocommerce-delivery-notes' ); ?></strong>
224
- <?php _e('Leave blank to not print any policies or conditions.', 'woocommerce-delivery-notes' ); ?>
225
- </span>
226
- </td>
227
- </tr>
228
- <tr>
229
- <th>
230
- <label for="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>footer_imprint"><?php _e( 'Footer', 'woocommerce-delivery-notes' ); ?></label>
231
- </th>
232
- <td>
233
- <textarea name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>footer_imprint" rows="5" class="large-text"><?php echo stripslashes( wp_kses_stripslashes( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'footer_imprint' ) ) ); ?></textarea>
234
- <span class="description">
235
- <?php _e( 'Add some further footer imprint, e-mail, telephone, copyright notes etc. This makes the printed sheets a bit more branded.', 'woocommerce-delivery-notes' ); ?>
236
- <strong><?php _e( 'Note:', 'woocommerce-delivery-notes' ); ?></strong>
237
- <?php _e('Leave blank to not print a footer.', 'woocommerce-delivery-notes' ); ?>
238
- </span>
239
- </td>
240
- </tr>
241
- </tbody>
242
- </table>
243
-
244
- <h3><?php _e( 'Front-end Options', 'woocommerce-delivery-notes' ); ?></h3>
245
- <table class="form-table">
246
- <tbody>
247
- <tr>
248
- <th>
249
- <label><?php _e( 'Print Page Endpoint', 'woocommerce-delivery-notes' ); ?></label>
250
- </th>
251
- <td>
252
- <p>
253
- <input type="text" name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>print_order_page_endpoint" value="<?php echo get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'print_order_page_endpoint' ); ?>" />
254
- </p>
255
- <span class="description">
256
- <?php _e( 'The endpoint is appended to the accounts page URL to print the order. It should be unique.', 'woocommerce-delivery-notes' ); ?>
257
- </span>
258
- </td>
259
- </tr>
260
- <tr>
261
- <th>
262
- <?php _e( 'Print Buttons', 'woocommerce-delivery-notes' ); ?>
263
- </th>
264
- <td>
265
- <fieldset>
266
- <label>
267
- <input name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>print_button_on_view_order_page" type="hidden" value="" />
268
- <input name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>print_button_on_view_order_page" type="checkbox" value="1" <?php checked( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'print_button_on_view_order_page' ), 1 ); ?> />
269
- <?php _e( 'Show print button on the "View Order" page', 'woocommerce-delivery-notes' ); ?>
270
- </label>
271
- </fieldset>
272
- <fieldset>
273
- <label>
274
- <input name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>print_button_on_my_account_page" type="hidden" value="" />
275
- <input name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>print_button_on_my_account_page" type="checkbox" value="1" <?php checked( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'print_button_on_my_account_page' ), 1 ); ?> />
276
- <?php _e( 'Show print buttons on the "My Account" page', 'woocommerce-delivery-notes' ); ?>
277
- </label>
278
- </fieldset>
279
- </td>
280
- </tr>
281
- </tbody>
282
- </table>
283
284
- <h3><?php _e( 'Order Numbering', 'woocommerce-delivery-notes' ); ?></h3>
285
- <table class="form-table">
286
- <tbody>
287
- <tr>
288
- <th>
289
- <?php _e( 'Invoice Number', 'woocommerce-delivery-notes' ); ?>
290
- </th>
291
- <td>
292
- <p>
293
- <label>
294
- <?php $create_invoice_number = get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'create_invoice_number' ); ?>
295
- <input name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>create_invoice_number" type="hidden" value="" />
296
- <input name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>create_invoice_number" id="create-invoice-number" type="checkbox" value="1" <?php checked( $create_invoice_number, 1 ); ?> />
297
- <?php _e( 'Create invoice numbers', 'woocommerce-delivery-notes' ); ?>
298
- </label>
299
- </p>
300
- </td>
301
- </tr>
302
- <tr class="invoice-number-row" <?php if( empty( $create_invoice_number ) ) : ?> style="display: none;"<?php endif; ?>>
303
- <th>
304
- <label><?php _e( 'Invoice Number Start', 'woocommerce-delivery-notes' ); ?></label>
305
- </th>
306
- <td>
307
- <p>
308
- <input type="text" name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>invoice_number_start" value="<?php echo stripslashes( wp_kses_stripslashes( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'invoice_number_start', 1 ) ) ); ?>" />
309
- </p>
310
- <span class="description">
311
- <?php _e( 'Start the numbering at the specified number.', 'woocommerce-delivery-notes' ); ?>
312
- <strong><?php _e( 'Note:', 'woocommerce-delivery-notes' ); ?></strong>
313
- <?php _e( 'Use only integers.', 'woocommerce-delivery-notes' ); ?>
314
- <?php _e( 'Already created invoice numbers are not affected by changes.', 'woocommerce-delivery-notes' ); ?>
315
- </span>
316
- </td>
317
- </tr>
318
- <tr class="invoice-number-row" <?php if( empty( $create_invoice_number ) ) : ?> style="display: none;"<?php endif; ?>>
319
- <th>
320
- <label><?php _e( 'Invoice Number Prefix', 'woocommerce-delivery-notes' ); ?></label>
321
- </th>
322
- <td>
323
- <p>
324
- <input type="text" name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>invoice_number_prefix" value="<?php echo stripslashes( wp_kses_stripslashes( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'invoice_number_prefix' ) ) ); ?>" />
325
- </p>
326
- <span class="description">
327
- <?php _e( 'This text will be prepended to the invoice number.', 'woocommerce-delivery-notes' ); ?>
328
- <strong><?php _e( 'Note:', 'woocommerce-delivery-notes' ); ?></strong>
329
- <?php _e( 'Leave blank to not add a prefix.', 'woocommerce-delivery-notes' ); ?>
330
- <?php _e( 'Already created invoice numbers are not affected by changes.', 'woocommerce-delivery-notes' ); ?>
331
- </span>
332
- </td>
333
- </tr>
334
- <tr class="invoice-number-row" <?php if( empty( $create_invoice_number ) ) : ?> style="display: none;"<?php endif; ?>>
335
- <th>
336
- <label><?php _e( 'Invoice Number Suffix', 'woocommerce-delivery-notes' ); ?></label>
337
- </th>
338
- <td>
339
- <p>
340
- <input type="text" name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>invoice_number_suffix" value="<?php echo stripslashes( wp_kses_stripslashes( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'invoice_number_suffix' ) ) ); ?>" />
341
- </p>
342
- <span class="description">
343
- <?php _e( 'This text will be appended to the invoice number.', 'woocommerce-delivery-notes' ); ?>
344
- <strong><?php _e( 'Note:', 'woocommerce-delivery-notes' ); ?></strong>
345
- <?php _e( 'Leave blank to not add a suffix.', 'woocommerce-delivery-notes' ); ?>
346
- <?php _e( 'Already created invoice numbers are not affected by changes.', 'woocommerce-delivery-notes' ); ?>
347
- </span>
348
- </td>
349
- </tr>
350
- <tr>
351
- <th>
352
- <label><?php _e( 'Sequential Order Number', 'woocommerce-delivery-notes' ); ?></label>
353
- </th>
354
- <td>
355
- <?php if( $this->is_woocommerce_sequential_order_numbers_activated() ) : ?>
356
- <?php _e( 'Sequential numbering is enabled.', 'woocommerce-delivery-notes' ); ?>
357
- <?php else : ?>
358
- <?php printf( __( 'Install and activate the free <a href="%s">WooCommerce Sequential Order Numbers</a> Plugin.', 'woocommerce-delivery-notes' ), 'http://wordpress.org/extend/plugins/woocommerce-sequential-order-numbers/' ); ?>
359
- <?php endif; ?>
360
- </td>
361
- </tr>
362
- </tbody>
363
- </table>
364
365
- <input type="hidden" name="<?php echo $this->hidden_submit; ?>" value="submitted">
366
- <?php
367
}
368
369
/**
370
- * Save all settings
371
- */
372
- public function save_settings_page() {
373
- if ( isset( $_POST[ $this->hidden_submit ] ) && $_POST[ $this->hidden_submit ] == 'submitted' ) {
374
-
375
- // Save settings
376
- foreach ( $_POST as $key => $value ) {
377
- if ( $key != $this->hidden_submit && strpos( $key, WooCommerce_Delivery_Notes::$plugin_prefix ) !== false ) {
378
- // Set a default values
379
- if ( empty( $value ) ) {
380
- if ( $key == WooCommerce_Delivery_Notes::$plugin_prefix . 'print_order_page_endpoint' ) {
381
- $value = 'print-order';
382
- }
383
-
384
- if ( $key == WooCommerce_Delivery_Notes::$plugin_prefix . 'invoice_number_start' ) {
385
- $value = 1;
386
- }
387
- }
388
-
389
- // Sanitize values
390
- if ( $key == WooCommerce_Delivery_Notes::$plugin_prefix . 'print_order_page_endpoint' ) {
391
- $value = sanitize_title( $value );
392
- }
393
-
394
- if ( $key == WooCommerce_Delivery_Notes::$plugin_prefix . 'invoice_number_start' ) {
395
- if ( !ctype_digit( $value ) ) {
396
- $value = 1;
397
- }
398
-
399
- // Check if the counter should be reset
400
- if( get_option( $key ) != $value ) {
401
- update_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'invoice_number_counter', 0 );
402
- }
403
-
404
- }
405
-
406
- // Update the value
407
- if ( empty( $value ) ) {
408
- delete_option( $key );
409
- } else {
410
- if ( get_option( $key ) && get_option( $key ) != $value ) {
411
- update_option( $key, $value );
412
- }
413
- else {
414
- add_option( $key, $value );
415
- }
416
- }
417
- }
418
}
419
-
420
- // Flush permalink structs with
421
- set_transient( WooCommerce_Delivery_Notes::$plugin_prefix . 'flush_rewrite_rules', true );
422
}
423
}
424
-
425
}
426
427
}
1
<?php
2
3
+ /**
4
+ * Exit if accessed directly
5
+ */
6
+ if ( !defined( 'ABSPATH' ) ) {
7
+ exit;
8
+ }
9
+
10
/**
11
* Settings class
12
*/
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' ) );
29
+ add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) );
30
+ add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) );
31
+
32
+ add_action( 'woocommerce_admin_field_wcdn_image_select', array( $this, 'output_image_select' ) );
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' ) );
47
+ wp_enqueue_script( 'woocommerce-delivery-notes-admin', WooCommerce_Delivery_Notes::$plugin_url . 'js/admin.js', array( 'jquery', 'custom-header', 'woocommerce-delivery-notes-print-link' ) );
48
+
49
+ // Localize the script strings
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
*/
57
+ public function add_settings_page( $settings_tabs ) {
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
*/
65
+ public function output() {
66
+ global $current_section;
67
+ $settings = $this->get_settings( $current_section );
68
+ woocommerce_admin_fields( $settings );
69
+ }
70
+
71
+ /**
72
+ * Save the settings
73
+ */
74
+ function save() {
75
+ global $current_section;
76
+ set_transient( 'wcdn_flush_rewrite_rules', true );
77
+ $settings = $this->get_settings( $current_section );
78
+ woocommerce_update_options( $settings );
79
}
80
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/', '#' ),
97
+ 'id' => 'wcdn_template_style',
98
+ 'class' => 'wc-enhanced-select',
99
+ 'default' => '',
100
+ 'type' => 'select',
101
+ 'options' => $this->get_options_styles(),
102
+ 'desc_tip' => false,
103
+ ),
104
+
105
+ array(
106
+ 'title' => __( 'Shop Logo', 'woocommerce-delivery-notes' ),
107
+ 'desc' => '',
108
+ 'id' => 'wcdn_company_logo_image_id',
109
+ 'css' => '',
110
+ 'default' => '',
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' => '',
118
+ 'id' => 'wcdn_custom_company_name',
119
+ 'css' => 'min-width:100%;',
120
+ 'default' => '',
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' ),
128
+ 'id' => 'wcdn_company_address',
129
+ 'css' => 'min-width:100%;min-height:100px;',
130
+ 'default' => '',
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' ),
138
+ 'id' => 'wcdn_personal_notes',
139
+ 'css' => 'min-width:100%;min-height:100px;',
140
+ 'default' => '',
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' ),
148
+ 'id' => 'wcdn_policies_conditions',
149
+ 'css' => 'min-width:100%;min-height:100px;',
150
+ 'default' => '',
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' ),
158
+ 'id' => 'wcdn_footer_imprint',
159
+ 'css' => 'min-width:100%;min-height:100px;',
160
+ 'default' => '',
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' => '',
180
+ 'id' => 'wcdn_print_order_page_endpoint',
181
+ 'css' => '',
182
+ 'default' => 'print-order',
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' ),
190
+ 'id' => 'wcdn_email_print_link',
191
+ 'default' => 'no',
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' ),
199
+ 'id' => 'wcdn_print_button_on_view_order_page',
200
+ 'default' => 'no',
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',
208
+ 'default' => 'no',
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' ),
228
+ 'id' => 'wcdn_create_invoice_number',
229
+ 'default' => 'no',
230
+ 'type' => 'checkbox',
231
+ 'desc_tip' => ''
232
+ ),
233
+
234
+ array(
235
+ 'title' => __( 'Next Number', 'woocommerce-delivery-notes' ),
236
+ 'desc' => '',
237
+ 'id' => 'wcdn_invoice_number_count',
238
+ 'class' => 'create-invoice',
239
+ 'css' => '',
240
+ 'default' => 1,
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' => '',
248
+ 'id' => 'wcdn_invoice_number_prefix',
249
+ 'class' => 'create-invoice',
250
+ 'css' => '',
251
+ 'default' => '',
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' => '',
259
+ 'id' => 'wcdn_invoice_number_suffix',
260
+ 'class' => 'create-invoice',
261
+ 'css' => '',
262
+ 'default' => '',
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
+
290
/**
291
+ * Generate the template type setting fields
292
*/
293
+ public function generate_template_type_fields( $settings, $section = '' ) {
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 );
301
+ $end = count( $template_registrations ) - 1;
302
+ foreach( $template_registrations as $index => $template_registration ) {
303
+ $title = '';
304
+ $desc_tip = '';
305
+ $checkboxgroup = '';
306
+
307
+ // Define the group settings
308
+ if( $index == 0 ) {
309
+ $title = __( 'Admin', 'woocommerce-delivery-notes' );
310
+ $checkboxgroup = 'start';
311
+ } else if( $index == $end ) {
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,
319
+ 'desc' => $template_registration['labels']['setting'],
320
+ 'id' => 'wcdn_template_type_' . $template_registration['type'],
321
+ 'default' => 'no',
322
+ 'type' => 'checkbox',
323
+ 'checkboxgroup' => $checkboxgroup,
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',
342
+ 'post_status' => array( 'wc-pending', 'wc-processing', 'wc-on-hold', 'wc-completed', 'wc-cancelled', 'wc-refunded', 'wc-failed' ),
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
*/
378
+ public function load_image_ajax() {
379
+ // Verify the nonce
380
+ if ( empty( $_REQUEST['nonce'] ) || ! wp_verify_nonce( $_REQUEST['nonce'], 'woocommerce-settings' ) ) {
381
+ die();
382
+ }
383
+
384
+ // Verify the id
385
+ if( empty( $_POST['attachment_id'] ) ) {
386
die();
387
}
388
389
+ // create the image
390
+ $this->create_image( $_POST['attachment_id'] );
391
392
exit;
393
}
394
395
/**
396
+ * Create image
397
*/
398
+ public function create_image( $attachment_id ) {
399
$attachment_src = wp_get_attachment_image_src( $attachment_id, 'medium', false );
400
+ $orientation = 'landscape';
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
*/
413
+ public function output_image_select( $value ) {
414
+ // Define the defaults
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'] ); ?> ">
440
+ <div class="thumbnail">
441
+ <div class="centered">
442
+ <?php if( !empty( $option_value ) ) : ?>
443
+ <?php $this->create_image( $option_value ); ?>
444
+ <?php endif; ?>
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'] ); ?>
452
+ </a>
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
470
+ if( $position == 0 ) {
471
+ $new_array = array_merge( $insert, $array );
472
+ } else {
473
+ // if pos is end just merge them
474
+ if( $position >= ( count( $array ) - 1 ) ) {
475
+ $new_array = array_merge($array, $insert);
476
+ } else {
477
+ // split into head and tail, then merge head+inserted bit+tail
478
+ $head = array_slice( $array, 0, $position );
479
+ $tail = array_slice( $array, $position );
480
+ $new_array = array_merge( $head, $insert, $tail );
481
}
482
}
483
+ return $new_array;
484
}
485
}
486
487
}
includes/class-wcdn-theme.php CHANGED
@@ -1,14 +1,19 @@
1
<?php
2
3
/**
4
* Frontend Theme class
5
*/
6
if ( !class_exists( 'WooCommerce_Delivery_Notes_Theme' ) ) {
7
8
class WooCommerce_Delivery_Notes_Theme {
9
-
10
- public $template_type;
11
-
12
/**
13
* Constructor
14
*/
@@ -22,14 +27,12 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Theme' ) ) {
22
* the theme and plugins are ready.
23
*/
24
public function load_hooks() {
25
- // Define defaults
26
- $this->template_type = apply_filters( 'wcdn_theme_print_button_template_type', 'invoice' );
27
-
28
// hooks
29
add_filter( 'woocommerce_my_account_my_orders_actions', array( $this, 'create_print_button_account_page' ), 10, 2 );
30
add_action( 'woocommerce_view_order', array( $this, 'create_print_button_order_page' ) );
31
add_action( 'woocommerce_thankyou', array( $this, 'create_print_button_order_page' ) );
32
add_action( 'wp_enqueue_scripts', array( $this, 'add_scripts' ) );
33
}
34
35
/**
@@ -46,9 +49,10 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Theme' ) ) {
46
* Create a print button for the 'My Account' page
47
*/
48
public function create_print_button_account_page( $actions, $order ) {
49
- if( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'print_button_on_my_account_page' ) ) {
50
$actions['print'] = array(
51
- 'url' => wcdn_get_print_link( $order->id, $this->template_type ),
52
'name' => __( 'Print', 'woocommerce-delivery-notes' )
53
);
54
}
@@ -58,14 +62,30 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Theme' ) ) {
58
/**
59
* Create a print button for the 'View Order' page
60
*/
61
- public function create_print_button_order_page( $order_id ) {
62
- if( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'print_button_on_view_order_page' ) ) {
63
- $print_url = wcdn_get_print_link( $order_id, $this->template_type );
64
65
- // use a different url for the tracking page
66
if( $this->is_woocommerce_tracking_page() ) {
67
- $print_url = wcdn_get_print_link( $order_id, $this->template_type, $_REQUEST['order_email'] );
68
}
69
?>
70
<p class="order-print">
71
<a href="<?php echo $print_url; ?>" class="button print"><?php _e( 'Print', 'woocommerce-delivery-notes' ); ?></a>
@@ -74,6 +94,39 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Theme' ) ) {
74
}
75
}
76
77
/**
78
* Is WooCommerce 'Order Tracking' page
79
*/
1
<?php
2
3
+ /**
4
+ * Exit if accessed directly
5
+ */
6
+ if ( !defined( 'ABSPATH' ) ) {
7
+ exit;
8
+ }
9
+
10
/**
11
* Frontend Theme class
12
*/
13
if ( !class_exists( 'WooCommerce_Delivery_Notes_Theme' ) ) {
14
15
class WooCommerce_Delivery_Notes_Theme {
16
+
17
/**
18
* Constructor
19
*/
27
* the theme and plugins are ready.
28
*/
29
public function load_hooks() {
30
// hooks
31
add_filter( 'woocommerce_my_account_my_orders_actions', array( $this, 'create_print_button_account_page' ), 10, 2 );
32
add_action( 'woocommerce_view_order', array( $this, 'create_print_button_order_page' ) );
33
add_action( 'woocommerce_thankyou', array( $this, 'create_print_button_order_page' ) );
34
add_action( 'wp_enqueue_scripts', array( $this, 'add_scripts' ) );
35
+ add_action( 'woocommerce_email_after_order_table', array( $this, 'add_email_print_url' ), 100, 3 );
36
}
37
38
/**
49
* Create a print button for the 'My Account' page
50
*/
51
public function create_print_button_account_page( $actions, $order ) {
52
+ if( get_option( 'wcdn_print_button_on_my_account_page' ) == 'yes' ) {
53
+ // Add the print button
54
$actions['print'] = array(
55
+ 'url' => wcdn_get_print_link( $order->id, $this->get_template_type( $order ) ),
56
'name' => __( 'Print', 'woocommerce-delivery-notes' )
57
);
58
}
62
/**
63
* Create a print button for the 'View Order' page
64
*/
65
+ public function create_print_button_order_page( $order_id ) {
66
+ $order = new WC_Order( $order_id );
67
+
68
+ // Output the button only when the option is enabled
69
+ if( get_option( 'wcdn_print_button_on_view_order_page' ) == 'yes' ) {
70
+ // Default button for all pages and logged in users
71
+ $print_url = wcdn_get_print_link( $order_id, $this->get_template_type( $order ) );
72
73
+ // Pass the email to the url for the tracking
74
+ // and thank you page. This allows to view the
75
+ // print page without logging in.
76
if( $this->is_woocommerce_tracking_page() ) {
77
+ $print_url = wcdn_get_print_link( $order_id, $this->get_template_type( $order ), $_REQUEST['order_email'] );
78
+ }
79
+
80
+ // Thank you page
81
+ if( is_order_received_page() && !is_user_logged_in() ) {
82
+ // Don't output the butten when there is no email
83
+ if( !$order->billing_email ) {
84
+ return;
85
+ }
86
+ $print_url = wcdn_get_print_link( $order_id, $this->get_template_type( $order ), $order->billing_email );
87
}
88
+
89
?>
90
<p class="order-print">
91
<a href="<?php echo $print_url; ?>" class="button print"><?php _e( 'Print', 'woocommerce-delivery-notes' ); ?></a>
94
}
95
}
96
97
+ /**
98
+ * Add a print url to the emails that are sent to the customer
99
+ */
100
+ public function add_email_print_url( $order, $sent_to_admin = true, $plain_text = false ) {
101
+ if( get_option( 'wcdn_email_print_link' ) == 'yes' ) {
102
+ if( $order->billing_email && !$sent_to_admin ) {
103
+ $url = wcdn_get_print_link( $order->id, $this->get_template_type( $order ), $order->billing_email, true );
104
+
105
+ if( $plain_text ) :
106
+ echo __( 'Print your order', 'woocommerce-delivery-notes' ) . "\n\n";
107
+
108
+ echo $url . "\n";
109
+
110
+ echo "\n****************************************************\n\n";
111
+ else : ?>
112
+ <p><strong><?php _e( 'Print:', 'woocommerce-delivery-notes' ); ?></strong> <a href="<?php echo $url; ?>"><?php _e( 'Open print view in browser', 'woocommerce-delivery-notes' ); ?></a></p>
113
+ <?php endif;
114
+ }
115
+ }
116
+ }
117
+
118
+ /**
119
+ * Get the print button template type depnding on order status
120
+ */
121
+ public function get_template_type( $order ) {
122
+ if( $order->status == 'completed' ) {
123
+ $type = apply_filters( 'wcdn_theme_print_button_template_type_complete_status', 'invoice' );
124
+ } else {
125
+ $type = apply_filters( 'wcdn_theme_print_button_template_type', 'order' );
126
+ }
127
+ return $type;
128
+ }
129
+
130
/**
131
* Is WooCommerce 'Order Tracking' page
132
*/
includes/class-wcdn-writepanel.php CHANGED
@@ -1,12 +1,19 @@
1
<?php
2
3
/**
4
* Writepanel class
5
*/
6
if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
7
8
class WooCommerce_Delivery_Notes_Writepanel {
9
-
10
/**
11
* Constructor
12
*/
@@ -18,7 +25,8 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
18
/**
19
* Load the admin hooks
20
*/
21
- public function load_admin_hooks() {
22
add_action( 'woocommerce_admin_order_actions_end', array( $this, 'add_listing_actions' ) );
23
add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts' ) );
24
add_action( 'admin_enqueue_scripts', array( $this, 'add_styles' ) );
@@ -47,7 +55,7 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
47
if( $this->is_order_edit_page() || $this->is_order_post_page() ) {
48
wp_enqueue_script( 'thickbox' );
49
wp_enqueue_script( 'woocommerce-delivery-notes-print-link', WooCommerce_Delivery_Notes::$plugin_url . 'js/jquery.print-link.js', array( 'jquery' ) );
50
- wp_enqueue_script( 'woocommerce-delivery-notes-admin', WooCommerce_Delivery_Notes::$plugin_url . 'js/admin.js', array( 'jquery', 'woocommerce-delivery-notes-print-link', 'thickbox' ) );
51
}
52
}
53
@@ -79,13 +87,17 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
79
* Add print actions to the orders listing
80
*/
81
public function add_listing_actions( $order ) {
82
- ?>
83
- <a href="<?php echo wcdn_get_print_link( $order->id, 'invoice' ); ?>" class="button tips print-preview-button invoice" target="_blank" alt="<?php esc_attr_e( 'Print Invoice', 'woocommerce-delivery-notes' ); ?>" data-tip="<?php esc_attr_e( 'Print Invoice', 'woocommerce-delivery-notes' ); ?>">
84
- <?php _e( 'Print Invoice', 'woocommerce-delivery-notes' ); ?>
85
- </a>
86
- <a href="<?php echo wcdn_get_print_link( $order->id, 'delivery-note' ); ?>" class="button tips print-preview-button delivery-note" target="_blank" alt="<?php esc_attr_e( 'Print Delivery Note', 'woocommerce-delivery-notes' ); ?>" data-tip="<?php esc_attr_e( 'Print Delivery Note', 'woocommerce-delivery-notes' ); ?>">
87
- <?php _e( 'Print Delivery Note', 'woocommerce-delivery-notes' ); ?>
88
- </a>
89
<span class="print-preview-loading spinner"></span>
90
<?php
91
}
@@ -102,11 +114,14 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
102
if( $this->is_order_edit_page() ) : ?>
103
<script type="text/javascript">
104
jQuery(document).ready(function($) {
105
- $('<option>').val('wcdn_print_invoice').attr('title', 'invoice').text('<?php echo esc_js( __( 'Print Invoice', 'woocommerce-delivery-notes' ) ); ?>').appendTo('select[name="action"]');
106
- $('<option>').val('wcdn_print_invoice').attr('title', 'invoice').text('<?php echo esc_js( __( 'Print Invoice', 'woocommerce-delivery-notes' ) ); ?>').appendTo('select[name="action2"]');
107
-
108
- $('<option>').val('wcdn_print_delivery_note').attr('title', 'delivery-note').text('<?php echo esc_js( __( 'Print Delivery Note', 'woocommerce-delivery-notes' ) ); ?>').appendTo('select[name="action"]');
109
- $('<option>').val('wcdn_print_delivery_note').attr('title', 'delivery-note').text('<?php echo esc_js( __( 'Print Delivery Note', 'woocommerce-delivery-notes' ) ); ?>').appendTo('select[name="action2"]');
110
});
111
</script>
112
<?php endif;
@@ -120,32 +135,61 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
120
// get the action staht should be started
121
$wp_list_table = _get_list_table('WP_Posts_List_Table');
122
$action = $wp_list_table->current_action();
123
-
124
// stop if there are no post ids
125
if( !isset( $_REQUEST['post'] ) ) {
126
return;
127
}
128
129
// only for specified actions
130
- switch ( $action ) {
131
- case 'wcdn_print_invoice':
132
- $template_type = 'invoice';
133
- $report_action = 'printed_invoice';
134
- break;
135
- case 'wcdn_print_delivery_note':
136
- $template_type = 'delivery-note';
137
- $report_action = 'printed_delivery_note';
138
break;
139
- default:
140
- return;
141
}
142
143
// do the action
144
$post_ids = array_map( 'absint', (array) $_REQUEST['post'] );
145
$total = count( $post_ids );
146
$url = wcdn_get_print_link( $post_ids , $template_type );
147
- $sendback = add_query_arg( array( 'post_type' => 'shop_order', $report_action => true, 'total' => $total, 'print_url' => urlencode( $url ) ), '' );
148
149
wp_redirect( $sendback );
150
exit;
151
}
@@ -156,20 +200,24 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
156
*/
157
public function confirm_bulk_actions() {
158
if( $this->is_order_edit_page() ) {
159
- if ( isset( $_REQUEST['printed_delivery_note'] ) || isset( $_REQUEST['printed_invoice'] ) ) {
160
- $total = isset( $_REQUEST['total'] ) ? absint( $_REQUEST['total'] ) : 0;
161
-
162
- // Confirmation message
163
- if( isset( $_REQUEST['printed_invoice'] ) ) {
164
- $message = sprintf( _n( 'Invoice created.', '%s invoices created.', $total, 'woocommerce-delivery-notes' ), number_format_i18n( $total ) );
165
- } elseif( isset( $_REQUEST['printed_delivery_note'] ) ) {
166
- $message = sprintf( _n( 'Delivery note created.', '%s delivery notes created.', $total, 'woocommerce-delivery-notes' ), number_format_i18n( $total ) );
167
}
168
- ?>
169
- <div id="woocommerce-delivery-notes-bulk-print-message" class="updated">
170
- <p><?php echo $message; ?> <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>
171
- </div>
172
- <?php
173
}
174
}
175
}
@@ -185,21 +233,30 @@ if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
185
* Create the meta box content on the single order page
186
*/
187
public function create_box_content() {
188
- global $post_id;
189
- $create_invoice_number = get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'create_invoice_number' );
190
?>
191
<div class="print-actions">
192
- <a href="<?php echo wcdn_get_print_link( $post_id, 'invoice' ); ?>" class="button print-preview-button" target="_blank" alt="<?php esc_attr_e( 'Print Invoice', 'woocommerce-delivery-notes' ); ?>"><?php _e( 'Print Invoice', 'woocommerce-delivery-notes' ); ?></a>
193
- <a href="<?php echo wcdn_get_print_link( $post_id, 'delivery-note' ); ?>" class="button print-preview-button" target="_blank" alt="<?php esc_attr_e( 'Print Delivery Note', 'woocommerce-delivery-notes' ); ?>"><?php _e( 'Print Delivery Note', 'woocommerce-delivery-notes' ); ?></a>
194
<span class="print-preview-loading spinner"></span>
195
</div>
196
<?php
197
- if( !empty( $create_invoice_number ) ) :
198
$invoice_number = wcdn_get_order_invoice_number( $post_id );
199
- ?>
200
- <div class="print-info">
201
- <strong><?php _e( 'Invoice number: ', 'woocommerce-delivery-notes' ); ?></strong> <?php echo $invoice_number; ?>
202
- </div>
203
<?php endif; ?>
204
<?php
205
}
1
<?php
2
3
+ /**
4
+ * Exit if accessed directly
5
+ */
6
+ if ( !defined( 'ABSPATH' ) ) {
7
+ exit;
8
+ }
9
+
10
/**
11
* Writepanel class
12
*/
13
if ( !class_exists( 'WooCommerce_Delivery_Notes_Writepanel' ) ) {
14
15
class WooCommerce_Delivery_Notes_Writepanel {
16
+
17
/**
18
* Constructor
19
*/
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' ) );
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
87
* Add print actions to the orders listing
88
*/
89
public function add_listing_actions( $order ) {
90
+ ?>
91
+ <?php foreach( WooCommerce_Delivery_Notes_Print::$template_registrations as $template_registration ) : ?>
92
+ <?php if( get_option( 'wcdn_template_type_' . $template_registration['type'] ) == 'yes' && $template_registration['type'] !== 'order' ) : ?>
93
+
94
+ <a href="<?php echo wcdn_get_print_link( $order->id, $template_registration['type'] ); ?>" class="button tips print-preview-button <?php echo $template_registration['type']; ?>" target="_blank" alt="<?php esc_attr_e( __( $template_registration['labels']['print'], 'woocommerce-delivery-notes' ) ); ?>" data-tip="<?php esc_attr_e( __( $template_registration['labels']['print'], 'woocommerce-delivery-notes' ) ); ?>">
95
+ <?php _e( $template_registration['labels']['print'], 'woocommerce-delivery-notes' ); ?>
96
+ </a>
97
+
98
+ <?php endif; ?>
99
+ <?php endforeach; ?>
100
+
101
<span class="print-preview-loading spinner"></span>
102
<?php
103
}
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
+
120
+ $('<option>').val('wcdn_print_<?php echo $template_registration['type']; ?>').attr('title', '<?php echo $template_registration['type']; ?>').text('<?php echo esc_js( __( $template_registration['labels']['print'], 'woocommerce-delivery-notes' ) ); ?>').appendTo('select[name="action"]');
121
+ $('<option>').val('wcdn_print_<?php echo $template_registration['type']; ?>').attr('title', '<?php echo $template_registration['type']; ?>').text('<?php echo esc_js( __( $template_registration['labels']['print'], 'woocommerce-delivery-notes' ) ); ?>').appendTo('select[name="action2"]');
122
+
123
+ <?php endif; ?>
124
+ <?php endforeach; ?>
125
});
126
</script>
127
<?php endif;
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'] ) {
147
+ $template_type = $template_registration['type'];
148
+ $report_action = 'printed_' . $template_registration['type'];
149
break;
150
+ }
151
+ }
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 );
174
+ }
175
+ if( isset( $referer_args['paged'] ) ) {
176
+ $args = wp_parse_args( array( 'paged' => $referer_args['paged'] ), $args );
177
+ }
178
+ if( isset( $referer_args['orderby'] ) ) {
179
+ $args = wp_parse_args( array( 'orderby' => $referer_args['orderby'] ), $args );
180
+ }
181
+ if( isset( $referer_args['order'] ) ) {
182
+ $args = wp_parse_args( array( 'orderby' => $referer_args['order'] ), $args );
183
+ }
184
+
185
// do the action
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, '' );
193
wp_redirect( $sendback );
194
exit;
195
}
200
*/
201
public function confirm_bulk_actions() {
202
if( $this->is_order_edit_page() ) {
203
+ foreach( WooCommerce_Delivery_Notes_Print::$template_registrations as $template_registration ) {
204
+ if( isset( $_REQUEST['printed_' . $template_registration['type']] ) ) {
205
+ // use singular or plural form
206
+ $total = isset( $_REQUEST['total'] ) ? absint( $_REQUEST['total'] ) : 0;
207
+ if( $total <= 1 ) {
208
+ $message = $template_registration['labels']['message'];
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
}
221
}
222
}
223
}
233
* Create the meta box content on the single order page
234
*/
235
public function create_box_content() {
236
+ global $post_id, $wcdn;
237
?>
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
}
includes/wcdn-template-functions.php CHANGED
@@ -1,11 +1,21 @@
1
<?php
2
3
/**
4
* Output the template part
5
*/
6
function wcdn_get_template_content( $name, $args = null ) {
7
global $wcdn;
8
- wc_get_template( $name, $args, $wcdn->print->template_path_theme, $wcdn->print->template_path_plugin );
9
}
10
11
/**
@@ -13,28 +23,30 @@ function wcdn_get_template_content( $name, $args = null ) {
13
*/
14
function wcdn_get_template_type() {
15
global $wcdn;
16
- return apply_filters( 'wcdn_template_type', $wcdn->print->template_type );
17
}
18
19
/**
20
* Return print page link
21
*/
22
- function wcdn_get_print_link( $order_ids, $template_type = 'order', $order_email = null ) {
23
global $wcdn;
24
- return $wcdn->print->get_print_page_url( $order_ids, $template_type, $order_email );
25
}
26
27
/**
28
* Output the document title depending on type
29
*/
30
function wcdn_document_title() {
31
- if( wcdn_get_template_type() == 'invoice' ) {
32
- echo apply_filters( 'wcdn_document_title', __( 'Invoice', 'woocommerce-delivery-notes' ) );
33
- } elseif( wcdn_get_template_type() == 'delivery-note' ) {
34
- echo apply_filters( 'wcdn_document_title', __( 'Delivery Note', 'woocommerce-delivery-notes' ) );
35
- } else {
36
- echo apply_filters( 'wcdn_document_title', __( 'Order', 'woocommerce-delivery-notes' ) );
37
- }
38
}
39
40
/**
@@ -127,16 +139,32 @@ function wcdn_template_stylesheet() {
127
global $wcdn;
128
$name = apply_filters( 'wcdn_template_stylesheet_name', 'style.css' );
129
?>
130
- <link rel="stylesheet" href="<?php echo $wcdn->print->get_template_url( $name ); ?>" type="text/css" media="screen,print" />
131
<?php
132
}
133