WooCommerce Sequential Order Numbers - Version 1.9.0

Version Description

Download this release

Release Info

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

Code changes from version 1.8.3 to 1.9.0

i18n/languages/woocommerce-sequential-order-numbers.pot CHANGED
@@ -1,29 +1,29 @@
1
- # Copyright (C) 2018 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.8.3\n"
6
  "Report-Msgid-Bugs-To: "
7
  "https://woocommerce.com/my-account/marketplace-ticket-form/\n"
8
- "POT-Creation-Date: 2018-07-17 23:45:46+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: 2018-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:70
17
  #. translators: Placeholders: %s - plugin name
18
  msgid "You cannot clone instances of %s."
19
  msgstr ""
20
 
21
- #: woocommerce-sequential-order-numbers.php:82
22
  #. translators: Placeholders: %s - plugin name
23
  msgid "You cannot unserialize instances of %s."
24
  msgstr ""
25
 
26
- #: woocommerce-sequential-order-numbers.php:527
27
  #. translators: Placeholders: %1$s - plugin name; %2$s - WooCommerce version;
28
  #. %3$s, %5$s - <a> tags; %4$s - </a> tag
29
  msgid ""
@@ -31,14 +31,14 @@ msgid ""
31
  "%3$supdate WooCommerce%4$s or run the %5$sWooCommerce database upgrade%4$s."
32
  msgstr ""
33
 
34
- #: woocommerce-sequential-order-numbers.php:569
35
  #. Translators: %s - error message(s)
36
  msgid ""
37
  "Error activating and installing <strong>WooCommerce Sequential Order "
38
  "Numbers</strong>: %s"
39
  msgstr ""
40
 
41
- #: woocommerce-sequential-order-numbers.php:570
42
  msgid "&laquo; Go Back"
43
  msgstr ""
44
 
1
+ # Copyright (C) 2019 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.9.0\n"
6
  "Report-Msgid-Bugs-To: "
7
  "https://woocommerce.com/my-account/marketplace-ticket-form/\n"
8
+ "POT-Creation-Date: 2019-08-16 00:05:04+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: 2019-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:68
17
  #. translators: Placeholders: %s - plugin name
18
  msgid "You cannot clone instances of %s."
19
  msgstr ""
20
 
21
+ #: woocommerce-sequential-order-numbers.php:80
22
  #. translators: Placeholders: %s - plugin name
23
  msgid "You cannot unserialize instances of %s."
24
  msgstr ""
25
 
26
+ #: woocommerce-sequential-order-numbers.php:486
27
  #. translators: Placeholders: %1$s - plugin name; %2$s - WooCommerce version;
28
  #. %3$s, %5$s - <a> tags; %4$s - </a> tag
29
  msgid ""
31
  "%3$supdate WooCommerce%4$s or run the %5$sWooCommerce database upgrade%4$s."
32
  msgstr ""
33
 
34
+ #: woocommerce-sequential-order-numbers.php:528
35
  #. Translators: %s - error message(s)
36
  msgid ""
37
  "Error activating and installing <strong>WooCommerce Sequential Order "
38
  "Numbers</strong>: %s"
39
  msgstr ""
40
 
41
+ #: woocommerce-sequential-order-numbers.php:529
42
  msgid "&laquo; Go Back"
43
  msgstr ""
44
 
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: SkyVerge, maxrice, tamarazuk, chasewiseman, nekojira, beka.rice
3
  Tags: woocommerce, order number, sequential order number, woocommerce orders
4
  Requires at least: 4.4
5
- Tested up to: 4.9.7
6
- Stable tag: 1.8.3
7
 
8
  This plugin extends WooCommerce by setting sequential order numbers for new orders.
9
 
@@ -11,7 +11,7 @@ This plugin extends WooCommerce by setting sequential order numbers for new orde
11
 
12
  This plugin extends WooCommerce by automatically 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 2.6.14 or newer.**
15
 
16
  > No configuration needed! The plugin is so easy to use, there aren't even any settings. Activate it, and orders will automatically become sequential.
17
 
@@ -101,6 +101,10 @@ $order_number = $order->get_order_number();
101
 
102
  == Changelog ==
103
 
 
 
 
 
104
  = 2018.07.17 - version 1.8.3 =
105
  * Misc - Require WooCommerce 2.6.14+ and WordPress 4.4+
106
 
2
  Contributors: SkyVerge, maxrice, tamarazuk, chasewiseman, nekojira, beka.rice
3
  Tags: woocommerce, order number, sequential order number, woocommerce orders
4
  Requires at least: 4.4
5
+ Tested up to: 5.2.2
6
+ Stable tag: 1.9.0
7
 
8
  This plugin extends WooCommerce by setting sequential order numbers for new orders.
9
 
11
 
12
  This plugin extends WooCommerce by automatically 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 3.0.9 or newer.**
15
 
16
  > No configuration needed! The plugin is so easy to use, there aren't even any settings. Activate it, and orders will automatically become sequential.
17
 
101
 
102
  == Changelog ==
103
 
104
+ = 2019.08.15 - version 1.9.0 =
105
+ * Misc - Add support for WooCommerce 3.7
106
+ * Misc - Remove support for WooCommerce 2.6
107
+
108
  = 2018.07.17 - version 1.8.3 =
109
  * Misc - Require WooCommerce 2.6.14+ and WordPress 4.4+
110
 
woocommerce-sequential-order-numbers.php CHANGED
@@ -5,23 +5,21 @@
5
  * Description: Provides sequential order numbers for WooCommerce orders
6
  * Author: SkyVerge
7
  * Author URI: http://www.skyverge.com
8
- * Version: 1.8.3
9
  * Text Domain: woocommerce-sequential-order-numbers
10
  * Domain Path: /i18n/languages/
11
  *
12
- * Copyright: (c) 2012-2018, 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
16
  *
17
- * @package WC-Sequential-Order-Numbers
18
  * @author SkyVerge
19
- * @category Plugin
20
- * @copyright Copyright (c) 2012-2018, SkyVerge, Inc.
21
  * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
22
  *
23
- * WC requires at least: 2.6.14
24
- * WC tested up to: 3.4.3
25
  */
26
 
27
  defined( 'ABSPATH' ) or exit;
@@ -35,10 +33,10 @@ class WC_Seq_Order_Number {
35
 
36
 
37
  /** version number */
38
- const VERSION = '1.8.3';
39
 
40
  /** minimum required wc version */
41
- const MINIMUM_WC_VERSION = '2.6.14';
42
 
43
  /** @var \WC_Seq_Order_Number single instance of this plugin */
44
  protected static $instance;
@@ -111,6 +109,11 @@ class WC_Seq_Order_Number {
111
  add_filter( 'wcs_renewal_order_meta_query', array( $this, 'subscriptions_remove_renewal_order_meta' ) );
112
  add_filter( 'wcs_renewal_order_created', array( $this, 'subscriptions_set_sequential_order_number' ), 10, 2 );
113
 
 
 
 
 
 
114
  if ( is_admin() ) {
115
  add_filter( 'request', array( $this, 'woocommerce_custom_shop_order_orderby' ), 20 );
116
  add_filter( 'woocommerce_shop_order_search_fields', array( $this, 'custom_search_fields' ) );
@@ -172,12 +175,12 @@ class WC_Seq_Order_Number {
172
  return 0;
173
  }
174
 
175
- if ( self::get_order_meta( $order, '_order_number' ) ) {
176
- // _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
177
  return 0;
178
  }
179
 
180
- return self::get_order_prop( $order, 'id' );
181
  }
182
 
183
 
@@ -193,7 +196,7 @@ class WC_Seq_Order_Number {
193
  if ( 'shop_order' === $post->post_type && 'auto-draft' !== $post->post_status ) {
194
 
195
  $order = wc_get_order( $post_id );
196
- $order_number = self::get_order_meta( $order, '_order_number' );
197
 
198
  if ( '' === $order_number ) {
199
 
@@ -222,13 +225,13 @@ class WC_Seq_Order_Number {
222
  * for display.
223
  *
224
  * @param string $order_number the order id with a leading hash
225
- * @param WC_Order $order the order object
226
  * @return string custom order number
227
  */
228
  public function get_order_number( $order_number, $order ) {
229
 
230
- if ( self::get_order_meta( $order, '_order_number' ) ) {
231
- $order_number = self::get_order_meta( $order, '_order_number' );
232
  }
233
 
234
  return $order_number;
@@ -296,22 +299,22 @@ class WC_Seq_Order_Number {
296
 
297
 
298
  /**
299
- * Sets an order number on a subscriptions-created order
300
  *
301
  * @since 1.3
 
302
  * @param \WC_Order $renewal_order the new renewal order object
303
- * @param \WC_Subscription $subscription Post ID of a 'shop_subscription' post, or instance of a WC_Subscription object
304
  * @return \WC_Order renewal order instance
305
  */
306
  public function subscriptions_set_sequential_order_number( $renewal_order, $subscription ) {
307
 
308
- // sanity check
309
- if ( ! $renewal_order instanceof WC_Order ) {
310
- return $renewal_order;
311
- }
312
 
313
- $order_post = get_post( self::get_order_prop( $renewal_order, 'id' ) );
314
- $this->set_sequential_order_number( $order_post->ID, $order_post );
 
 
315
 
316
  // after Subs 2.0 this callback needs to return the renewal order
317
  return $renewal_order;
@@ -332,6 +335,47 @@ class WC_Seq_Order_Number {
332
  return $order_meta_query . " AND meta_key NOT IN ( '_order_number' )";
333
  }
334
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
335
 
336
  /** Helper Methods ******************************************************/
337
 
@@ -344,25 +388,12 @@ class WC_Seq_Order_Number {
344
  * @return \WC_Seq_Order_Number
345
  */
346
  public static function instance() {
347
- if ( is_null( self::$instance ) ) {
 
348
  self::$instance = new self();
349
  }
350
- return self::$instance;
351
- }
352
-
353
-
354
- /**
355
- * Checks if WooCommerce is active
356
- *
357
- * @since 1.3
358
- * @deprecated 1.8.3
359
- *
360
- * @return bool true if WooCommerce is active, false otherwise
361
- */
362
- public static function is_woocommerce_active() {
363
 
364
- _deprecated_function( 'WC_Seq_Order_Number::is_woocommerce_active', '1.8.3', 'WC_Seq_Order_Number::is_plugin_active' );
365
- return self::is_plugin_active( 'woocommerce.php' );
366
  }
367
 
368
 
@@ -404,67 +435,6 @@ class WC_Seq_Order_Number {
404
  }
405
 
406
 
407
- /**
408
- * Helper method to get order properties pre and post WC 3.0.
409
- *
410
- * TODO: Remove this when WooCommerce 3.0+ is required and remove helpers {BR 2017-03-08}
411
- *
412
- * @param \WC_Order $order the order for which to get data
413
- * @param string $prop the order property to get
414
- * @param string $context the context for the property, 'edit' or 'view'
415
- * @return mixed the order property
416
- */
417
- protected static function get_order_prop( $order, $prop, $context = 'edit' ) {
418
-
419
- $value = '';
420
-
421
- if ( self::is_wc_version_gte_3_0() ) {
422
-
423
- if ( is_callable( array( $order, "get_{$prop}" ) ) ) {
424
- $value = $order->{"get_{$prop}"}( $context );
425
- }
426
-
427
- } else {
428
-
429
- // if this is the 'view' context and there is an accessor method, use it
430
- if ( is_callable( array( $order, "get_{$prop}" ) ) && 'view' === $context ) {
431
- $value = $order->{"get_{$prop}"}();
432
- } else {
433
- $value = $order->$prop;
434
- }
435
- }
436
-
437
- return $value;
438
- }
439
-
440
-
441
- /**
442
- * Helper method to get order meta pre and post WC 3.0.
443
- *
444
- * TODO: Remove this when WooCommerce 3.0+ is required and remove helpers {BR 2017-03-08}
445
- *
446
- * @param \WC_Order $order the order object
447
- * @param string $key the meta key
448
- * @param bool $single whether to get the meta as a single item. Defaults to `true`
449
- * @param string $context if 'view' then the value will be filtered
450
- * @return mixed the order property
451
- */
452
- protected static function get_order_meta( $order, $key = '', $single = true, $context = 'edit' ) {
453
-
454
- if ( self::is_wc_version_gte_3_0() ) {
455
-
456
- $value = $order->get_meta( $key, $single, $context );
457
-
458
- } else {
459
-
460
- $order_id = is_callable( array( $order, 'get_id' ) ) ? $order->get_id() : $order->id;
461
- $value = get_post_meta( $order_id, $key, $single );
462
- }
463
-
464
- return $value;
465
- }
466
-
467
-
468
  /** Compatibility Methods ******************************************************/
469
 
470
 
@@ -479,17 +449,6 @@ class WC_Seq_Order_Number {
479
  }
480
 
481
 
482
- /**
483
- * Returns true if the installed version of WooCommerce is 3.0 or greater
484
- *
485
- * @since 1.8.0
486
- * @return boolean true if the installed version of WooCommerce is 3.0 or greater
487
- */
488
- private static function is_wc_version_gte_3_0() {
489
- return self::get_wc_version() && version_compare( self::get_wc_version(), '3.0', '>=' );
490
- }
491
-
492
-
493
  /**
494
  * Perform a minimum WooCommerce version check
495
  *
@@ -602,9 +561,11 @@ class WC_Seq_Order_Number {
602
 
603
 
604
  /**
605
- * Run when plugin version number changes
606
  *
607
  * 1.0.0
 
 
608
  */
609
  private function upgrade( $installed_version ) {
610
  // upgrade code goes here
5
  * Description: Provides sequential order numbers for WooCommerce orders
6
  * Author: SkyVerge
7
  * Author URI: http://www.skyverge.com
8
+ * Version: 1.9.0
9
  * Text Domain: woocommerce-sequential-order-numbers
10
  * Domain Path: /i18n/languages/
11
  *
12
+ * Copyright: (c) 2012-2019, 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
16
  *
 
17
  * @author SkyVerge
18
+ * @copyright Copyright (c) 2012-2019, SkyVerge, Inc.
 
19
  * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
20
  *
21
+ * WC requires at least: 3.0.9
22
+ * WC tested up to: 3.7.0
23
  */
24
 
25
  defined( 'ABSPATH' ) or exit;
33
 
34
 
35
  /** version number */
36
+ const VERSION = '1.9.0';
37
 
38
  /** minimum required wc version */
39
+ const MINIMUM_WC_VERSION = '3.0.9';
40
 
41
  /** @var \WC_Seq_Order_Number single instance of this plugin */
42
  protected static $instance;
109
  add_filter( 'wcs_renewal_order_meta_query', array( $this, 'subscriptions_remove_renewal_order_meta' ) );
110
  add_filter( 'wcs_renewal_order_created', array( $this, 'subscriptions_set_sequential_order_number' ), 10, 2 );
111
 
112
+ // WooCommerce Admin support
113
+ if ( class_exists( 'WC_Admin_Install', false ) ) {
114
+ add_filter( 'woocommerce_rest_orders_prepare_object_query', array( $this, 'wc_admin_order_number_api_param' ), 10, 2 );
115
+ }
116
+
117
  if ( is_admin() ) {
118
  add_filter( 'request', array( $this, 'woocommerce_custom_shop_order_orderby' ), 20 );
119
  add_filter( 'woocommerce_shop_order_search_fields', array( $this, 'custom_search_fields' ) );
175
  return 0;
176
  }
177
 
178
+ // _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
179
+ if ( $order->get_meta( '_order_number', true, 'edit' ) ) {
180
  return 0;
181
  }
182
 
183
+ return $order->get_id();
184
  }
185
 
186
 
196
  if ( 'shop_order' === $post->post_type && 'auto-draft' !== $post->post_status ) {
197
 
198
  $order = wc_get_order( $post_id );
199
+ $order_number = $order->get_meta( '_order_number', true, 'edit' );
200
 
201
  if ( '' === $order_number ) {
202
 
225
  * for display.
226
  *
227
  * @param string $order_number the order id with a leading hash
228
+ * @param \WC_Order $order the order object
229
  * @return string custom order number
230
  */
231
  public function get_order_number( $order_number, $order ) {
232
 
233
+ if ( $sequential_order_number = $order->get_meta( '_order_number', true, 'edit' ) ) {
234
+ $order_number = $sequential_order_number;
235
  }
236
 
237
  return $order_number;
299
 
300
 
301
  /**
302
+ * Sets an order number on a subscriptions-created order.
303
  *
304
  * @since 1.3
305
+ *
306
  * @param \WC_Order $renewal_order the new renewal order object
307
+ * @param \WC_Subscription $subscription Post ID of a 'shop_subscription' post, or instance of a WC_Subscription object
308
  * @return \WC_Order renewal order instance
309
  */
310
  public function subscriptions_set_sequential_order_number( $renewal_order, $subscription ) {
311
 
312
+ if ( $renewal_order instanceof WC_Order ) {
 
 
 
313
 
314
+ $order_post = get_post( $renewal_order->get_id() );
315
+
316
+ $this->set_sequential_order_number( $order_post->ID, $order_post );
317
+ }
318
 
319
  // after Subs 2.0 this callback needs to return the renewal order
320
  return $renewal_order;
335
  return $order_meta_query . " AND meta_key NOT IN ( '_order_number' )";
336
  }
337
 
338
+ /**
339
+ * Hook WooCommerce Admin's order number search to the meta value.
340
+ *
341
+ * @param array $args Arguments to be passed to WC_Order_Query.
342
+ * @param WP_REST_Request $request REST API request being made.
343
+ * @return array Arguments to be passed to WC_Order_Query.
344
+ */
345
+ public function wc_admin_order_number_api_param( $args, $request ) {
346
+ global $wpdb;
347
+
348
+ if (
349
+ '/wc/v4/orders' === $request->get_route() &&
350
+ isset( $request['number'] )
351
+ ) {
352
+ // Handles 'number' value here and modify $args.
353
+ $number_search = trim( $request['number'] );
354
+ $order_sql = esc_sql( $args['order'] ); // Order defaults to DESC.
355
+ $limit = intval( $args['posts_per_page'] ); // Posts per page defaults to 10.
356
+
357
+ // Search Order number meta value instead of Post ID.
358
+ $order_ids = $wpdb->get_col(
359
+ $wpdb->prepare(
360
+ "SELECT post_id
361
+ FROM {$wpdb->prefix}postmeta
362
+ WHERE meta_key = '_order_number'
363
+ AND meta_value LIKE %s
364
+ ORDER BY post_id {$order_sql}
365
+ LIMIT %d",
366
+ $wpdb->esc_like( $number_search ) . '%',
367
+ $limit
368
+ )
369
+ );
370
+
371
+ $args['post__in'] = empty( $order_ids ) ? array( 0 ) : $order_ids;
372
+
373
+ // Remove the 'number' parameter to short circuit WooCommerce Admin's handling.
374
+ unset( $request['number'] );
375
+ }
376
+
377
+ return $args;
378
+ }
379
 
380
  /** Helper Methods ******************************************************/
381
 
388
  * @return \WC_Seq_Order_Number
389
  */
390
  public static function instance() {
391
+
392
+ if ( null === self::$instance ) {
393
  self::$instance = new self();
394
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
395
 
396
+ return self::$instance;
 
397
  }
398
 
399
 
435
  }
436
 
437
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
438
  /** Compatibility Methods ******************************************************/
439
 
440
 
449
  }
450
 
451
 
 
 
 
 
 
 
 
 
 
 
 
452
  /**
453
  * Perform a minimum WooCommerce version check
454
  *
561
 
562
 
563
  /**
564
+ * Runs when plugin version number changes.
565
  *
566
  * 1.0.0
567
+ *
568
+ * @param string $installed_version
569
  */
570
  private function upgrade( $installed_version ) {
571
  // upgrade code goes here