WooCommerce Sequential Order Numbers - Version 1.9.1

Version Description

Download this release

Release Info

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

Code changes from version 1.9.0 to 1.9.1

build/i18n/languages/woocommerce-sequential-order-numbers.pot ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.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: 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:458
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:459
24
+ msgid "&laquo; Go Back"
25
+ msgstr ""
26
+
27
+ #. Plugin Name of the plugin/theme
28
+ msgid "WooCommerce Sequential Order Numbers"
29
+ msgstr ""
30
+
31
+ #. Plugin URI of the plugin/theme
32
+ msgid "http://www.skyverge.com/blog/woocommerce-sequential-order-numbers/"
33
+ msgstr ""
34
+
35
+ #. Description of the plugin/theme
36
+ msgid "Provides sequential order numbers for WooCommerce orders"
37
+ msgstr ""
38
+
39
+ #. Author of the plugin/theme
40
+ msgid "SkyVerge"
41
+ msgstr ""
42
+
43
+ #. Author URI of the plugin/theme
44
+ msgid "http://www.skyverge.com"
45
+ msgstr ""
build/readme.txt ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.2
6
+ Requires WooCommerce at least: 2.3
7
+ Tested WooCommerce up to: 2.5
8
+ Stable tag: 1.6.1
9
+
10
+ This plugin extends WooCommerce by setting sequential order numbers for new orders.
11
+
12
+ == Description ==
13
+
14
+ 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.
15
+
16
+ **This plugin requires WooCommerce 2.1 or newer.**
17
+
18
+ > No configuration needed! The plugin is so easy to use, there aren't even any settings. Activate it, and orders will automatically become sequential.
19
+
20
+ 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 our premium WooCommerce Sequential Order Numbers Pro plugin, which is available in the [WooThemes Store](http://www.woothemes.com/products/sequential-order-numbers-pro/).
21
+
22
+ = Feedback =
23
+ * We are open to your suggestions and feedback - Thank you for using or trying out one of our plugins!
24
+ * Drop us a line at [www.skyverge.com](http://www.skyverge.com)
25
+
26
+ = Support Details =
27
+ We do support our free plugins and extensions, but please understand that support for premium products takes priority. We typically check the forums every few days (with a maximum delay of one week).
28
+
29
+ = More Details =
30
+ - See the [product page](http://www.skyverge.com/product/woocommerce-sequential-order-numbers/) for full details.
31
+ - Check out the [Pro Version](http://www.woothemes.com/products/sequential-order-numbers-pro/).
32
+ - View more of SkyVerge's [free WooCommerce extensions](http://profiles.wordpress.org/skyverge/)
33
+ - View all [SkyVerge WooCommerce extensions](http://www.skyverge.com/shop/)
34
+
35
+ == Installation ==
36
+
37
+ 1. Upload the entire 'woocommerce-sequential-order-numbers' folder to the '/wp-content/plugins/' directory or upload the zip via Plugins &gt; Add New
38
+ 2. Activate the plugin through the 'Plugins' menu in WordPress
39
+ 3. No configuration needed! Order numbers will continue sequentially from the current highest order number, or from 1 if no orders have been placed yet
40
+
41
+ == Frequently Asked Questions ==
42
+
43
+ = Where are the settings? =
44
+
45
+ The plugin doesn't require any :). When you activate it, it gets to work right away! Orders will automatically become sequential, starting from the most recent order number.
46
+
47
+ = Can I start the order numbers at a particular number? =
48
+
49
+ This free version does not have that functionality, but the premium [WooCommerce Sequential Order Numbers Pro](http://www.woothemes.com/products/sequential-order-numbers-pro/) will allow you to choose any starting number that's higher than your most current order number.
50
+
51
+ = Can I set an order number prefix/suffix? =
52
+
53
+ This free version does not have that functionality, but it's included in the premium [WooCommerce Sequential Order Numbers Pro](http://www.woothemes.com/products/sequential-order-numbers-pro/).
54
+
55
+ == Changelog ==
56
+
57
+ = 1.6.1 - 2016.02.04 =
58
+ * Misc - WooCommerce Subscriptions: Use new hook wcs_renewal_order_meta_query instead of deprecated woocommerce_subscriptions_renewal_order_meta_query
59
+
60
+ = 1.6.0 - 2016.01.20 =
61
+ * Misc - WooCommerce Subscriptions: Use new filter hook wcs_renewal_order_created instead of deprecated woocommerce_subscriptions_renewal_order_created
62
+ * Misc - WooCommerce 2.5 compatibility
63
+ * Misc - Dropped WooCommerce 2.2 support
64
+
65
+ = 1.5.1 - 2015.11.26 =
66
+ * Fix - Compatibility fix with WooCommerce Subscriptions 2.0
67
+
68
+ = 1.5.0 - 2015.07.28 =
69
+ * Misc - WooCommerce 2.4 Compatibility
70
+
71
+ = 1.4.0 - 2015.02.10 =
72
+ * Fix - Improved install routine for shops with a large number of orders
73
+ * Misc - WooCommerce 2.3 compatibility
74
+
75
+ = 1.3.4 - 2014.09.23 =
76
+ * Fix - Compatibility fix with WooCommerce 2.1
77
+ * Fix - Fix a deprecated notice in WooCommerce 2.2
78
+
79
+ = 1.3.3 - 2014.09.05 =
80
+ * Localization - Included a .pot file for localization
81
+
82
+ = 1.3.2 - 2014.09.02 =
83
+ * Misc - WooCommerce 2.2 compatibility
84
+
85
+ = 1.3.1 - 2014.01.22 =
86
+ * Misc - WooCommerce 2.1 compatibility
87
+
88
+ = 1.3 - 2013.04.26 =
89
+ * Feature - Improved WooCommerce Subscriptions compatibility
90
+ * Feature - Improved WooCommerce Pre-Orders compatibility
91
+ * General code cleanup and refactor
92
+
93
+ = 1.2.4 - 2012.12.14 =
94
+ * Fix - WordPress 3.5 compatibility fix
95
+ * Fix - Order numbers not assigned to temporary auto-draft orders created from the admin
96
+
97
+ = 1.2.3 - 2012.06.06 =
98
+ * Fix - Removed WooCommerce functions, which caused a compatibility issue with other WooCommerce plugins
99
+
100
+ = 1.2.2 - 2012.05.25 =
101
+ * Tweak - Takes advantage of new action hooks/filters available in WooCommerce 1.5.6
102
+ * Fix - Bug fix on installation to stores with more than 10 existing orders
103
+
104
+ = 1.2.1 - 2012.05.13 =
105
+ * Tweak - Minor updates due to WooCommerce 1.5.5 release
106
+
107
+ = 1.2.0 - 2012.04.21 =
108
+ * Feature - Added support for the order tracking page
109
+
110
+ = 1.1.2 - 2012.04.18 =
111
+ * Tweak - Minor updates due to WooCommerce 1.5.4 release
112
+
113
+ = 1.1.1 - 2012.04.02 =
114
+ * Fix - Order number in the subject line of the admin new order email is fixed
115
+
116
+ = 1.1.0 - 2012.04.02 =
117
+ * Feature - Search by order number
118
+
119
+ = 1.0.1 - 2012.04.02 =
120
+ * Fix - small bug fix
121
+
122
+ = 1.0.0 - 2012.04.02 =
123
+ * Initial Release
124
+
125
+ == Upgrade Notice ==
126
+
127
+ = 1.2.2 - 2012.05.25 =
128
+ This version requires WooCommerce 1.5.6
129
+
130
+ = 1.2.1 - 2012.05.13 =
131
+ This version requires WooCommerce 1.5.5
build/woocommerce-sequential-order-numbers.php ADDED
@@ -0,0 +1,498 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin Name: WooCommerce Sequential Order Numbers
4
+ * Plugin URI: http://www.skyverge.com/blog/woocommerce-sequential-order-numbers/
5
+ * Description: Provides sequential order numbers for WooCommerce orders
6
+ * Author: SkyVerge
7
+ * Author URI: http://www.skyverge.com
8
+ * Version: 1.6.1
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
16
+ *
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
+
24
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
25
+
26
+ // Check if WooCommerce is active
27
+ if ( ! WC_Seq_Order_Number::is_woocommerce_active() ) {
28
+ return;
29
+ }
30
+
31
+ /**
32
+ * The WC_Seq_Order_Number global object
33
+ * @name $wc_seq_order_number
34
+ * @global WC_Seq_Order_Number $GLOBALS['wc_seq_order_number']
35
+ */
36
+ $GLOBALS['wc_seq_order_number'] = new WC_Seq_Order_Number();
37
+
38
+ class WC_Seq_Order_Number {
39
+
40
+
41
+ /** version number */
42
+ const VERSION = '1.6.1';
43
+
44
+ /** version option name */
45
+ const VERSION_OPTION_NAME = 'woocommerce_seq_order_number_db_version';
46
+
47
+ /** minimum required wc version */
48
+ const MINIMUM_WC_VERSION = '2.3';
49
+
50
+
51
+ /**
52
+ * Construct the plugin
53
+ *
54
+ * @since 1.3.2
55
+ */
56
+ public function __construct() {
57
+
58
+ add_action( 'plugins_loaded', array( $this, 'initialize' ) );
59
+ add_action( 'init', array( $this, 'load_translation' ) );
60
+ }
61
+
62
+
63
+ /**
64
+ * Initialize the plugin, bailing if any required conditions are not met,
65
+ * including minimum WooCommerce version
66
+ *
67
+ * @since 1.3.2
68
+ */
69
+ public function initialize() {
70
+
71
+ if ( ! $this->minimum_wc_version_met() ) {
72
+ // halt functionality
73
+ return;
74
+ }
75
+
76
+ // Set the custom order number on the new order. we hook into wp_insert_post for orders which are created
77
+ // from the frontend, and we hook into woocommerce_process_shop_order_meta for admin-created orders
78
+ add_action( 'wp_insert_post', array( $this, 'set_sequential_order_number' ), 10, 2 );
79
+ add_action( 'woocommerce_process_shop_order_meta', array( $this, 'set_sequential_order_number' ), 10, 2 );
80
+
81
+ // return our custom order number for display
82
+ add_filter( 'woocommerce_order_number', array( $this, 'get_order_number' ), 10, 2 );
83
+
84
+ // order tracking page search by order number
85
+ add_filter( 'woocommerce_shortcode_order_tracking_order_id', array( $this, 'find_order_by_order_number' ) );
86
+
87
+ // WC Subscriptions support
88
+ if ( self::is_wc_subscriptions_version_gte_2_0() ) {
89
+ add_filter( 'wcs_renewal_order_meta_query', array( $this, 'subscriptions_remove_renewal_order_meta' ) );
90
+ add_filter( 'wcs_renewal_order_created', array( $this, 'subscriptions_set_sequential_order_number' ), 10, 2 );
91
+ } else {
92
+ add_filter( 'woocommerce_subscriptions_renewal_order_meta_query', array( $this, 'subscriptions_remove_renewal_order_meta' ) );
93
+ add_action( 'woocommerce_subscriptions_renewal_order_created', array( $this, 'subscriptions_set_sequential_order_number' ), 10, 2 );
94
+ }
95
+
96
+ if ( is_admin() ) {
97
+ add_filter( 'request', array( $this, 'woocommerce_custom_shop_order_orderby' ), 20 );
98
+ add_filter( 'woocommerce_shop_order_search_fields', array( $this, 'custom_search_fields' ) );
99
+
100
+ // sort by underlying _order_number on the Pre-Orders table
101
+ add_filter( 'wc_pre_orders_edit_pre_orders_request', array( $this, 'custom_orderby' ) );
102
+ add_filter( 'wc_pre_orders_search_fields', array( $this, 'custom_search_fields' ) );
103
+ }
104
+
105
+ // Installation
106
+ if ( is_admin() && ! is_ajax() ) {
107
+ $this->install();
108
+ }
109
+ }
110
+
111
+
112
+ /**
113
+ * Load Translations
114
+ *
115
+ * @since 1.3.3
116
+ */
117
+ public function load_translation() {
118
+
119
+ // localization
120
+ load_plugin_textdomain( 'woocommerce-sequential-order-numbers', false, dirname( plugin_basename( __FILE__ ) ) . '/i18n/languages' );
121
+ }
122
+
123
+
124
+ /**
125
+ * Search for an order with order_number $order_number
126
+ *
127
+ * @param string $order_number order number to search for
128
+ * @return int post_id for the order identified by $order_number, or 0
129
+ */
130
+ public function find_order_by_order_number( $order_number ) {
131
+
132
+ // search for the order by custom order number
133
+ $query_args = array(
134
+ 'numberposts' => 1,
135
+ 'meta_key' => '_order_number',
136
+ 'meta_value' => $order_number,
137
+ 'post_type' => 'shop_order',
138
+ 'post_status' => 'any',
139
+ 'fields' => 'ids',
140
+ );
141
+
142
+ $posts = get_posts( $query_args );
143
+ list( $order_id ) = ! empty( $posts ) ? $posts : null;
144
+
145
+ // order was found
146
+ if ( $order_id !== null ) {
147
+ return $order_id;
148
+ }
149
+
150
+ // if we didn't find the order, then it may be that this plugin was disabled and an order was placed in the interim
151
+ $order = wc_get_order( $order_number );
152
+
153
+ if ( ! $order ) {
154
+ return 0;
155
+ }
156
+
157
+ if ( $order->order_number ) {
158
+ // _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
159
+ return 0;
160
+ }
161
+
162
+ return $order->id;
163
+ }
164
+
165
+
166
+ /**
167
+ * Set the _order_number field for the newly created order
168
+ *
169
+ * @param int $post_id post identifier
170
+ * @param WP_Post $post post object
171
+ */
172
+ public function set_sequential_order_number( $post_id, $post ) {
173
+ global $wpdb;
174
+
175
+ if ( 'shop_order' === $post->post_type && 'auto-draft' !== $post->post_status ) {
176
+
177
+ $order_number = get_post_meta( $post_id, '_order_number', true );
178
+
179
+ if ( '' === $order_number ) {
180
+
181
+ // attempt the query up to 3 times for a much higher success rate if it fails (due to Deadlock)
182
+ $success = false;
183
+ for ( $i = 0; $i < 3 && ! $success; $i++ ) {
184
+
185
+ // this seems to me like the safest way to avoid order number clashes
186
+ $query = $wpdb->prepare( "
187
+ INSERT INTO {$wpdb->postmeta} (post_id, meta_key, meta_value)
188
+ SELECT %d, '_order_number', IF( MAX( CAST( meta_value as UNSIGNED ) ) IS NULL, 1, MAX( CAST( meta_value as UNSIGNED ) ) + 1 )
189
+ FROM {$wpdb->postmeta}
190
+ WHERE meta_key='_order_number'",
191
+ $post_id );
192
+
193
+ $success = $wpdb->query( $query );
194
+ }
195
+ }
196
+ }
197
+ }
198
+
199
+
200
+ /**
201
+ * Filter to return our _order_number field rather than the post ID,
202
+ * for display.
203
+ *
204
+ * @param string $order_number the order id with a leading hash
205
+ * @param WC_Order $order the order object
206
+ * @return string custom order number, with leading hash for < WC 2.3
207
+ */
208
+ public function get_order_number( $order_number, $order ) {
209
+
210
+ if ( $order->order_number ) {
211
+ return $order->order_number;
212
+ }
213
+
214
+ return $order_number;
215
+ }
216
+
217
+
218
+ /** Admin filters ******************************************************/
219
+
220
+
221
+ /**
222
+ * Admin order table orderby ID operates on our meta _order_number
223
+ *
224
+ * @param array $vars associative array of orderby parameteres
225
+ * @return array associative array of orderby parameteres
226
+ */
227
+ public function woocommerce_custom_shop_order_orderby( $vars ) {
228
+ global $typenow, $wp_query;
229
+
230
+ if ( 'shop_order' === $typenow ) {
231
+ return $vars;
232
+ }
233
+
234
+ return $this->custom_orderby( $vars );
235
+ }
236
+
237
+
238
+ /**
239
+ * Mofifies the given $args argument to sort on our meta integral _order_number
240
+ *
241
+ * @since 1.3
242
+ * @param array $args associative array of orderby parameteres
243
+ * @return array associative array of orderby parameteres
244
+ */
245
+ public function custom_orderby( $args ) {
246
+
247
+ // Sorting
248
+ if ( isset( $args['orderby'] ) && 'ID' == $args['orderby'] ) {
249
+
250
+ $args = array_merge( $args, array(
251
+ 'meta_key' => '_order_number', // sort on numerical portion for better results
252
+ 'orderby' => 'meta_value_num',
253
+ ) );
254
+ }
255
+
256
+ return $args;
257
+ }
258
+
259
+
260
+ /**
261
+ * Add our custom _order_number to the set of search fields so that
262
+ * the admin search functionality is maintained
263
+ *
264
+ * @param array $search_fields array of post meta fields to search by
265
+ * @return array of post meta fields to search by
266
+ */
267
+ public function custom_search_fields( $search_fields ) {
268
+
269
+ array_push( $search_fields, '_order_number' );
270
+
271
+ return $search_fields;
272
+ }
273
+
274
+
275
+ /** 3rd Party Plugin Support ******************************************************/
276
+
277
+
278
+ /**
279
+ * Helper method to get the version of WooCommerce Subscriptions
280
+ *
281
+ * @since 1.5.1
282
+ * @return string|null WC_Subscriptions version number or null if not found
283
+ */
284
+ protected static function get_wc_subscriptions_version() {
285
+ return class_exists( 'WC_Subscriptions' ) && ! empty( WC_Subscriptions::$version ) ? WC_Subscriptions::$version : null;
286
+ }
287
+
288
+
289
+ /**
290
+ * Returns true if the installed version of WooCommerce Subscriptions is 2.0.0 or greater
291
+ *
292
+ * @since 1.5.1
293
+ * @return boolean
294
+ */
295
+ protected static function is_wc_subscriptions_version_gte_2_0() {
296
+ return self::get_wc_subscriptions_version() && version_compare( self::get_wc_subscriptions_version(), '2.0-beta-1', '>=' );
297
+ }
298
+
299
+
300
+ /**
301
+ * Sets an order number on a subscriptions-created order
302
+ *
303
+ * @since 1.3
304
+ * @param WC_Order $renewal_order the new renewal order object
305
+ * @param WC_Order $original_order the original order object (Subscriptions 2.0+: Subscription object)
306
+ * @return void|WC_Order Void for Subscriptions 1.5, renewal order instance for Subscriptions 2.0+
307
+ */
308
+ public function subscriptions_set_sequential_order_number( $renewal_order, $original_order ) {
309
+
310
+ $order_post = get_post( $renewal_order->id );
311
+ $this->set_sequential_order_number( $order_post->ID, $order_post );
312
+
313
+ // after 2.0 this callback needs to return the renewal order
314
+ if ( self::is_wc_subscriptions_version_gte_2_0() ) {
315
+ return $renewal_order;
316
+ }
317
+ }
318
+
319
+
320
+ /**
321
+ * Don't copy over order number meta when creating a parent or child renewal order
322
+ *
323
+ * Prevents unnecessary order meta from polluting parent renewal orders,
324
+ * and set order number for subscription orders
325
+ *
326
+ * @since 1.3
327
+ * @param array $order_meta_query query for pulling the metadata
328
+ * @return string
329
+ */
330
+ public function subscriptions_remove_renewal_order_meta( $order_meta_query ) {
331
+ return $order_meta_query . " AND meta_key NOT IN ( '_order_number' )";
332
+ }
333
+
334
+
335
+ /** Helper Methods ******************************************************/
336
+
337
+
338
+ /**
339
+ * Checks if WooCommerce is active
340
+ *
341
+ * @since 1.3
342
+ * @return bool true if WooCommerce is active, false otherwise
343
+ */
344
+ public static function is_woocommerce_active() {
345
+
346
+ $active_plugins = (array) get_option( 'active_plugins', array() );
347
+
348
+ if ( is_multisite() ) {
349
+ $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
350
+ }
351
+
352
+ return in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins );
353
+ }
354
+
355
+
356
+ /** Compatibility Methods ******************************************************/
357
+
358
+
359
+ /**
360
+ * Helper method to get the version of the currently installed WooCommerce
361
+ *
362
+ * @since 1.3.2
363
+ * @return string woocommerce version number or null
364
+ */
365
+ private static function get_wc_version() {
366
+ return defined( 'WC_VERSION' ) && WC_VERSION ? WC_VERSION : null;
367
+ }
368
+
369
+
370
+ /**
371
+ * Returns true if the installed version of WooCommerce is 2.4 or greater
372
+ *
373
+ * @since 1.6.0
374
+ * @return boolean true if the installed version of WooCommerce is 2.3 or greater
375
+ */
376
+ public static function is_wc_version_gte_2_4() {
377
+ return self::get_wc_version() && version_compare( self::get_wc_version(), '2.4', '>=' );
378
+ }
379
+
380
+
381
+ /**
382
+ * Returns true if the installed version of WooCommerce is 2.5 or greater
383
+ *
384
+ * @since 1.6.0
385
+ * @return boolean true if the installed version of WooCommerce is 2.3 or greater
386
+ */
387
+ public static function is_wc_version_gte_2_5() {
388
+ return self::get_wc_version() && version_compare( self::get_wc_version(), '2.5', '>=' );
389
+ }
390
+
391
+
392
+ /**
393
+ * Perform a minimum WooCommerce version check
394
+ *
395
+ * @since 1.3.2
396
+ * @return boolean true if the required version is met, false otherwise
397
+ */
398
+ private function minimum_wc_version_met() {
399
+
400
+ // if a plugin defines a minimum WC version, render a notice and skip loading the plugin
401
+ if ( defined( 'self::MINIMUM_WC_VERSION' ) && version_compare( self::get_wc_version(), self::MINIMUM_WC_VERSION, '<' ) ) {
402
+
403
+ if ( is_admin() && ! is_ajax() && ! has_action( 'admin_notices', array( $this, 'render_update_notices' ) ) ) {
404
+
405
+ add_action( 'admin_notices', array( $this, 'render_update_notices' ) );
406
+ }
407
+
408
+ return false;
409
+ }
410
+
411
+ return true;
412
+ }
413
+
414
+
415
+ /**
416
+ * Render a notice to update WooCommerce if needed
417
+ *
418
+ * @since 1.3.2
419
+ */
420
+ public function render_update_notices() {
421
+
422
+ echo '<div class="error"><p>The following plugin is inactive because it requires a newer version of WooCommerce:</p><ul>';
423
+
424
+ printf( '<li>%1$s requires WooCommerce %2$s or newer</li>', 'Sequential Order Numbers', self::MINIMUM_WC_VERSION );
425
+
426
+ echo '</ul><p>Please <a href="' . admin_url( 'update-core.php' ) . '">update WooCommerce&nbsp;&raquo;</a></p></div>';
427
+
428
+ }
429
+
430
+
431
+ /** Lifecycle methods ******************************************************/
432
+
433
+
434
+ /**
435
+ * Run every time. Used since the activation hook is not executed when updating a plugin
436
+ */
437
+ private function install() {
438
+ $installed_version = get_option( WC_Seq_Order_Number::VERSION_OPTION_NAME );
439
+
440
+ if ( ! $installed_version ) {
441
+
442
+ // initial install, set the order number for all existing orders to the post id:
443
+ // page through the "publish" orders in blocks to avoid out of memory errors
444
+ $offset = (int) get_option( 'wc_sequential_order_numbers_install_offset', 0 );
445
+ $posts_per_page = 500;
446
+
447
+ do {
448
+
449
+ // initial install, set the order number for all existing orders to the post id
450
+ $order_ids = get_posts( array( 'post_type' => 'shop_order', 'fields' => 'ids', 'offset' => $offset, 'posts_per_page' => $posts_per_page, 'post_status' => 'any' ) );
451
+
452
+ // some sort of bad database error: deactivate the plugin and display an error
453
+ if ( is_wp_error( $order_ids ) ) {
454
+ require_once ABSPATH . 'wp-admin/includes/plugin.php';
455
+ deactivate_plugins( 'woocommerce-sequential-order-numbers/woocommerce-sequential-order-numbers.php' ); // hardcode the plugin path so that we can use symlinks in development
456
+
457
+ // Translators: %s - error message(s)
458
+ 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>' ) .
459
+ '<a href="' . admin_url( 'plugins.php' ) . '">' . __( '&laquo; Go Back', 'woocommerce-sequential-order-numbers' ) . '</a>' );
460
+ }
461
+
462
+
463
+ if ( is_array( $order_ids ) ) {
464
+
465
+ foreach( $order_ids as $order_id ) {
466
+
467
+ if ( '' === get_post_meta( $order_id, '_order_number', true ) ) {
468
+ add_post_meta( $order_id, '_order_number', $order_id );
469
+ }
470
+ }
471
+ }
472
+
473
+ // increment offset
474
+ $offset += $posts_per_page;
475
+ // and keep track of how far we made it in case we hit a script timeout
476
+ update_option( 'wc_sequential_order_numbers_install_offset', $offset );
477
+
478
+ } while ( count( $order_ids ) === $posts_per_page ); // while full set of results returned (meaning there may be more results still to retrieve)
479
+ }
480
+
481
+ if ( $installed_version !== WC_Seq_Order_Number::VERSION ) {
482
+ $this->upgrade( $installed_version );
483
+
484
+ // new version number
485
+ update_option( WC_Seq_Order_Number::VERSION_OPTION_NAME, WC_Seq_Order_Number::VERSION );
486
+ }
487
+ }
488
+
489
+
490
+ /**
491
+ * Run when plugin version number changes
492
+ */
493
+ private function upgrade( $installed_version ) {
494
+ // upgrade code goes here
495
+ }
496
+
497
+
498
+ }
i18n/languages/woocommerce-sequential-order-numbers.pot CHANGED
@@ -2,10 +2,10 @@
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"
@@ -13,6 +13,19 @@ msgstr ""
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."
@@ -23,7 +36,7 @@ msgstr ""
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,17 +44,6 @@ 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
-
45
  #. Plugin Name of the plugin/theme
46
  msgid "WooCommerce Sequential Order Numbers"
47
  msgstr ""
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.1\n"
6
  "Report-Msgid-Bugs-To: "
7
  "https://woocommerce.com/my-account/marketplace-ticket-form/\n"
8
+ "POT-Creation-Date: 2019-10-03 04:04:55+00:00\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=utf-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
13
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
  "Language-Team: LANGUAGE <LL@li.org>\n"
15
 
16
+ #: build/woocommerce-sequential-order-numbers.php:458
17
+ #: woocommerce-sequential-order-numbers.php:529
18
+ #. Translators: %s - error message(s)
19
+ msgid ""
20
+ "Error activating and installing <strong>WooCommerce Sequential Order "
21
+ "Numbers</strong>: %s"
22
+ msgstr ""
23
+
24
+ #: build/woocommerce-sequential-order-numbers.php:459
25
+ #: woocommerce-sequential-order-numbers.php:530
26
+ msgid "&laquo; Go Back"
27
+ msgstr ""
28
+
29
  #: woocommerce-sequential-order-numbers.php:68
30
  #. translators: Placeholders: %s - plugin name
31
  msgid "You cannot clone instances of %s."
36
  msgid "You cannot unserialize instances of %s."
37
  msgstr ""
38
 
39
+ #: woocommerce-sequential-order-numbers.php:487
40
  #. translators: Placeholders: %1$s - plugin name; %2$s - WooCommerce version;
41
  #. %3$s, %5$s - <a> tags; %4$s - </a> tag
42
  msgid ""
44
  "%3$supdate WooCommerce%4$s or run the %5$sWooCommerce database upgrade%4$s."
45
  msgstr ""
46
 
 
 
 
 
 
 
 
 
 
 
 
47
  #. Plugin Name of the plugin/theme
48
  msgid "WooCommerce Sequential Order Numbers"
49
  msgstr ""
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: 5.2.2
6
- Stable tag: 1.9.0
7
 
8
  This plugin extends WooCommerce by setting sequential order numbers for new orders.
9
 
@@ -101,6 +101,9 @@ $order_number = $order->get_order_number();
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
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.3
6
+ Stable tag: 1.9.1
7
 
8
  This plugin extends WooCommerce by setting sequential order numbers for new orders.
9
 
101
 
102
  == Changelog ==
103
 
104
+ = 2019.10.03 - version 1.9.1 =
105
+ * Fix - Fix order number filter in WooCommerce Admin Downloads Analytics
106
+
107
  = 2019.08.15 - version 1.9.0 =
108
  * Misc - Add support for WooCommerce 3.7
109
  * Misc - Remove support for WooCommerce 2.6
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.9.0
9
  * Text Domain: woocommerce-sequential-order-numbers
10
  * Domain Path: /i18n/languages/
11
  *
@@ -33,7 +33,7 @@ class WC_Seq_Order_Number {
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';
@@ -110,7 +110,8 @@ class WC_Seq_Order_Number {
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
 
5
  * Description: Provides sequential order numbers for WooCommerce orders
6
  * Author: SkyVerge
7
  * Author URI: http://www.skyverge.com
8
+ * Version: 1.9.1
9
  * Text Domain: woocommerce-sequential-order-numbers
10
  * Domain Path: /i18n/languages/
11
  *
33
 
34
 
35
  /** version number */
36
+ const VERSION = '1.9.1';
37
 
38
  /** minimum required wc version */
39
  const MINIMUM_WC_VERSION = '3.0.9';
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( 'Automattic\WooCommerce\Admin\Install', false ) ||
114
+ class_exists( 'WC_Admin_Install', false ) ) {
115
  add_filter( 'woocommerce_rest_orders_prepare_object_query', array( $this, 'wc_admin_order_number_api_param' ), 10, 2 );
116
  }
117