WooCommerce Sequential Order Numbers - Version 1.6.0

Version Description

  • 2015.nn.nn =
  • Misc - WooCommerce Subscriptions: Use new filter hook wcs_renewal_order_created instead of deprecated woocommerce_subscriptions_renewal_order_created
  • Misc - WooCommerce 2.5 compatibility
  • Misc - Dropped WooCommerce 2.2 support
Download this release

Release Info

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

Code changes from version 1.5.1 to 1.6.0

i18n/languages/woocommerce-sequential-order-numbers.pot CHANGED
@@ -1,25 +1,26 @@
1
- # Copyright (C) 2015 SkyVerge
2
  # This file is distributed under the GNU General Public License v3.0.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: WooCommerce Sequential Order Numbers 1.5.1\n"
6
  "Report-Msgid-Bugs-To: "
7
  "https://github.com/skyverge/woocommerce-sequential-order-numbers/issues\n"
8
  "POT-Creation-Date: 2014-09-05 22:27:38+00:00\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=utf-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
12
- "PO-Revision-Date: 2015-MO-DA HO:MI+ZONE\n"
13
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
  "Language-Team: LANGUAGE <LL@li.org>\n"
15
 
16
- #: woocommerce-sequential-order-numbers.php:444
 
17
  msgid ""
18
  "Error activating and installing <strong>WooCommerce Sequential Order "
19
  "Numbers</strong>: %s"
20
  msgstr ""
21
 
22
- #: woocommerce-sequential-order-numbers.php:445
23
  msgid "&laquo; Go Back"
24
  msgstr ""
25
 
1
+ # Copyright (C) 2016 SkyVerge
2
  # This file is distributed under the GNU General Public License v3.0.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: WooCommerce Sequential Order Numbers 1.6.0\n"
6
  "Report-Msgid-Bugs-To: "
7
  "https://github.com/skyverge/woocommerce-sequential-order-numbers/issues\n"
8
  "POT-Creation-Date: 2014-09-05 22:27:38+00:00\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=utf-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
12
+ "PO-Revision-Date: 2016-MO-DA HO:MI+ZONE\n"
13
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
  "Language-Team: LANGUAGE <LL@li.org>\n"
15
 
16
+ #: woocommerce-sequential-order-numbers.php:460
17
+ #. Translators: %s - error message(s)
18
  msgid ""
19
  "Error activating and installing <strong>WooCommerce Sequential Order "
20
  "Numbers</strong>: %s"
21
  msgstr ""
22
 
23
+ #: woocommerce-sequential-order-numbers.php:461
24
  msgid "&laquo; Go Back"
25
  msgstr ""
26
 
readme.txt CHANGED
@@ -1,11 +1,11 @@
1
  === WooCommerce Sequential Order Numbers ===
2
  Contributors: SkyVerge, maxrice, tamarazuk, chasewiseman, nekojira
3
  Tags: woocommerce, order number
4
- Requires at least: 3.8
5
- Tested up to: 4.4
6
- Requires WooCommerce at least: 2.2
7
- Tested WooCommerce up to: 2.4.10
8
- Stable tag: 1.5.1
9
 
10
  This plugin extends WooCommerce by setting sequential order numbers for new orders.
11
 
@@ -54,6 +54,11 @@ This free version does not have that functionality, but it's included in the pre
54
 
55
  == Changelog ==
56
 
 
 
 
 
 
57
  = 1.5.1 - 2015.11.26 =
58
  * Fix - Compatibility fix with WooCommerce Subscriptions 2.0
59
 
1
  === WooCommerce Sequential Order Numbers ===
2
  Contributors: SkyVerge, maxrice, tamarazuk, chasewiseman, nekojira
3
  Tags: woocommerce, order number
4
+ Requires at least: 4.0
5
+ Tested up to: 4.4.1
6
+ Requires WooCommerce at least: 2.3
7
+ Tested WooCommerce up to: 2.5
8
+ Stable tag: 1.6.0
9
 
10
  This plugin extends WooCommerce by setting sequential order numbers for new orders.
11
 
54
 
55
  == Changelog ==
56
 
57
+ = 1.6.0 - 2015.nn.nn =
58
+ * Misc - WooCommerce Subscriptions: Use new filter hook wcs_renewal_order_created instead of deprecated woocommerce_subscriptions_renewal_order_created
59
+ * Misc - WooCommerce 2.5 compatibility
60
+ * Misc - Dropped WooCommerce 2.2 support
61
+
62
  = 1.5.1 - 2015.11.26 =
63
  * Fix - Compatibility fix with WooCommerce Subscriptions 2.0
64
 
woocommerce-sequential-order-numbers.php CHANGED
@@ -5,11 +5,11 @@
5
  * Description: Provides sequential order numbers for WooCommerce orders
6
  * Author: SkyVerge
7
  * Author URI: http://www.skyverge.com
8
- * Version: 1.5.1
9
  * Text Domain: woocommerce-sequential-order-numbers
10
  * Domain Path: /i18n/languages/
11
  *
12
- * Copyright: (c) 2012-2013 SkyVerge, Inc. (info@skyverge.com)
13
  *
14
  * License: GNU General Public License v3.0
15
  * License URI: http://www.gnu.org/licenses/gpl-3.0.html
@@ -17,7 +17,7 @@
17
  * @package WC-Sequential-Order-Numbers
18
  * @author SkyVerge
19
  * @category Plugin
20
- * @copyright Copyright (c) 2012-2013, SkyVerge, Inc.
21
  * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
22
  */
23
 
@@ -38,13 +38,13 @@ $GLOBALS['wc_seq_order_number'] = new WC_Seq_Order_Number();
38
  class WC_Seq_Order_Number {
39
 
40
  /** version number */
41
- const VERSION = "1.5.1";
42
 
43
  /** version option name */
44
  const VERSION_OPTION_NAME = "woocommerce_seq_order_number_db_version";
45
 
46
  /** minimum required wc version */
47
- const MINIMUM_WC_VERSION = '2.2';
48
 
49
 
50
  /**
@@ -78,7 +78,7 @@ class WC_Seq_Order_Number {
78
  add_action( 'woocommerce_process_shop_order_meta', array( $this, 'set_sequential_order_number' ), 10, 2 );
79
 
80
  // return our custom order number for display
81
- add_filter( 'woocommerce_order_number', array( $this, 'get_order_number' ), 10, 2);
82
 
83
  // order tracking page search by order number
84
  add_filter( 'woocommerce_shortcode_order_tracking_order_id', array( $this, 'find_order_by_order_number' ) );
@@ -87,9 +87,9 @@ class WC_Seq_Order_Number {
87
  add_filter( 'woocommerce_subscriptions_renewal_order_meta_query', array( $this, 'subscriptions_remove_renewal_order_meta' ), 10, 4 );
88
 
89
  if ( self::is_wc_subscriptions_version_gte_2_0() ) {
90
- add_filter( 'woocommerce_subscriptions_renewal_order_created', array( $this, 'subscriptions_set_sequential_order_number' ), 10, 4 );
91
  } else {
92
- add_action( 'woocommerce_subscriptions_renewal_order_created', array( $this, 'subscriptions_set_sequential_order_number' ), 10, 4 );
93
  }
94
 
95
  if ( is_admin() ) {
@@ -172,12 +172,15 @@ class WC_Seq_Order_Number {
172
  global $wpdb;
173
 
174
  if ( 'shop_order' == $post->post_type && 'auto-draft' != $post->post_status ) {
 
175
  $order_number = get_post_meta( $post_id, '_order_number', true );
 
176
  if ( "" == $order_number ) {
177
 
178
  // attempt the query up to 3 times for a much higher success rate if it fails (due to Deadlock)
179
  $success = false;
180
  for ( $i = 0; $i < 3 && ! $success; $i++ ) {
 
181
  // this seems to me like the safest way to avoid order number clashes
182
  $query = $wpdb->prepare( "
183
  INSERT INTO {$wpdb->postmeta} (post_id, meta_key, meta_value)
@@ -204,7 +207,7 @@ class WC_Seq_Order_Number {
204
  public function get_order_number( $order_number, $order ) {
205
 
206
  if ( $order->order_number ) {
207
- return ( self::is_wc_version_gte_2_3() ? '' : '#' ) . $order->order_number;
208
  }
209
 
210
  return $order_number;
@@ -222,9 +225,9 @@ class WC_Seq_Order_Number {
222
  */
223
  public function woocommerce_custom_shop_order_orderby( $vars ) {
224
  global $typenow, $wp_query;
 
225
  if ( 'shop_order' == $typenow ) {
226
  return $vars;
227
-
228
  }
229
 
230
  return $this->custom_orderby( $vars );
@@ -239,8 +242,10 @@ class WC_Seq_Order_Number {
239
  * @return array associative array of orderby parameteres
240
  */
241
  public function custom_orderby( $args ) {
 
242
  // Sorting
243
  if ( isset( $args['orderby'] ) && 'ID' == $args['orderby'] ) {
 
244
  $args = array_merge( $args, array(
245
  'meta_key' => '_order_number', // sort on numerical portion for better results
246
  'orderby' => 'meta_value_num',
@@ -276,7 +281,6 @@ class WC_Seq_Order_Number {
276
  * @return string|null WC_Subscriptions version number or null if not found
277
  */
278
  protected static function get_wc_subscriptions_version() {
279
-
280
  return class_exists( 'WC_Subscriptions' ) && ! empty( WC_Subscriptions::$version ) ? WC_Subscriptions::$version : null;
281
  }
282
 
@@ -288,7 +292,6 @@ class WC_Seq_Order_Number {
288
  * @return boolean
289
  */
290
  protected static function is_wc_subscriptions_version_gte_2_0() {
291
-
292
  return self::get_wc_subscriptions_version() && version_compare( self::get_wc_subscriptions_version(), '2.0-beta-1', '>=' );
293
  }
294
 
@@ -298,16 +301,15 @@ class WC_Seq_Order_Number {
298
  *
299
  * @since 1.3
300
  * @param WC_Order $renewal_order the new renewal order object
301
- * @param WC_Order $original_order the original order object
302
- * @param int $product_id the product post identifier
303
- * @param string $new_order_role the role the renewal order is taking, one of 'parent' or 'child'
304
- * @return void|WC_Order Renewal order instance for Subscriptions 2.0+
305
  */
306
- public function subscriptions_set_sequential_order_number( $renewal_order, $original_order, $product_id, $new_order_role ) {
307
 
308
  $order_post = get_post( $renewal_order->id );
309
  $this->set_sequential_order_number( $order_post->ID, $order_post );
310
 
 
311
  if ( self::is_wc_subscriptions_version_gte_2_0() ) {
312
  return $renewal_order;
313
  }
@@ -363,19 +365,29 @@ class WC_Seq_Order_Number {
363
  * @return string woocommerce version number or null
364
  */
365
  private static function get_wc_version() {
366
-
367
  return defined( 'WC_VERSION' ) && WC_VERSION ? WC_VERSION : null;
368
  }
369
 
370
 
371
  /**
372
- * Returns true if the installed version of WooCommerce is 2.3 or greater
 
 
 
 
 
 
 
 
 
 
 
373
  *
374
- * @since 1.4.0
375
  * @return boolean true if the installed version of WooCommerce is 2.3 or greater
376
  */
377
- public static function is_wc_version_gte_2_3() {
378
- return self::get_wc_version() && version_compare( self::get_wc_version(), '2.3', '>=' );
379
  }
380
 
381
 
@@ -389,9 +401,12 @@ class WC_Seq_Order_Number {
389
 
390
  // if a plugin defines a minimum WC version, render a notice and skip loading the plugin
391
  if ( defined( 'self::MINIMUM_WC_VERSION' ) && version_compare( self::get_wc_version(), self::MINIMUM_WC_VERSION, '<' ) ) {
 
392
  if ( is_admin() && ! defined( 'DOING_AJAX' ) && ! has_action( 'admin_notices', array( $this, 'render_update_notices' ) ) ) {
 
393
  add_action( 'admin_notices', array( $this, 'render_update_notices' ) );
394
  }
 
395
  return false;
396
  }
397
 
@@ -408,7 +423,7 @@ class WC_Seq_Order_Number {
408
 
409
  echo '<div class="error"><p>The following plugin is inactive because it requires a newer version of WooCommerce:</p><ul>';
410
 
411
- printf( '<li>%s requires WooCommerce %s or newer</li>', 'Sequential Order Numbers', self::MINIMUM_WC_VERSION );
412
 
413
  echo '</ul><p>Please <a href="' . admin_url( 'update-core.php' ) . '">update WooCommerce&nbsp;&raquo;</a></p></div>';
414
 
@@ -441,13 +456,16 @@ class WC_Seq_Order_Number {
441
  require_once ABSPATH . 'wp-admin/includes/plugin.php';
442
  deactivate_plugins( 'woocommerce-sequential-order-numbers/woocommerce-sequential-order-numbers.php' ); // hardcode the plugin path so that we can use symlinks in development
443
 
 
444
  wp_die( sprintf( __( 'Error activating and installing <strong>WooCommerce Sequential Order Numbers</strong>: %s', 'woocommerce-sequential-order-numbers' ), '<ul><li>' . implode( '</li><li>', $order_ids->get_error_messages() ) . '</li></ul>' ) .
445
  '<a href="' . admin_url( 'plugins.php' ) . '">' . __( '&laquo; Go Back', 'woocommerce-sequential-order-numbers' ) . '</a>' );
446
  }
447
 
448
 
449
  if ( is_array( $order_ids ) ) {
 
450
  foreach( $order_ids as $order_id ) {
 
451
  if ( '' == get_post_meta( $order_id, '_order_number', true ) ) {
452
  add_post_meta( $order_id, '_order_number', $order_id );
453
  }
@@ -477,4 +495,6 @@ class WC_Seq_Order_Number {
477
  private function upgrade( $installed_version ) {
478
  // upgrade code goes here
479
  }
 
 
480
  }
5
  * Description: Provides sequential order numbers for WooCommerce orders
6
  * Author: SkyVerge
7
  * Author URI: http://www.skyverge.com
8
+ * Version: 1.6.0
9
  * Text Domain: woocommerce-sequential-order-numbers
10
  * Domain Path: /i18n/languages/
11
  *
12
+ * Copyright: (c) 2012-2016 SkyVerge, Inc. (info@skyverge.com)
13
  *
14
  * License: GNU General Public License v3.0
15
  * License URI: http://www.gnu.org/licenses/gpl-3.0.html
17
  * @package WC-Sequential-Order-Numbers
18
  * @author SkyVerge
19
  * @category Plugin
20
+ * @copyright Copyright (c) 2012-2016, SkyVerge, Inc.
21
  * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
22
  */
23
 
38
  class WC_Seq_Order_Number {
39
 
40
  /** version number */
41
+ const VERSION = "1.6.0";
42
 
43
  /** version option name */
44
  const VERSION_OPTION_NAME = "woocommerce_seq_order_number_db_version";
45
 
46
  /** minimum required wc version */
47
+ const MINIMUM_WC_VERSION = '2.3';
48
 
49
 
50
  /**
78
  add_action( 'woocommerce_process_shop_order_meta', array( $this, 'set_sequential_order_number' ), 10, 2 );
79
 
80
  // return our custom order number for display
81
+ add_filter( 'woocommerce_order_number', array( $this, 'get_order_number' ), 10, 2 );
82
 
83
  // order tracking page search by order number
84
  add_filter( 'woocommerce_shortcode_order_tracking_order_id', array( $this, 'find_order_by_order_number' ) );
87
  add_filter( 'woocommerce_subscriptions_renewal_order_meta_query', array( $this, 'subscriptions_remove_renewal_order_meta' ), 10, 4 );
88
 
89
  if ( self::is_wc_subscriptions_version_gte_2_0() ) {
90
+ add_filter( 'wcs_renewal_order_created', array( $this, 'subscriptions_set_sequential_order_number' ), 10, 2 );
91
  } else {
92
+ add_action( 'woocommerce_subscriptions_renewal_order_created', array( $this, 'subscriptions_set_sequential_order_number' ), 10, 2 );
93
  }
94
 
95
  if ( is_admin() ) {
172
  global $wpdb;
173
 
174
  if ( 'shop_order' == $post->post_type && 'auto-draft' != $post->post_status ) {
175
+
176
  $order_number = get_post_meta( $post_id, '_order_number', true );
177
+
178
  if ( "" == $order_number ) {
179
 
180
  // attempt the query up to 3 times for a much higher success rate if it fails (due to Deadlock)
181
  $success = false;
182
  for ( $i = 0; $i < 3 && ! $success; $i++ ) {
183
+
184
  // this seems to me like the safest way to avoid order number clashes
185
  $query = $wpdb->prepare( "
186
  INSERT INTO {$wpdb->postmeta} (post_id, meta_key, meta_value)
207
  public function get_order_number( $order_number, $order ) {
208
 
209
  if ( $order->order_number ) {
210
+ return $order->order_number;
211
  }
212
 
213
  return $order_number;
225
  */
226
  public function woocommerce_custom_shop_order_orderby( $vars ) {
227
  global $typenow, $wp_query;
228
+
229
  if ( 'shop_order' == $typenow ) {
230
  return $vars;
 
231
  }
232
 
233
  return $this->custom_orderby( $vars );
242
  * @return array associative array of orderby parameteres
243
  */
244
  public function custom_orderby( $args ) {
245
+
246
  // Sorting
247
  if ( isset( $args['orderby'] ) && 'ID' == $args['orderby'] ) {
248
+
249
  $args = array_merge( $args, array(
250
  'meta_key' => '_order_number', // sort on numerical portion for better results
251
  'orderby' => 'meta_value_num',
281
  * @return string|null WC_Subscriptions version number or null if not found
282
  */
283
  protected static function get_wc_subscriptions_version() {
 
284
  return class_exists( 'WC_Subscriptions' ) && ! empty( WC_Subscriptions::$version ) ? WC_Subscriptions::$version : null;
285
  }
286
 
292
  * @return boolean
293
  */
294
  protected static function is_wc_subscriptions_version_gte_2_0() {
 
295
  return self::get_wc_subscriptions_version() && version_compare( self::get_wc_subscriptions_version(), '2.0-beta-1', '>=' );
296
  }
297
 
301
  *
302
  * @since 1.3
303
  * @param WC_Order $renewal_order the new renewal order object
304
+ * @param WC_Order $original_order the original order object (Subscriptions 2.0+: Subscription object)
305
+ * @return void|WC_Order Void for Subscriptions 1.5, renewal order instance for Subscriptions 2.0+
 
 
306
  */
307
+ public function subscriptions_set_sequential_order_number( $renewal_order, $original_order ) {
308
 
309
  $order_post = get_post( $renewal_order->id );
310
  $this->set_sequential_order_number( $order_post->ID, $order_post );
311
 
312
+ // after 2.0 this callback needs to return the renewal order
313
  if ( self::is_wc_subscriptions_version_gte_2_0() ) {
314
  return $renewal_order;
315
  }
365
  * @return string woocommerce version number or null
366
  */
367
  private static function get_wc_version() {
 
368
  return defined( 'WC_VERSION' ) && WC_VERSION ? WC_VERSION : null;
369
  }
370
 
371
 
372
  /**
373
+ * Returns true if the installed version of WooCommerce is 2.4 or greater
374
+ *
375
+ * @since 1.6.0
376
+ * @return boolean true if the installed version of WooCommerce is 2.3 or greater
377
+ */
378
+ public static function is_wc_version_gte_2_4() {
379
+ return self::get_wc_version() && version_compare( self::get_wc_version(), '2.4', '>=' );
380
+ }
381
+
382
+
383
+ /**
384
+ * Returns true if the installed version of WooCommerce is 2.5 or greater
385
  *
386
+ * @since 1.6.0
387
  * @return boolean true if the installed version of WooCommerce is 2.3 or greater
388
  */
389
+ public static function is_wc_version_gte_2_5() {
390
+ return self::get_wc_version() && version_compare( self::get_wc_version(), '2.5', '>=' );
391
  }
392
 
393
 
401
 
402
  // if a plugin defines a minimum WC version, render a notice and skip loading the plugin
403
  if ( defined( 'self::MINIMUM_WC_VERSION' ) && version_compare( self::get_wc_version(), self::MINIMUM_WC_VERSION, '<' ) ) {
404
+
405
  if ( is_admin() && ! defined( 'DOING_AJAX' ) && ! has_action( 'admin_notices', array( $this, 'render_update_notices' ) ) ) {
406
+
407
  add_action( 'admin_notices', array( $this, 'render_update_notices' ) );
408
  }
409
+
410
  return false;
411
  }
412
 
423
 
424
  echo '<div class="error"><p>The following plugin is inactive because it requires a newer version of WooCommerce:</p><ul>';
425
 
426
+ printf( '<li>%1$s requires WooCommerce %2$s or newer</li>', 'Sequential Order Numbers', self::MINIMUM_WC_VERSION );
427
 
428
  echo '</ul><p>Please <a href="' . admin_url( 'update-core.php' ) . '">update WooCommerce&nbsp;&raquo;</a></p></div>';
429
 
456
  require_once ABSPATH . 'wp-admin/includes/plugin.php';
457
  deactivate_plugins( 'woocommerce-sequential-order-numbers/woocommerce-sequential-order-numbers.php' ); // hardcode the plugin path so that we can use symlinks in development
458
 
459
+ // Translators: %s - error message(s)
460
  wp_die( sprintf( __( 'Error activating and installing <strong>WooCommerce Sequential Order Numbers</strong>: %s', 'woocommerce-sequential-order-numbers' ), '<ul><li>' . implode( '</li><li>', $order_ids->get_error_messages() ) . '</li></ul>' ) .
461
  '<a href="' . admin_url( 'plugins.php' ) . '">' . __( '&laquo; Go Back', 'woocommerce-sequential-order-numbers' ) . '</a>' );
462
  }
463
 
464
 
465
  if ( is_array( $order_ids ) ) {
466
+
467
  foreach( $order_ids as $order_id ) {
468
+
469
  if ( '' == get_post_meta( $order_id, '_order_number', true ) ) {
470
  add_post_meta( $order_id, '_order_number', $order_id );
471
  }
495
  private function upgrade( $installed_version ) {
496
  // upgrade code goes here
497
  }
498
+
499
+
500
  }