WooCommerce Sequential Order Numbers - Version 1.2.2

Version Description

  • Takes advantage of new action hooks/filters available in WooCommerce 1.5.6
  • Bug fix on installation to stores with more than 10 existing orders
Download this release

Release Info

Developer FoxRunSoftware
Plugin Icon WooCommerce Sequential Order Numbers
Version 1.2.2
Comparing to
See all releases

Code changes from version 1.2.1 to 1.2.2

Files changed (2) hide show
  1. readme.txt +27 -2
  2. woocommerce-sequential-order-numbers.php +79 -589
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: FoxRunSoftware
3
Tags: woocommerce, order number
4
Requires at least: 3.3
5
Tested up to: 3.3
6
- Stable tag: 1.2.1
7
8
This plugin extends the WooCommerce e-commerce plugin by setting sequential order numbers for new orders.
9
@@ -11,7 +11,9 @@ This plugin extends the WooCommerce e-commerce plugin by setting sequential orde
11
12
This plugin extends the WooCommerce e-commerce plugin by setting sequential order numbers for new orders. If there are existing orders at the time of installation, the sequential order numbers will start with the highest current order number.
13
14
- This plugin requires WooCommerce 1.5.5 or greater.
15
16
= Feedback =
17
* I am open to your suggestions and feedback - Thank you for using or trying out one of my plugins!
@@ -19,6 +21,7 @@ This plugin requires WooCommerce 1.5.5 or greater.
19
20
= More =
21
* Vist the [WooCommerce Sequential Order Number plugin page](http://www.foxrunsoftware.net/articles/wordpress/woocommerce-sequential-order-numbers/) for further details and a discussion of the implementation. [Also see my other plugins](http://www.foxrunsoftware.com) or see [my WordPress.org profile page](http://profiles.wordpress.org/foxrunsoftware/)
22
23
== Installation ==
24
@@ -26,8 +29,22 @@ This plugin requires WooCommerce 1.5.5 or greater.
26
2. Activate the plugin through the 'Plugins' menu in WordPress
27
3. Order numbers will continue sequentially from the current highest order number, or from 1 if no orders have been placed yet
28
29
== Changelog ==
30
31
= 1.2.1 =
32
* Minor updates due to WooCommerce 1.5.5 release
33
@@ -48,3 +65,11 @@ This plugin requires WooCommerce 1.5.5 or greater.
48
49
= 1.0.0 =
50
* Initial Release
3
Tags: woocommerce, order number
4
Requires at least: 3.3
5
Tested up to: 3.3
6
+ Stable tag: 1.2.2
7
8
This plugin extends the WooCommerce e-commerce plugin by setting sequential order numbers for new orders.
9
11
12
This plugin extends the WooCommerce e-commerce plugin by setting sequential order numbers for new orders. If there are existing orders at the time of installation, the sequential order numbers will start with the highest current order number.
13
14
+ If you like this plugin, but are looking for the ability to set the starting number, or to add a custom prefix/suffix to your order numbers (ie, you'd prefer something like WT101UK, WT102UK, etc) please consider my newly released paid WooCommerce Sequential Order Numbers Pro plugin, available from the [WooThemes Store](http://www.woothemes.com/extension/sequential-order-numbers-pro/)
15
+
16
+ This plugin requires WooCommerce 1.5.6 or greater.
17
18
= Feedback =
19
* I am open to your suggestions and feedback - Thank you for using or trying out one of my plugins!
21
22
= More =
23
* Vist the [WooCommerce Sequential Order Number plugin page](http://www.foxrunsoftware.net/articles/wordpress/woocommerce-sequential-order-numbers/) for further details and a discussion of the implementation. [Also see my other plugins](http://www.foxrunsoftware.com) or see [my WordPress.org profile page](http://profiles.wordpress.org/foxrunsoftware/)
24
+ * Find the enhanced WooCommerce Sequential Order Numbers Pro now available from [WooThemes](http://www.woothemes.com/extension/sequential-order-numbers-pro/)
25
26
== Installation ==
27
29
2. Activate the plugin through the 'Plugins' menu in WordPress
30
3. Order numbers will continue sequentially from the current highest order number, or from 1 if no orders have been placed yet
31
32
+ == Frequently Asked Questions ==
33
+
34
+ = Can I start the order numbers at a particular number? =
35
+
36
+ This free version does not have that functionality, but now you can with the paid [WooCommerce Sequential Order Numbers Pro](http://www.woothemes.com/extension/sequential-order-numbers-pro/)
37
+
38
+ = Can I set an order number prefix/suffix? =
39
+
40
+ This free version does not have that functionality, but now you can with the paid [WooCommerce Sequential Order Numbers Pro](http://www.woothemes.com/extension/sequential-order-numbers-pro/)
41
+
42
== Changelog ==
43
44
+ = 1.2.2 =
45
+ * Takes advantage of new action hooks/filters available in WooCommerce 1.5.6
46
+ * Bug fix on installation to stores with more than 10 existing orders
47
+
48
= 1.2.1 =
49
* Minor updates due to WooCommerce 1.5.5 release
50
65
66
= 1.0.0 =
67
* Initial Release
68
+
69
+ == Upgrade Notice ==
70
+
71
+ = 1.2.2 =
72
+ This version requires WooCommerce 1.5.6
73
+
74
+ = 1.2.1 =
75
+ This version requires WooCommerce 1.5.5
woocommerce-sequential-order-numbers.php CHANGED
@@ -5,9 +5,9 @@ Plugin URI: http://www.foxrunsoftware.net/articles/wordpress/woocommerce-sequent
5
Description: Provides sequential order numbers for WooCommerce orders
6
Author: Justin Stern
7
Author URI: http://www.foxrunsoftware.net
8
- Version: 1.2.1
9
10
- Copyright: © 2012 Justin Stern (email : justin@foxrunsoftware.net)
11
License: GNU General Public License v3.0
12
License URI: http://www.gnu.org/licenses/gpl-3.0.html
13
*/
@@ -22,584 +22,72 @@ if ( is_woocommerce_active() ) {
22
if ( ! class_exists( 'WC_Seq_Order_Number' ) ) {
23
24
class WC_Seq_Order_Number {
25
- const VERSION = "1.2.1";
26
const VERSION_OPTION_NAME = "woocommerce_seq_order_number_db_version";
27
28
public function __construct() {
29
30
- // actions/filters
31
- add_action( 'woocommerce_init', array( &$this, 'woocommerce_loaded' ) );
32
add_action( 'wp_insert_post', array( &$this, 'set_sequential_order_number' ), 10, 2 );
33
- add_filter( 'woocommerce_order_number', array( &$this, 'get_order_number' ), 10, 2);
34
- add_filter( 'woocommerce_email_subject_new_order', array( &$this, 'email_subject_new_order' ), 10, 2 );
35
36
- // Installation
37
- if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install();
38
- }
39
-
40
-
41
- /**
42
- * Called after WooCommerce is initialized, so put anything in here that
43
- * needs to be run after WooCommerce has had a chance to initialize.
44
- */
45
- function woocommerce_loaded() {
46
- global $woocommerce;
47
48
- // remove the order tracking shortcode and use our own.
49
- remove_shortcode( 'woocommerce_order_tracking', 'get_woocommerce_order_tracking' );
50
- add_shortcode( 'woocommerce_order_tracking', array( &$this, 'get_woocommerce_order_tracking' ) );
51
52
if ( is_admin() ) {
53
- // Override a bunch of admin functionality to support the sequential order numbers on the backend, unfortunately...
54
- remove_action( 'manage_shop_order_posts_custom_column', 'woocommerce_custom_order_columns', 2 );
55
- add_action( 'manage_shop_order_posts_custom_column', array( &$this, 'woocommerce_custom_order_columns' ), 2 );
56
-
57
- add_filter( 'request', array( &$this, 'woocommerce_custom_shop_order_orderby' ), 20 );
58
-
59
- remove_filter( 'parse_query', 'woocommerce_shop_order_search_custom_fields' );
60
- add_filter( 'parse_query', array( &$this, 'woocommerce_shop_order_search_custom_fields' ) );
61
-
62
- add_action( 'add_meta_boxes', array( &$this, 'woocommerce_meta_boxes' ), 20 );
63
}
64
- }
65
-
66
-
67
- /**
68
- * Order Tracking page shortcode, which we hijack and replace with
69
- * our own order_number-friendly version
70
- */
71
- public function get_woocommerce_order_tracking( $atts ) {
72
- global $woocommerce;
73
- return $woocommerce->shortcode_wrapper( array( &$this, 'woocommerce_order_tracking' ), $atts );
74
- }
75
-
76
-
77
- /**
78
- * Order Tracking page shortcode, largely unchanged from the original
79
- * this one just searches by order_number
80
- *
81
- * Code based on WooCommerce woocommerce_order_tracking()
82
- * @see woocommerce/shortcodes/shortcode-order_tracking.php
83
- */
84
- public function woocommerce_order_tracking( $atts ) {
85
- global $woocommerce;
86
-
87
- $woocommerce->nocache();
88
-
89
- extract(shortcode_atts(array(
90
- ), $atts));
91
-
92
- global $post;
93
94
- if ($_POST) :
95
-
96
- $woocommerce->verify_nonce( 'order_tracking' );
97
-
98
- if (isset($_POST['orderid']) && $_POST['orderid'] > 0) $order_id = (int) $_POST['orderid']; else $order_id = 0;
99
- if (isset($_POST['order_email']) && $_POST['order_email']) $order_email = trim($_POST['order_email']); else $order_email = '';
100
-
101
- // try and find the order by order_number
102
- $order = $this->find_order_by_order_number( $order_id );
103
-
104
- if ($order->id && $order_email) :
105
-
106
- if (strtolower($order->billing_email) == strtolower($order_email)) :
107
-
108
- woocommerce_get_template( 'order/tracking.php', array(
109
- 'order' => $order
110
- ) );
111
-
112
- return;
113
-
114
- endif;
115
-
116
- endif;
117
-
118
- echo '<p>'.sprintf(__('Sorry, we could not find that order id in our database. <a href="%s">Want to retry?</a>', 'woocommerce'), get_permalink($post->ID)).'</p>';
119
-
120
- else :
121
-
122
- woocommerce_get_template( 'order/form-tracking.php' );
123
-
124
- endif;
125
-
126
- }
127
-
128
-
129
- /**
130
- * Largely unchanged from the WooCommerce original, just one point
131
- * change identified below
132
- *
133
- * Code based on WooCommerce 1.5.5 woocommerce_custom_order_columns()
134
- * @see woocommerce/admin/post-types/shop_order.php
135
- */
136
- function woocommerce_custom_order_columns($column) {
137
-
138
- global $post, $woocommerce;
139
- $order = new WC_Order( $post->ID );
140
-
141
- switch ($column) {
142
- case "order_status" :
143
-
144
- printf( '<mark class="%s">%s</mark>', sanitize_title($order->status), __($order->status, 'woocommerce') );
145
-
146
- break;
147
- case "order_title" :
148
-
149
- if ($order->user_id) $user_info = get_userdata($order->user_id);
150
-
151
- if (isset($user_info) && $user_info) :
152
-
153
- $user = '<a href="user-edit.php?user_id=' . esc_attr( $user_info->ID ) . '">';
154
-
155
- if ($user_info->first_name || $user_info->last_name) $user .= $user_info->first_name.' '.$user_info->last_name;
156
- else $user .= esc_html( $user_info->display_name );
157
-
158
- $user .= '</a>';
159
-
160
- else :
161
- $user = __('Guest', 'woocommerce');
162
- endif;
163
-
164
- // JES - changed $post->ID to $order->get_order_number()
165
- echo '<a href="'.admin_url('post.php?post='.$post->ID.'&action=edit').'"><strong>'.sprintf( __('Order %s', 'woocommerce'), $order->get_order_number() ).'</strong></a> ' . __('made by', 'woocommerce') . ' ' . $user;
166
-
167
- if ($order->billing_email) :
168
- echo '<small class="meta">'.__('Email:', 'woocommerce') . ' ' . '<a href="' . esc_url( 'mailto:'.$order->billing_email ).'">'.esc_html( $order->billing_email ).'</a></small>';
169
- endif;
170
- if ($order->billing_phone) :
171
- echo '<small class="meta">'.__('Tel:', 'woocommerce') . ' ' . esc_html( $order->billing_phone ) . '</small>';
172
- endif;
173
-
174
- break;
175
- case "billing_address" :
176
- if ($order->get_formatted_billing_address()) :
177
-
178
- echo '<a target="_blank" href="' . esc_url( 'http://maps.google.com/maps?&q='.urlencode( $order->get_billing_address() ).'&z=16' ) . '">'. preg_replace('#<br\s*/?>#i', ', ', $order->get_formatted_billing_address()) .'</a>';
179
- else :
180
- echo '&ndash;';
181
- endif;
182
-
183
- if ($order->payment_method_title) :
184
- echo '<small class="meta">' . __('Via', 'woocommerce') . ' ' . esc_html( $order->payment_method_title ) . '</small>';
185
- endif;
186
-
187
- break;
188
- case "shipping_address" :
189
- if ($order->get_formatted_shipping_address()) :
190
-
191
- echo '<a target="_blank" href="' . esc_url( 'http://maps.google.com/maps?&q='.urlencode( $order->get_shipping_address() ).'&z=16' ) .'">'. preg_replace('#<br\s*/?>#i', ', ', $order->get_formatted_shipping_address()) .'</a>';
192
- else :
193
- echo '&ndash;';
194
- endif;
195
-
196
- if ($order->shipping_method_title) :
197
- echo '<small class="meta">' . __('Via', 'woocommerce') . ' ' . esc_html( $order->shipping_method_title ) . '</small>';
198
- endif;
199
- break;
200
- case "total_cost" :
201
- echo $order->get_formatted_order_total();
202
- break;
203
- case "order_date" :
204
-
205
- if ( '0000-00-00 00:00:00' == $post->post_date ) :
206
- $t_time = $h_time = __( 'Unpublished', 'woocommerce' );
207
- else :
208
- $t_time = get_the_time( __( 'Y/m/d g:i:s A', 'woocommerce' ), $post );
209
-
210
- $gmt_time = strtotime($post->post_date_gmt);
211
- $time_diff = current_time('timestamp', 1) - $gmt_time;
212
-
213
- if ( $time_diff > 0 && $time_diff < 24*60*60 )
214
- $h_time = sprintf( __( '%s ago', 'woocommerce' ), human_time_diff( $gmt_time, current_time('timestamp', 1) ) );
215
- else
216
- $h_time = get_the_time( __( 'Y/m/d', 'woocommerce' ), $post );
217
- endif;
218
-
219
- echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post ) . '</abbr>';
220
-
221
- break;
222
- case "order_actions" :
223
-
224
- ?><p>
225
- <?php if (in_array($order->status, array('pending', 'on-hold'))) : ?><a class="button" href="<?php echo wp_nonce_url( admin_url('admin-ajax.php?action=woocommerce-mark-order-processing&order_id=' . $post->ID), 'woocommerce-mark-order-processing' ); ?>"><?php _e('Processing', 'woocommerce'); ?></a><?php endif; ?>
226
- <?php if (in_array($order->status, array('pending', 'on-hold', 'processing'))) : ?><a class="button" href="<?php echo wp_nonce_url( admin_url('admin-ajax.php?action=woocommerce-mark-order-complete&order_id=' . $post->ID), 'woocommerce-mark-order-complete' ); ?>"><?php _e('Complete', 'woocommerce'); ?></a><?php endif; ?>
227
- <a class="button" href="<?php echo admin_url('post.php?post='.$post->ID.'&action=edit'); ?>"><?php _e('View', 'woocommerce'); ?></a>
228
- </p><?php
229
-
230
- break;
231
- case "note" :
232
-
233
- if ($order->customer_note)
234
- echo '<img src="'.$woocommerce->plugin_url().'/assets/images/note.png" alt="yes" class="tips" data-tip="'. __('Yes', 'woocommerce') .'" />';
235
- else
236
- echo '<img src="'.$woocommerce->plugin_url().'/assets/images/note-off.png" alt="no" class="tips" data-tip="'. __('No', 'woocommerce') .'" />';
237
-
238
- break;
239
- case "order_comments" :
240
-
241
- echo '<div class="post-com-count-wrapper">
242
- <a href="'. admin_url('post.php?post='.$post->ID.'&action=edit') .'" class="post-com-count"><span class="comment-count">'. $post->comment_count .'</span></a>
243
- </div>';
244
- break;
245
- }
246
- }
247
-
248
-
249
- /**
250
- * Orderby ID operates on the meta _order_number
251
- */
252
- function woocommerce_custom_shop_order_orderby( $vars ) {
253
- global $typenow, $wp_query;
254
- if ( $typenow != 'shop_order' ) return $vars;
255
-
256
- // Sorting
257
- if ( isset( $vars['orderby'] ) ) :
258
- if ( 'ID' == $vars['orderby'] ) :
259
- $vars = array_merge( $vars, array(
260
- 'meta_key' => '_order_number',
261
- 'orderby' => 'meta_value_num'
262
- ) );
263
- endif;
264
-
265
- endif;
266
-
267
- return $vars;
268
}
269
270
271
/**
272
- * Largely unchanged from original, just one point change noted below
273
*
274
- * Code based on WooCommerce 1.5.5 woocommerce_shop_order_search_custom_fields()
275
- * @see woocommerce/admin/post-types/shop_order.php
276
- */
277
- function woocommerce_shop_order_search_custom_fields( $wp ) {
278
- global $pagenow, $wpdb;
279
-
280
- if( 'edit.php' != $pagenow ) return $wp;
281
- if( !isset( $wp->query_vars['s'] ) || !$wp->query_vars['s'] ) return $wp;
282
- if ($wp->query_vars['post_type']!='shop_order') return $wp;
283
-
284
- $search_fields = array(
285
- '_order_key',
286
- '_billing_first_name',
287
- '_billing_last_name',
288
- '_billing_company',
289
- '_billing_address_1',
290
- '_billing_address_2',
291
- '_billing_city',
292
- '_billing_postcode',
293
- '_billing_country',
294
- '_billing_state',
295
- '_billing_email',
296
- '_order_items',
297
- '_billing_phone',
298
- '_order_number' // JES - added this
299
- );
300
-
301
- // Query matching custom fields - this seems faster than meta_query
302
- $post_ids = $wpdb->get_col($wpdb->prepare('SELECT post_id FROM '.$wpdb->postmeta.' WHERE meta_key IN ('.'"'.implode('","', $search_fields).'"'.') AND meta_value LIKE "%%%s%%"', esc_attr($_GET['s']) ));
303
-
304
- // Query matching excerpts and titles
305
- $post_ids = array_merge($post_ids, $wpdb->get_col($wpdb->prepare('
306
- SELECT '.$wpdb->posts.'.ID
307
- FROM '.$wpdb->posts.'
308
- LEFT JOIN '.$wpdb->postmeta.' ON '.$wpdb->posts.'.ID = '.$wpdb->postmeta.'.post_id
309
- LEFT JOIN '.$wpdb->users.' ON '.$wpdb->postmeta.'.meta_value = '.$wpdb->users.'.ID
310
- WHERE
311
- post_excerpt LIKE "%%%1$s%%" OR
312
- post_title LIKE "%%%1$s%%" OR
313
- (
314
- meta_key = "_customer_user" AND
315
- (
316
- user_login LIKE "%%%1$s%%" OR
317
- user_nicename LIKE "%%%1$s%%" OR
318
- user_email LIKE "%%%1$s%%" OR
319
- display_name LIKE "%%%1$s%%"
320
- )
321
- )
322
- ',
323
- esc_attr($_GET['s'])
324
- )));
325
-
326
- // Add ID
327
- $search_order_id = str_replace('Order #', '', $_GET['s']);
328
- if (is_numeric($search_order_id)) $post_ids[] = $search_order_id;
329
-
330
- // Add blank ID so not all results are returned if the search finds nothing
331
- $post_ids[] = 0;
332
-
333
- // Remove s - we don't want to search order name
334
- unset( $wp->query_vars['s'] );
335
-
336
- // so we know we're doing this
337
- $wp->query_vars['shop_order_search'] = true;
338
-
339
- // Search by found posts
340
- $wp->query_vars['post__in'] = $post_ids;
341
- }
342
-
343
-
344
- /**
345
- * Remove the WooCommerce order data meta box and add our own
346
- */
347
- function woocommerce_meta_boxes() {
348
- remove_meta_box( 'woocommerce-order-data', 'shop_order', 'normal' );
349
- add_meta_box( 'woocommerce-order-data', __( 'Order Data', 'woocommerce' ), array( &$this,'woocommerce_order_data_meta_box' ), 'shop_order', 'normal', 'high' );
350
- }
351
-
352
-
353
- /**
354
- * Largely unchanged from the WooCommerce original, just one point
355
- * change identified below
356
*
357
- * Code based on WooCommerce 1.5.5 woocommerce_order_data_meta_box()
358
- * @see woocommerce/admin/post-types/writepanels/writepanel-order_data.php
359
*/
360
- function woocommerce_order_data_meta_box($post) {
361
-
362
- global $post, $wpdb, $thepostid, $order_status, $woocommerce;
363
364
- $thepostid = $post->ID;
365
-
366
- $order = new WC_Order( $thepostid );
367
-
368
- wp_nonce_field( 'woocommerce_save_data', 'woocommerce_meta_nonce' );
369
370
- // Custom user
371
- $customer_user = (int) get_post_meta($post->ID, '_customer_user', true);
372
373
- // Order status
374
- $order_status = wp_get_post_terms($post->ID, 'shop_order_status');
375
- if ($order_status) :
376
- $order_status = current($order_status);
377
- $order_status = $order_status->slug;
378
- else :
379
- $order_status = 'pending';
380
- endif;
381
382
- if (!isset($post->post_title) || empty($post->post_title)) :
383
- $order_title = 'Order';
384
- else :
385
- $order_title = $post->post_title;
386
- endif;
387
- ?>
388
- <style type="text/css">
389
- #titlediv, #major-publishing-actions, #minor-publishing-actions, #visibility, #submitdiv { display:none }
390
- </style>
391
- <div class="panel-wrap woocommerce">
392
- <input name="post_title" type="hidden" value="<?php echo esc_attr( $order_title ); ?>" />
393
- <input name="post_status" type="hidden" value="publish" />
394
- <div id="order_data" class="panel">
395
-
396
- <div class="order_data_left">
397
-
398
- <h2><?php _e('Order Details', 'woocommerce'); ?> &mdash; <?php echo $order->get_order_number(); /* JES: changed $thepostid to $order->get_order_number() */ ?></h2>
399
-
400
- <p class="form-field"><label for="order_status"><?php _e('Order status:', 'woocommerce') ?></label>
401
- <select id="order_status" name="order_status" class="chosen_select">
402
- <?php
403
- $statuses = (array) get_terms('shop_order_status', array('hide_empty' => 0, 'orderby' => 'id'));
404
- foreach ($statuses as $status) :
405
- echo '<option value="'.$status->slug.'" ';
406
- if ($status->slug==$order_status) echo 'selected="selected"';
407
- echo '>'.__($status->name, 'woocommerce').'</option>';
408
- endforeach;
409
- ?>
410
- </select></p>
411
-
412
- <p class="form-field last"><label for="order_date"><?php _e('Order Date:', 'woocommerce') ?></label>
413
- <input type="text" class="date-picker-field" name="order_date" id="order_date" maxlength="10" value="<?php echo date('Y-m-d', strtotime( $post->post_date ) ); ?>" /> @ <input type="text" class="hour" placeholder="<?php _e('h', 'woocommerce') ?>" name="order_date_hour" id="order_date_hour" maxlength="2" size="2" value="<?php echo date('H', strtotime( $post->post_date ) ); ?>" />:<input type="text" class="minute" placeholder="<?php _e('m', 'woocommerce') ?>" name="order_date_minute" id="order_date_minute" maxlength="2" size="2" value="<?php echo date('i', strtotime( $post->post_date ) ); ?>" />
414
- </p>
415
416
- <p class="form-field form-field-wide"><label for="customer_user"><?php _e('Customer:', 'woocommerce') ?></label>
417
- <select id="customer_user" name="customer_user" class="chosen_select">
418
- <option value=""><?php _e('Guest', 'woocommerce') ?></option>
419
- <?php
420
- $users = new WP_User_Query( array( 'orderby' => 'display_name' ) );
421
- $users = $users->get_results();
422
- if ($users) foreach ( $users as $user ) :
423
- echo '<option value="'.$user->ID.'" '; selected($customer_user, $user->ID); echo '>' . $user->display_name . ' ('.$user->user_email.')</option>';
424
- endforeach;
425
- ?>
426
- </select></p>
427
-
428
- <p class="form-field form-field-wide"><label for="excerpt"><?php _e('Customer Note:', 'woocommerce') ?></label>
429
- <textarea rows="1" cols="40" name="excerpt" tabindex="6" id="excerpt" placeholder="<?php _e('Customer\'s notes about the order', 'woocommerce'); ?>"><?php echo $post->post_excerpt; ?></textarea></p>
430
-
431
- </div>
432
- <div class="order_data_right">
433
- <div class="order_data">
434
- <h2><?php _e('Billing Details', 'woocommerce'); ?> <a class="edit_address" href="#">(<?php _e('Edit', 'woocommerce') ;?>)</a></h2>
435
- <?php
436
- $billing_data = apply_filters('woocommerce_admin_billing_fields', array(
437
- 'first_name' => array(
438
- 'label' => __('First Name', 'woocommerce'),
439
- 'show' => false
440
- ),
441
- 'last_name' => array(
442
- 'label' => __('Last Name', 'woocommerce'),
443
- 'show' => false
444
- ),
445
- 'company' => array(
446
- 'label' => __('Company', 'woocommerce'),
447
- 'show' => false
448
- ),
449
- 'address_1' => array(
450
- 'label' => __('Address 1', 'woocommerce'),
451
- 'show' => false
452
- ),
453
- 'address_2' => array(
454
- 'label' => __('Address 2', 'woocommerce'),
455
- 'show' => false
456
- ),
457
- 'city' => array(
458
- 'label' => __('City', 'woocommerce'),
459
- 'show' => false
460
- ),
461
- 'postcode' => array(
462
- 'label' => __('Postcode', 'woocommerce'),
463
- 'show' => false
464
- ),
465
- 'country' => array(
466
- 'label' => __('Country', 'woocommerce'),
467
- 'show' => false,
468
- 'type' => 'select',
469
- 'options' => $woocommerce->countries->get_allowed_countries()
470
- ),
471
- 'state' => array(
472
- 'label' => __('State/County', 'woocommerce'),
473
- 'show' => false
474
- ),
475
- 'email' => array(
476
- 'label' => __('Email', 'woocommerce'),
477
- ),
478
- 'phone' => array(
479
- 'label' => __('Phone', 'woocommerce'),
480
- ),
481
- ));
482
-
483
- // Display values
484
- echo '<div class="address">';
485
-
486
- if ($order->get_formatted_billing_address()) echo '<p><strong>'.__('Address', 'woocommerce').':</strong><br/> ' .$order->get_formatted_billing_address().'</p>'; else echo '<p class="none_set"><strong>'.__('Address', 'woocommerce').':</strong> ' . __('No billing address set.', 'woocommerce') . '</p>';
487
-
488
- foreach ( $billing_data as $key => $field ) : if (isset($field['show']) && !$field['show']) continue;
489
- $field_name = 'billing_'.$key;
490
- if ( $order->$field_name ) echo '<p><strong>'.$field['label'].':</strong> '.$order->$field_name.'</p>';
491
- endforeach;
492
-
493
- echo '</div>';
494
-
495
- // Display form
496
- echo '<div class="edit_address"><p><button class="button load_customer_billing">'.__('Load customer billing address', 'woocommerce').'</button></p>';
497
-
498
- foreach ( $billing_data as $key => $field ) :
499
- if (!isset($field['type'])) $field['type'] = 'text';
500
- switch ($field['type']) {
501
- case "select" :
502
- woocommerce_wp_select( array( 'id' => '_billing_' . $key, 'label' => $field['label'], 'options' => $field['options'] ) );
503
- break;
504
- default :
505
- woocommerce_wp_text_input( array( 'id' => '_billing_' . $key, 'label' => $field['label'] ) );
506
- break;
507
- }
508
- endforeach;
509
-
510
- echo '</div>';
511
- ?>
512
- </div>
513
- <div class="order_data order_data_alt">
514
-
515
- <h2><?php _e('Shipping Details', 'woocommerce'); ?> <a class="edit_address" href="#">(<?php _e('Edit', 'woocommerce') ;?>)</a></h2>
516
- <?php
517
- $shipping_data = apply_filters('woocommerce_admin_shipping_fields', array(
518
- 'first_name' => array(
519
- 'label' => __('First Name', 'woocommerce'),
520
- 'show' => false
521
- ),
522
- 'last_name' => array(
523
- 'label' => __('Last Name', 'woocommerce'),
524
- 'show' => false
525
- ),
526
- 'company' => array(
527
- 'label' => __('Company', 'woocommerce'),
528
- 'show' => false
529
- ),
530
- 'address_1' => array(
531
- 'label' => __('Address 1', 'woocommerce'),
532
- 'show' => false
533
- ),
534
- 'address_2' => array(
535
- 'label' => __('Address 2', 'woocommerce'),
536
- 'show' => false
537
- ),
538
- 'city' => array(
539
- 'label' => __('City', 'woocommerce'),
540
- 'show' => false
541
- ),
542
- 'postcode' => array(
543
- 'label' => __('Postcode', 'woocommerce'),
544
- 'show' => false
545
- ),
546
- 'country' => array(
547
- 'label' => __('Country', 'woocommerce'),
548
- 'show' => false,
549
- 'type' => 'select',
550
- 'options' => $woocommerce->countries->get_allowed_countries()
551
- ),
552
- 'state' => array(
553
- 'label' => __('State/County', 'woocommerce'),
554
- 'show' => false
555
- ),
556
- ));
557
-
558
- // Display values
559
- echo '<div class="address">';
560
-
561
- if ($order->get_formatted_shipping_address()) echo '<p><strong>'.__('Address', 'woocommerce').':</strong><br/> ' .$order->get_formatted_shipping_address().'</p>'; else echo '<p class="none_set"><strong>'.__('Address', 'woocommerce').':</strong> ' . __('No shipping address set.', 'woocommerce') . '</p>';
562
-
563
- if ( $shipping_data ) foreach ( $shipping_data as $key => $field ) : if (isset($field['show']) && !$field['show']) continue;
564
- $field_name = 'shipping_'.$key;
565
- if ( $order->$field_name ) echo '<p><strong>'.$field['label'].':</strong> '.$order->$field_name.'</p>';
566
- endforeach;
567
-
568
- echo '</div>';
569
-
570
- // Display form
571
- echo '<div class="edit_address"><p><button class="button load_customer_shipping">'.__('Load customer shipping address', 'woocommerce').'</button></p>';
572
-
573
- if ( $shipping_data ) foreach ( $shipping_data as $key => $field ) :
574
- if (!isset($field['type'])) $field['type'] = 'text';
575
- switch ($field['type']) {
576
- case "select" :
577
- woocommerce_wp_select( array( 'id' => '_shipping_' . $key, 'label' => $field['label'], 'options' => $field['options'] ) );
578
- break;
579
- default :
580
- woocommerce_wp_text_input( array( 'id' => '_shipping_' . $key, 'label' => $field['label'] ) );
581
- break;
582
- }
583
- endforeach;
584
-
585
- echo '</div>';
586
-
587
- do_action('woocommerce_admin_order_data_after_shipping_address');
588
- ?>
589
- </div>
590
- </div>
591
- <div class="clear"></div>
592
-
593
- </div>
594
- </div>
595
- <?php
596
}
597
598
599
/**
600
* Set the _order_number field for the newly created order
601
*/
602
- function set_sequential_order_number( $post_id, $post ) {
603
global $wpdb;
604
605
if ( $post->post_type == 'shop_order' ) {
@@ -618,9 +106,15 @@ if ( is_woocommerce_active() ) {
618
619
620
/**
621
- * Filter to return our _order_number field rather than the post ID
622
*/
623
- function get_order_number( $order_number, $order ) {
624
if ( isset( $order->order_custom_fields['_order_number'] ) ) {
625
return '#' . $order->order_custom_fields['_order_number'][0];
626
}
@@ -628,53 +122,48 @@ if ( is_woocommerce_active() ) {
628
}
629
630
631
/**
632
- * Fix the admin new order email
633
*/
634
- function email_subject_new_order( $subject, $order ) {
635
- $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
636
637
- return sprintf( __( '[%s] New Customer Order (%s)', 'woocommerce' ), $blogname, $order->get_order_number() );
638
}
639
640
641
- /** Helper methods ******************************************************/
642
-
643
-
644
/**
645
- * Search for an order with order_number $order_number
646
*
647
- * @param string $order_number order number to search for
648
*
649
- * @return WC_Order object with $order_number, or null if none is found
650
*/
651
- private function find_order_by_order_number( $order_number ) {
652
- $order = null;
653
-
654
- // search for the order by custom order number
655
- $query_args = array(
656
- 'numberposts' => 1,
657
- 'meta_key' => '_order_number',
658
- 'meta_value' => $order_number,
659
- 'post_type' => 'shop_order',
660
- 'post_status' => 'publish',
661
- 'fields' => 'ids'
662
- );
663
-
664
- list( $order_id ) = get_posts( $query_args );
665
666
- if ( $order_id !== null ) $order = new WC_Order( $order_id );
667
668
- // if we didn't find the order, then it may be from an order that pre-existed the installation of the sequential order number plugin
669
- if ( ! $order ) {
670
- $order = new WC_Order( $order_number );
671
- if ( isset( $order->order_custom_fields['_order_number'][0] ) ) {
672
- // _order_number was set, so this is not an old order, it's a new one that just happened to have post_id that matched the searched-for order_number
673
- $order = null;
674
- }
675
- }
676
-
677
- return $order;
678
}
679
680
@@ -689,7 +178,7 @@ if ( is_woocommerce_active() ) {
689
690
if ( ! $installed_version ) {
691
// initial install, set the order number for all existing orders to the post id
692
- $orders = get_posts( array( 'numberposts' => '', 'post_type' => 'shop_order' ) );
693
if ( is_array( $orders ) ) {
694
foreach( $orders as $order ) {
695
if ( get_post_meta( $order->ID, '_order_number', true ) == '' ) {
@@ -707,6 +196,7 @@ if ( is_woocommerce_active() ) {
707
}
708
}
709
710
/**
711
* Run when plugin version number changes
712
*/
5
Description: Provides sequential order numbers for WooCommerce orders
6
Author: Justin Stern
7
Author URI: http://www.foxrunsoftware.net
8
+ Version: 1.2.2
9
10
+ Copyright: 2012 Justin Stern (email : justin@foxrunsoftware.net)
11
License: GNU General Public License v3.0
12
License URI: http://www.gnu.org/licenses/gpl-3.0.html
13
*/
22
if ( ! class_exists( 'WC_Seq_Order_Number' ) ) {
23
24
class WC_Seq_Order_Number {
25
+ const VERSION = "1.2.2";
26
const VERSION_OPTION_NAME = "woocommerce_seq_order_number_db_version";
27
28
public function __construct() {
29
30
+ // set the custom order number on the new order
31
add_action( 'wp_insert_post', array( &$this, 'set_sequential_order_number' ), 10, 2 );
32
33
+ // return our custom order number for display
34
+ add_filter( 'woocommerce_order_number', array( &$this, 'get_order_number' ), 10, 2);
35
36
+ // order tracking page search by order number
37
+ add_filter( 'woocommerce_shortcode_order_tracking_order_id', array( &$this, 'find_order_by_order_number' ) );
38
39
if ( is_admin() ) {
40
+ add_filter( 'request', array( &$this, 'woocommerce_custom_shop_order_orderby' ), 20 );
41
+ add_filter( 'woocommerce_shop_order_search_fields', array( &$this, 'woocommerce_shop_order_search_fields' ) );
42
}
43
44
+ // Installation
45
+ if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install();
46
}
47
48
49
/**
50
+ * Search for an order with order_number $order_number
51
*
52
+ * @param string $order_number order number to search for
53
*
54
+ * @return int post_id for the order identified by $order_number, or 0
55
*/
56
+ public function find_order_by_order_number( $order_number ) {
57
58
+ // search for the order by custom order number
59
+ $query_args = array(
60
+ 'numberposts' => 1,
61
+ 'meta_key' => '_order_number',
62
+ 'meta_value' => $order_number,
63
+ 'post_type' => 'shop_order',
64
+ 'post_status' => 'publish',
65
+ 'fields' => 'ids'
66
+ );
67
68
+ list( $order_id ) = get_posts( $query_args );
69
70
+ // order was found
71
+ if ( $order_id !== null ) return $order_id;
72
73
+ // if we didn't find the order, then it may be that this plugin was disabled and an order was placed in the interim
74
+ $order = new WC_Order( $order_number );
75
+ if ( isset( $order->order_custom_fields['_order_number'][0] ) ) {
76
+ // _order_number was set, so this is not an old order, it's a new one that just happened to have post_id that matched the searched-for order_number
77
+ return 0;
78
+ }
79
80
+ return $order->id;
81
}
82
83
84
/**
85
* Set the _order_number field for the newly created order
86
+ *
87
+ * @param int $post_id post identifier
88
+ * @param object $post post object
89
*/
90
+ public function set_sequential_order_number( $post_id, $post ) {
91
global $wpdb;
92
93
if ( $post->post_type == 'shop_order' ) {
106
107
108
/**
109
+ * Filter to return our _order_number field rather than the post ID,
110
+ * for display.
111
+ *
112
+ * @param string $order_number the order id with a leading hash
113
+ * @param WC_Order $order the order object
114
+ *
115
+ * @return string custom order number, with leading hash
116
*/
117
+ public function get_order_number( $order_number, $order ) {
118
if ( isset( $order->order_custom_fields['_order_number'] ) ) {
119
return '#' . $order->order_custom_fields['_order_number'][0];
120
}
122
}
123
124
125
+ /** Admin filters ******************************************************/
126
+
127
+
128
/**
129
+ * Admin order table orderby ID operates on our meta _order_number
130
+ *
131
+ * @param array $vars associative array of orderby parameteres
132
+ *
133
+ * @return array associative array of orderby parameteres
134
*/
135
+ public function woocommerce_custom_shop_order_orderby( $vars ) {
136
+ global $typenow, $wp_query;
137
+ if ( $typenow != 'shop_order' ) return $vars;
138
+
139
+ // Sorting
140
+ if ( isset( $vars['orderby'] ) ) :
141
+ if ( 'ID' == $vars['orderby'] ) :
142
+ $vars = array_merge( $vars, array(
143
+ 'meta_key' => '_order_number',
144
+ 'orderby' => 'meta_value_num'
145
+ ) );
146
+ endif;
147
+
148
+ endif;
149
150
+ return $vars;
151
}
152
153
154
/**
155
+ * Add our custom _order_number to the set of search fields so that
156
+ * the admin search functionality is maintained
157
*
158
+ * @param array $search_fields array of post meta fields to search by
159
*
160
+ * @return array of post meta fields to search by
161
*/
162
+ public function woocommerce_shop_order_search_fields( $search_fields ) {
163
164
+ array_push( $search_fields, '_order_number' );
165
166
+ return $search_fields;
167
}
168
169
178
179
if ( ! $installed_version ) {
180
// initial install, set the order number for all existing orders to the post id
181
+ $orders = get_posts( array( 'numberposts' => '', 'post_type' => 'shop_order', 'nopaging' => true ) );
182
if ( is_array( $orders ) ) {
183
foreach( $orders as $order ) {
184
if ( get_post_meta( $order->ID, '_order_number', true ) == '' ) {
196
}
197
}
198
199
+
200
/**
201
* Run when plugin version number changes
202
*/