WooCommerce Sequential Order Numbers - Version 1.3.1

Version Description

  • 2014.01.22 =
  • Misc - WooCommerce 2.1 compatibility
Download this release

Release Info

Developer SkyVerge
Plugin Icon WooCommerce Sequential Order Numbers
Version 1.3.1
Comparing to
See all releases

Code changes from version 1.3 to 1.3.1

readme.txt CHANGED
@@ -1,9 +1,7 @@
1
  === WooCommerce Sequential Order Numbers ===
2
  Contributors: SkyVerge
3
  Tags: woocommerce, order number
4
- Requires at least: 3.3
5
- Tested up to: 3.5.1
6
- Stable tag: 1.3
7
 
8
  This plugin extends the WooCommerce e-commerce plugin by setting sequential order numbers for new orders.
9
 
@@ -41,6 +39,9 @@ This free version does not have that functionality, but now you can with the pre
41
 
42
  == Changelog ==
43
 
 
 
 
44
  = 1.3 - 2013.04.26 =
45
  * Feature - Improved WooCommerce Subscriptions compatibility
46
  * Feature - Improved WooCommerce Pre-Orders compatibility
1
  === WooCommerce Sequential Order Numbers ===
2
  Contributors: SkyVerge
3
  Tags: woocommerce, order number
4
+ Stable tag: 1.3.1
 
 
5
 
6
  This plugin extends the WooCommerce e-commerce plugin by setting sequential order numbers for new orders.
7
 
39
 
40
  == Changelog ==
41
 
42
+ = 1.3.1 - 2014.01.22 =
43
+ * Misc - WooCommerce 2.1 compatibility
44
+
45
  = 1.3 - 2013.04.26 =
46
  * Feature - Improved WooCommerce Subscriptions compatibility
47
  * Feature - Improved WooCommerce Pre-Orders compatibility
woocommerce-sequential-order-numbers.php CHANGED
@@ -5,7 +5,7 @@
5
  * Description: Provides sequential order numbers for WooCommerce orders
6
  * Author: SkyVerge
7
  * Author URI: http://www.skyverge.com
8
- * Version: 1.3
9
  *
10
  * Copyright: (c) 2012-2013 SkyVerge, Inc. (info@skyverge.com)
11
  *
@@ -22,8 +22,9 @@
22
  if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
23
 
24
  // Check if WooCommerce is active
25
- if ( ! WC_Seq_Order_Number::is_woocommerce_active() )
26
  return;
 
27
 
28
  /**
29
  * The WC_Seq_Order_Number global object
@@ -35,7 +36,7 @@ $GLOBALS['wc_seq_order_number'] = new WC_Seq_Order_Number();
35
  class WC_Seq_Order_Number {
36
 
37
  /** version number */
38
- const VERSION = "1.3";
39
 
40
  /** version option name */
41
  const VERSION_OPTION_NAME = "woocommerce_seq_order_number_db_version";
@@ -67,7 +68,9 @@ class WC_Seq_Order_Number {
67
  }
68
 
69
  // Installation
70
- if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install();
 
 
71
  }
72
 
73
 
@@ -82,22 +85,24 @@ class WC_Seq_Order_Number {
82
 
83
  // search for the order by custom order number
84
  $query_args = array(
85
- 'numberposts' => 1,
86
- 'meta_key' => '_order_number',
87
- 'meta_value' => $order_number,
88
- 'post_type' => 'shop_order',
89
- 'post_status' => 'publish',
90
- 'fields' => 'ids',
91
- );
92
 
93
  list( $order_id ) = get_posts( $query_args );
94
 
95
  // order was found
96
- if ( $order_id !== null ) return $order_id;
 
 
97
 
98
  // if we didn't find the order, then it may be that this plugin was disabled and an order was placed in the interim
99
  $order = new WC_Order( $order_number );
100
- if ( isset( $order->order_custom_fields['_order_number'][0] ) ) {
101
  // _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
102
  return 0;
103
  }
@@ -147,8 +152,9 @@ class WC_Seq_Order_Number {
147
  * @return string custom order number, with leading hash
148
  */
149
  public function get_order_number( $order_number, $order ) {
150
- if ( isset( $order->order_custom_fields['_order_number'] ) ) {
151
- return '#' . $order->order_custom_fields['_order_number'][0];
 
152
  }
153
 
154
  return $order_number;
@@ -167,7 +173,10 @@ class WC_Seq_Order_Number {
167
  */
168
  public function woocommerce_custom_shop_order_orderby( $vars ) {
169
  global $typenow, $wp_query;
170
- if ( 'shop_order' == $typenow ) return $vars;
 
 
 
171
 
172
  return $this->custom_orderby( $vars );
173
  }
@@ -260,13 +269,47 @@ class WC_Seq_Order_Number {
260
 
261
  $active_plugins = (array) get_option( 'active_plugins', array() );
262
 
263
- if ( is_multisite() )
264
  $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
 
265
 
266
  return in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins );
267
  }
268
 
269
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
270
  /** Lifecycle methods ******************************************************/
271
 
272
 
5
  * Description: Provides sequential order numbers for WooCommerce orders
6
  * Author: SkyVerge
7
  * Author URI: http://www.skyverge.com
8
+ * Version: 1.3.1
9
  *
10
  * Copyright: (c) 2012-2013 SkyVerge, Inc. (info@skyverge.com)
11
  *
22
  if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
23
 
24
  // Check if WooCommerce is active
25
+ if ( ! WC_Seq_Order_Number::is_woocommerce_active() ) {
26
  return;
27
+ }
28
 
29
  /**
30
  * The WC_Seq_Order_Number global object
36
  class WC_Seq_Order_Number {
37
 
38
  /** version number */
39
+ const VERSION = "1.3.1";
40
 
41
  /** version option name */
42
  const VERSION_OPTION_NAME = "woocommerce_seq_order_number_db_version";
68
  }
69
 
70
  // Installation
71
+ if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
72
+ $this->install();
73
+ }
74
  }
75
 
76
 
85
 
86
  // search for the order by custom order number
87
  $query_args = array(
88
+ 'numberposts' => 1,
89
+ 'meta_key' => '_order_number',
90
+ 'meta_value' => $order_number,
91
+ 'post_type' => 'shop_order',
92
+ 'post_status' => 'publish',
93
+ 'fields' => 'ids',
94
+ );
95
 
96
  list( $order_id ) = get_posts( $query_args );
97
 
98
  // order was found
99
+ if ( $order_id !== null ) {
100
+ return $order_id;
101
+ }
102
 
103
  // if we didn't find the order, then it may be that this plugin was disabled and an order was placed in the interim
104
  $order = new WC_Order( $order_number );
105
+ if ( $this->get_order_custom_field( $order, 'order_number' ) ) {
106
  // _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
107
  return 0;
108
  }
152
  * @return string custom order number, with leading hash
153
  */
154
  public function get_order_number( $order_number, $order ) {
155
+
156
+ if ( $this->get_order_custom_field( $order, 'order_number' ) ) {
157
+ return '#' . $this->get_order_custom_field( $order, 'order_number' );
158
  }
159
 
160
  return $order_number;
173
  */
174
  public function woocommerce_custom_shop_order_orderby( $vars ) {
175
  global $typenow, $wp_query;
176
+ if ( 'shop_order' == $typenow ) {
177
+ return $vars;
178
+
179
+ }
180
 
181
  return $this->custom_orderby( $vars );
182
  }
269
 
270
  $active_plugins = (array) get_option( 'active_plugins', array() );
271
 
272
+ if ( is_multisite() ) {
273
  $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
274
+ }
275
 
276
  return in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins );
277
  }
278
 
279
 
280
+ /**
281
+ * Returns an order custom field
282
+ *
283
+ * @since 1.3.1
284
+ * @param WC_Order $order the order object
285
+ * @param string $name the custom field name
286
+ */
287
+ private function get_order_custom_field( $order, $name ) {
288
+
289
+ if ( version_compare( $this->get_wc_version(), '2.0.20', '>' ) ) {
290
+ return isset( $order->$name ) ? $order->$name : '';
291
+ } else {
292
+ return isset( $order->order_custom_fields[ '_' . $name ][0] ) ? $order->order_custom_fields[ '_' . $name ][0] : '';
293
+ }
294
+ }
295
+
296
+
297
+ /**
298
+ * Compatibility function to get the version of the currently installed WooCommerce
299
+ *
300
+ * @since 1.3.1
301
+ * @return string woocommerce version number or null
302
+ */
303
+ private function get_wc_version() {
304
+
305
+ // WOOCOMMERCE_VERSION is now WC_VERSION, though WOOCOMMERCE_VERSION is still available for backwards compatibility, we'll disregard it on 2.1+
306
+ if ( defined( 'WC_VERSION' ) && WC_VERSION ) return WC_VERSION;
307
+ if ( defined( 'WOOCOMMERCE_VERSION' ) && WOOCOMMERCE_VERSION ) return WOOCOMMERCE_VERSION;
308
+
309
+ return null;
310
+ }
311
+
312
+
313
  /** Lifecycle methods ******************************************************/
314
 
315