Version Description
- 2014.09.02
- Misc - WooCommerce 2.2 compatibility
Download this release
Release Info
Developer | SkyVerge |
Plugin | WooCommerce Sequential Order Numbers |
Version | 1.3.2 |
Comparing to | |
See all releases |
Code changes from version 1.3.1 to 1.3.2
- assets/icon-128x128.png +0 -0
- assets/icon-256x256.png +0 -0
- readme.txt +6 -2
- woocommerce-sequential-order-numbers.php +162 -21
assets/icon-128x128.png
ADDED
Binary file
|
assets/icon-256x256.png
ADDED
Binary file
|
readme.txt
CHANGED
@@ -1,7 +1,8 @@
|
|
1 |
=== WooCommerce Sequential Order Numbers ===
|
2 |
Contributors: SkyVerge
|
3 |
Tags: woocommerce, order number
|
4 |
-
Stable tag: 1.3.
|
|
|
5 |
|
6 |
This plugin extends the WooCommerce e-commerce plugin by setting sequential order numbers for new orders.
|
7 |
|
@@ -11,7 +12,7 @@ This plugin extends the WooCommerce e-commerce plugin by setting sequential orde
|
|
11 |
|
12 |
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, available from the [WooThemes Store](http://www.woothemes.com/products/sequential-order-numbers-pro/)
|
13 |
|
14 |
-
This plugin requires WooCommerce 1
|
15 |
|
16 |
= Feedback =
|
17 |
* We are open to your suggestions and feedback - Thank you for using or trying out one of our plugins!
|
@@ -39,6 +40,9 @@ This free version does not have that functionality, but now you can with the pre
|
|
39 |
|
40 |
== Changelog ==
|
41 |
|
|
|
|
|
|
|
42 |
= 1.3.1 - 2014.01.22 =
|
43 |
* Misc - WooCommerce 2.1 compatibility
|
44 |
|
1 |
=== WooCommerce Sequential Order Numbers ===
|
2 |
Contributors: SkyVerge
|
3 |
Tags: woocommerce, order number
|
4 |
+
Stable tag: 1.3.2
|
5 |
+
Requires WooCommerce at least: 2.1
|
6 |
|
7 |
This plugin extends the WooCommerce e-commerce plugin by setting sequential order numbers for new orders.
|
8 |
|
12 |
|
13 |
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, available from the [WooThemes Store](http://www.woothemes.com/products/sequential-order-numbers-pro/)
|
14 |
|
15 |
+
This plugin requires WooCommerce 2.1 or greater.
|
16 |
|
17 |
= Feedback =
|
18 |
* We are open to your suggestions and feedback - Thank you for using or trying out one of our plugins!
|
40 |
|
41 |
== Changelog ==
|
42 |
|
43 |
+
= 1.3.2 - 2014.09.02
|
44 |
+
* Misc - WooCommerce 2.2 compatibility
|
45 |
+
|
46 |
= 1.3.1 - 2014.01.22 =
|
47 |
* Misc - WooCommerce 2.1 compatibility
|
48 |
|
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 |
*
|
@@ -36,13 +36,40 @@ $GLOBALS['wc_seq_order_number'] = new WC_Seq_Order_Number();
|
|
36 |
class WC_Seq_Order_Number {
|
37 |
|
38 |
/** version number */
|
39 |
-
const VERSION = "1.3.
|
40 |
|
41 |
/** version option name */
|
42 |
const VERSION_OPTION_NAME = "woocommerce_seq_order_number_db_version";
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
public function __construct() {
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
// set the custom order number on the new order. we hook into wp_insert_post for orders which are created
|
47 |
// from the frontend, and we hook into woocommerce_process_shop_order_meta for admin-created orders
|
48 |
add_action( 'wp_insert_post', array( $this, 'set_sequential_order_number' ), 10, 2 );
|
@@ -93,6 +120,8 @@ class WC_Seq_Order_Number {
|
|
93 |
'fields' => 'ids',
|
94 |
);
|
95 |
|
|
|
|
|
96 |
list( $order_id ) = get_posts( $query_args );
|
97 |
|
98 |
// order was found
|
@@ -101,8 +130,8 @@ class WC_Seq_Order_Number {
|
|
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 =
|
105 |
-
if ( $
|
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 |
}
|
@@ -153,8 +182,8 @@ class WC_Seq_Order_Number {
|
|
153 |
*/
|
154 |
public function get_order_number( $order_number, $order ) {
|
155 |
|
156 |
-
if ( $
|
157 |
-
return '#' . $
|
158 |
}
|
159 |
|
160 |
return $order_number;
|
@@ -277,36 +306,148 @@ class WC_Seq_Order_Number {
|
|
277 |
}
|
278 |
|
279 |
|
|
|
|
|
|
|
280 |
/**
|
281 |
-
*
|
282 |
*
|
283 |
-
*
|
284 |
-
*
|
285 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
286 |
*/
|
287 |
-
|
|
|
|
|
|
|
|
|
288 |
|
289 |
-
if ( version_compare( $this->get_wc_version(), '2.0.20', '>' ) ) {
|
290 |
-
return isset( $order->$name ) ? $order->$name : '';
|
291 |
} else {
|
292 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
293 |
}
|
|
|
|
|
294 |
}
|
295 |
|
296 |
|
297 |
/**
|
298 |
-
*
|
299 |
*
|
300 |
-
* @since 1.3.
|
301 |
* @return string woocommerce version number or null
|
302 |
*/
|
303 |
-
private function get_wc_version() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
304 |
|
305 |
-
|
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 |
|
5 |
* Description: Provides sequential order numbers for WooCommerce orders
|
6 |
* Author: SkyVerge
|
7 |
* Author URI: http://www.skyverge.com
|
8 |
+
* Version: 1.3.2
|
9 |
*
|
10 |
* Copyright: (c) 2012-2013 SkyVerge, Inc. (info@skyverge.com)
|
11 |
*
|
36 |
class WC_Seq_Order_Number {
|
37 |
|
38 |
/** version number */
|
39 |
+
const VERSION = "1.3.2";
|
40 |
|
41 |
/** version option name */
|
42 |
const VERSION_OPTION_NAME = "woocommerce_seq_order_number_db_version";
|
43 |
|
44 |
+
/** minimum required wc version */
|
45 |
+
const MINIMUM_WC_VERSION = '2.1';
|
46 |
+
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Construct the plugin
|
50 |
+
*
|
51 |
+
* @since 1.3.2
|
52 |
+
*/
|
53 |
public function __construct() {
|
54 |
|
55 |
+
add_action( 'plugins_loaded', array( $this, 'initialize' ) );
|
56 |
+
|
57 |
+
}
|
58 |
+
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Initialize the plugin, bailing if any required conditions are not met,
|
62 |
+
* including minimum WooCommerce version
|
63 |
+
*
|
64 |
+
* @since 1.3.2
|
65 |
+
*/
|
66 |
+
public function initialize() {
|
67 |
+
|
68 |
+
if ( ! $this->minimum_wc_version_met() ) {
|
69 |
+
// halt functionality
|
70 |
+
return;
|
71 |
+
}
|
72 |
+
|
73 |
// set the custom order number on the new order. we hook into wp_insert_post for orders which are created
|
74 |
// from the frontend, and we hook into woocommerce_process_shop_order_meta for admin-created orders
|
75 |
add_action( 'wp_insert_post', array( $this, 'set_sequential_order_number' ), 10, 2 );
|
120 |
'fields' => 'ids',
|
121 |
);
|
122 |
|
123 |
+
$query_args = self::backport_order_status_query_args( $query_args );
|
124 |
+
|
125 |
list( $order_id ) = get_posts( $query_args );
|
126 |
|
127 |
// order was found
|
130 |
}
|
131 |
|
132 |
// if we didn't find the order, then it may be that this plugin was disabled and an order was placed in the interim
|
133 |
+
$order = self::wc_get_order( $order_number );
|
134 |
+
if ( $order->order_number ) {
|
135 |
// _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
|
136 |
return 0;
|
137 |
}
|
182 |
*/
|
183 |
public function get_order_number( $order_number, $order ) {
|
184 |
|
185 |
+
if ( $order->order_number ) {
|
186 |
+
return '#' . $order->order_number;
|
187 |
}
|
188 |
|
189 |
return $order_number;
|
306 |
}
|
307 |
|
308 |
|
309 |
+
/** Compatibility Methods ******************************************************/
|
310 |
+
|
311 |
+
|
312 |
/**
|
313 |
+
* Get the WC Order instance for a given order ID or order post
|
314 |
*
|
315 |
+
* Introduced in WC 2.2 as part of the Order Factory so the 2.1 version is
|
316 |
+
* not an exact replacement.
|
317 |
+
*
|
318 |
+
* If no param is passed, it will use the global post. Otherwise pass an
|
319 |
+
* the order post ID or post object.
|
320 |
+
*
|
321 |
+
* @since 1.3.2
|
322 |
+
* @param bool|int|string|\WP_Post $the_order
|
323 |
+
* @return bool|\WC_Order
|
324 |
*/
|
325 |
+
public static function wc_get_order( $the_order = false ) {
|
326 |
+
|
327 |
+
if ( self::is_wc_version_gte_2_2() ) {
|
328 |
+
|
329 |
+
return wc_get_order( $the_order );
|
330 |
|
|
|
|
|
331 |
} else {
|
332 |
+
|
333 |
+
global $post;
|
334 |
+
|
335 |
+
if ( false === $the_order ) {
|
336 |
+
|
337 |
+
$order_id = $post->ID;
|
338 |
+
|
339 |
+
} elseif ( $the_order instanceof WP_Post ) {
|
340 |
+
|
341 |
+
$order_id = $the_order->ID;
|
342 |
+
|
343 |
+
} elseif ( is_numeric( $the_order ) ) {
|
344 |
+
|
345 |
+
$order_id = $the_order;
|
346 |
+
}
|
347 |
+
|
348 |
+
return new WC_Order( $order_id );
|
349 |
+
}
|
350 |
+
}
|
351 |
+
|
352 |
+
|
353 |
+
/**
|
354 |
+
* Transparently backport the `post_status` WP Query arg used by WC 2.2
|
355 |
+
* for order statuses to the `shop_order_status` taxonomy query arg used by
|
356 |
+
* WC 2.1
|
357 |
+
*
|
358 |
+
* @since 1.3.2
|
359 |
+
* @param array $args WP_Query args
|
360 |
+
* @return array
|
361 |
+
*/
|
362 |
+
public static function backport_order_status_query_args( $args ) {
|
363 |
+
|
364 |
+
if ( ! self::is_wc_version_gte_2_2() ) {
|
365 |
+
|
366 |
+
// convert post status arg to taxonomy query compatible with WC 2.1
|
367 |
+
if ( ! empty( $args['post_status'] ) ) {
|
368 |
+
|
369 |
+
$order_statuses = array();
|
370 |
+
|
371 |
+
foreach ( (array) $args['post_status'] as $order_status ) {
|
372 |
+
|
373 |
+
$order_statuses[] = str_replace( 'wc-', '', $order_status );
|
374 |
+
}
|
375 |
+
|
376 |
+
$args['post_status'] = 'publish';
|
377 |
+
|
378 |
+
$tax_query = array(
|
379 |
+
array(
|
380 |
+
'taxonomy' => 'shop_order_status',
|
381 |
+
'field' => 'slug',
|
382 |
+
'terms' => $order_statuses,
|
383 |
+
'operator' => 'IN',
|
384 |
+
)
|
385 |
+
);
|
386 |
+
|
387 |
+
$args['tax_query'] = array_merge( ( isset( $args['tax_query'] ) ? $args['tax_query'] : array() ), $tax_query );
|
388 |
+
}
|
389 |
}
|
390 |
+
|
391 |
+
return $args;
|
392 |
}
|
393 |
|
394 |
|
395 |
/**
|
396 |
+
* Helper method to get the version of the currently installed WooCommerce
|
397 |
*
|
398 |
+
* @since 1.3.2
|
399 |
* @return string woocommerce version number or null
|
400 |
*/
|
401 |
+
private static function get_wc_version() {
|
402 |
+
|
403 |
+
return defined( 'WC_VERSION' ) && WC_VERSION ? WC_VERSION : null;
|
404 |
+
}
|
405 |
+
|
406 |
+
|
407 |
+
/**
|
408 |
+
* Returns true if the installed version of WooCommerce is 2.2 or greater
|
409 |
+
*
|
410 |
+
* @since 1.3.2
|
411 |
+
* @return boolean true if the installed version of WooCommerce is 2.2 or greater
|
412 |
+
*/
|
413 |
+
public static function is_wc_version_gte_2_2() {
|
414 |
+
return self::get_wc_version() && version_compare( self::get_wc_version(), '2.2', '>=' );
|
415 |
+
}
|
416 |
+
|
417 |
+
|
418 |
+
/**
|
419 |
+
* Perform a minimum WooCommerce version check
|
420 |
+
*
|
421 |
+
* @since 1.3.2
|
422 |
+
* @return boolean true if the required version is met, false otherwise
|
423 |
+
*/
|
424 |
+
private function minimum_wc_version_met() {
|
425 |
+
|
426 |
+
// if a plugin defines a minimum WC version, render a notice and skip loading the plugin
|
427 |
+
if ( defined( 'self::MINIMUM_WC_VERSION' ) && version_compare( self::get_wc_version(), self::MINIMUM_WC_VERSION, '<' ) ) {
|
428 |
+
if ( is_admin() && ! defined( 'DOING_AJAX' ) && ! has_action( 'admin_notices', array( $this, 'render_update_notices' ) ) ) {
|
429 |
+
add_action( 'admin_notices', array( $this, 'render_update_notices' ) );
|
430 |
+
}
|
431 |
+
return false;
|
432 |
+
}
|
433 |
+
|
434 |
+
return true;
|
435 |
+
}
|
436 |
+
|
437 |
+
|
438 |
+
/**
|
439 |
+
* Render a notice to update WooCommerce if needed
|
440 |
+
*
|
441 |
+
* @since 1.3.2
|
442 |
+
*/
|
443 |
+
public function render_update_notices() {
|
444 |
+
|
445 |
+
echo '<div class="error"><p>The following plugin is inactive because it requires a newer version of WooCommerce:</p><ul>';
|
446 |
+
|
447 |
+
printf( '<li>%s requires WooCommerce %s or newer</li>', 'Sequential Order Numbers', self::MINIMUM_WC_VERSION );
|
448 |
|
449 |
+
echo '</ul><p>Please <a href="' . admin_url( 'update-core.php' ) . '">update WooCommerce »</a></p></div>';
|
|
|
|
|
450 |
|
|
|
451 |
}
|
452 |
|
453 |
|