WooCommerce Sequential Order Numbers - Version 1.1.0

Version Description

Download this release

Release Info

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

Code changes from version 1.0.1 to 1.1.0

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.0.1
7
 
8
  This plugin extends the WooCommerce e-commerce plugin by setting sequential order numbers for new orders.
9
 
@@ -26,6 +26,9 @@ This plugin extends the WooCommerce e-commerce plugin by setting sequential orde
26
 
27
  == Changelog ==
28
 
 
 
 
29
  = 1.0.1 =
30
  * small bug fix
31
 
3
  Tags: woocommerce, order number
4
  Requires at least: 3.3
5
  Tested up to: 3.3
6
+ Stable tag: 1.1.0
7
 
8
  This plugin extends the WooCommerce e-commerce plugin by setting sequential order numbers for new orders.
9
 
26
 
27
  == Changelog ==
28
 
29
+ = 1.0.1 =
30
+ * Search by order number
31
+
32
  = 1.0.1 =
33
  * small bug fix
34
 
woocommerce-sequential-order-numbers.php CHANGED
@@ -5,7 +5,7 @@ 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.0.1
9
 
10
  Copyright: © 2012 Justin Stern (email : justin@foxrunsoftware.net)
11
  License: GNU General Public License v3.0
@@ -22,7 +22,7 @@ if (is_woocommerce_active()) {
22
  if (!class_exists('WC_Seq_Order_Number')) {
23
 
24
  class WC_Seq_Order_Number {
25
- const VERSION = "1.0.1";
26
  const VERSION_OPTION_NAME = "woocommerce_seq_order_number_db_version";
27
 
28
  public function __construct() {
@@ -52,6 +52,9 @@ if (is_woocommerce_active()) {
52
  remove_filter( 'request', 'woocommerce_custom_shop_order_orderby' );
53
  add_filter( 'request', array(&$this, 'woocommerce_custom_shop_order_orderby' ));
54
 
 
 
 
55
  add_action( 'add_meta_boxes', array(&$this, 'woocommerce_meta_boxes'), 20 );
56
  }
57
  }
@@ -202,6 +205,73 @@ if (is_woocommerce_active()) {
202
  }
203
 
204
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
  /**
206
  * Remove the WooCommerce order data meta box and add our own
207
  */
5
  Description: Provides sequential order numbers for WooCommerce orders
6
  Author: Justin Stern
7
  Author URI: http://www.foxrunsoftware.net
8
+ Version: 1.1.0
9
 
10
  Copyright: © 2012 Justin Stern (email : justin@foxrunsoftware.net)
11
  License: GNU General Public License v3.0
22
  if (!class_exists('WC_Seq_Order_Number')) {
23
 
24
  class WC_Seq_Order_Number {
25
+ const VERSION = "1.1.0";
26
  const VERSION_OPTION_NAME = "woocommerce_seq_order_number_db_version";
27
 
28
  public function __construct() {
52
  remove_filter( 'request', 'woocommerce_custom_shop_order_orderby' );
53
  add_filter( 'request', array(&$this, 'woocommerce_custom_shop_order_orderby' ));
54
 
55
+ remove_filter( 'parse_query', 'woocommerce_shop_order_search_custom_fields' );
56
+ add_filter( 'parse_query', array(&$this, 'woocommerce_shop_order_search_custom_fields' ));
57
+
58
  add_action( 'add_meta_boxes', array(&$this, 'woocommerce_meta_boxes'), 20 );
59
  }
60
  }
205
  }
206
 
207
 
208
+ function woocommerce_shop_order_search_custom_fields( $wp ) {
209
+ global $pagenow, $wpdb;
210
+
211
+ if( 'edit.php' != $pagenow ) return $wp;
212
+ if( !isset( $wp->query_vars['s'] ) || !$wp->query_vars['s'] ) return $wp;
213
+ if ($wp->query_vars['post_type']!='shop_order') return $wp;
214
+
215
+ $search_fields = array(
216
+ '_order_key',
217
+ '_billing_first_name',
218
+ '_billing_last_name',
219
+ '_billing_company',
220
+ '_billing_address_1',
221
+ '_billing_address_2',
222
+ '_billing_city',
223
+ '_billing_postcode',
224
+ '_billing_country',
225
+ '_billing_state',
226
+ '_billing_email',
227
+ '_order_items',
228
+ '_billing_phone',
229
+ '_order_number' // JES - added this
230
+ );
231
+
232
+ // Query matching custom fields - this seems faster than meta_query
233
+ $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']) ));
234
+
235
+ // Query matching excerpts and titles
236
+ $post_ids = array_merge($post_ids, $wpdb->get_col($wpdb->prepare('
237
+ SELECT '.$wpdb->posts.'.ID
238
+ FROM '.$wpdb->posts.'
239
+ LEFT JOIN '.$wpdb->postmeta.' ON '.$wpdb->posts.'.ID = '.$wpdb->postmeta.'.post_id
240
+ LEFT JOIN '.$wpdb->users.' ON '.$wpdb->postmeta.'.meta_value = '.$wpdb->users.'.ID
241
+ WHERE
242
+ post_excerpt LIKE "%%%1$s%%" OR
243
+ post_title LIKE "%%%1$s%%" OR
244
+ (
245
+ meta_key = "_customer_user" AND
246
+ (
247
+ user_login LIKE "%%%1$s%%" OR
248
+ user_nicename LIKE "%%%1$s%%" OR
249
+ user_email LIKE "%%%1$s%%" OR
250
+ display_name LIKE "%%%1$s%%"
251
+ )
252
+ )
253
+ ',
254
+ esc_attr($_GET['s'])
255
+ )));
256
+
257
+ // Add ID
258
+ $search_order_id = str_replace('Order #', '', $_GET['s']);
259
+ if (is_numeric($search_order_id)) $post_ids[] = $search_order_id;
260
+
261
+ // Add blank ID so not all results are returned if the search finds nothing
262
+ $post_ids[] = 0;
263
+
264
+ // Remove s - we don't want to search order name
265
+ unset( $wp->query_vars['s'] );
266
+
267
+ // so we know we're doing this
268
+ $wp->query_vars['shop_order_search'] = true;
269
+
270
+ // Search by found posts
271
+ $wp->query_vars['post__in'] = $post_ids;
272
+ }
273
+
274
+
275
  /**
276
  * Remove the WooCommerce order data meta box and add our own
277
  */