5
5
* Description: Provides sequential order numbers for WooCommerce orders
6
6
* Author: SkyVerge
7
7
* Author URI: http://www.skyverge.com
8
- * Version: 1.6.0
8
+ * Version: 1.6.1
9
9
* Text Domain: woocommerce-sequential-order-numbers
10
10
* Domain Path: /i18n/languages/
11
11
*
37
37
38
38
class WC_Seq_Order_Number {
39
39
40
+
40
41
/** version number */
41
- const VERSION = " 1.6.0 " ;
42
+ const VERSION = ' 1.6.1 ' ;
42
43
43
44
/** version option name */
44
- const VERSION_OPTION_NAME = " woocommerce_seq_order_number_db_version " ;
45
+ const VERSION_OPTION_NAME = ' woocommerce_seq_order_number_db_version ' ;
45
46
46
47
/** minimum required wc version */
47
48
const MINIMUM_WC_VERSION = '2.3 ' ;
@@ -72,24 +73,24 @@ public function initialize() {
72
73
return ;
73
74
}
74
75
75
- // set the custom order number on the new order. we hook into wp_insert_post for orders which are created
76
- // from the frontend, and we hook into woocommerce_process_shop_order_meta for admin-created orders
77
- add_action ( 'wp_insert_post ' , array ( $ this , 'set_sequential_order_number ' ), 10 , 2 );
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 );
78
79
add_action ( 'woocommerce_process_shop_order_meta ' , array ( $ this , 'set_sequential_order_number ' ), 10 , 2 );
79
80
80
81
// return our custom order number for display
81
- add_filter ( 'woocommerce_order_number ' , array ( $ this , 'get_order_number ' ), 10 , 2 );
82
+ add_filter ( 'woocommerce_order_number ' , array ( $ this , 'get_order_number ' ), 10 , 2 );
82
83
83
84
// order tracking page search by order number
84
85
add_filter ( 'woocommerce_shortcode_order_tracking_order_id ' , array ( $ this , 'find_order_by_order_number ' ) );
85
86
86
- // WC Subscriptions support: prevent unnecessary order meta from polluting parent renewal orders, and set order number for subscription orders
87
- add_filter ( 'woocommerce_subscriptions_renewal_order_meta_query ' , array ( $ this , 'subscriptions_remove_renewal_order_meta ' ), 10 , 4 );
88
-
87
+ // WC Subscriptions support
89
88
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 );
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
91
} else {
92
- add_action ( 'woocommerce_subscriptions_renewal_order_created ' , array ( $ this , 'subscriptions_set_sequential_order_number ' ), 10 , 2 );
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 );
93
94
}
94
95
95
96
if ( is_admin () ) {
@@ -102,7 +103,7 @@ public function initialize() {
102
103
}
103
104
104
105
// Installation
105
- if ( is_admin () && ! defined ( ' DOING_AJAX ' ) ) {
106
+ if ( is_admin () && ! is_ajax ( ) ) {
106
107
$ this ->install ();
107
108
}
108
109
}
@@ -166,16 +167,16 @@ public function find_order_by_order_number( $order_number ) {
166
167
* Set the _order_number field for the newly created order
167
168
*
168
169
* @param int $post_id post identifier
169
- * @param object $post post object
170
+ * @param WP_Post $post post object
170
171
*/
171
172
public function set_sequential_order_number ( $ post_id , $ post ) {
172
173
global $ wpdb ;
173
174
174
- if ( 'shop_order ' == $ post ->post_type && 'auto-draft ' != $ post ->post_status ) {
175
+ if ( 'shop_order ' === $ post ->post_type && 'auto-draft ' != = $ post ->post_status ) {
175
176
176
177
$ order_number = get_post_meta ( $ post_id , '_order_number ' , true );
177
178
178
- if ( "" == $ order_number ) {
179
+ if ( '' = == $ order_number ) {
179
180
180
181
// attempt the query up to 3 times for a much higher success rate if it fails (due to Deadlock)
181
182
$ success = false ;
@@ -226,7 +227,7 @@ public function get_order_number( $order_number, $order ) {
226
227
public function woocommerce_custom_shop_order_orderby ( $ vars ) {
227
228
global $ typenow , $ wp_query ;
228
229
229
- if ( 'shop_order ' == $ typenow ) {
230
+ if ( 'shop_order ' === $ typenow ) {
230
231
return $ vars ;
231
232
}
232
233
@@ -319,18 +320,15 @@ public function subscriptions_set_sequential_order_number( $renewal_order, $orig
319
320
/**
320
321
* Don't copy over order number meta when creating a parent or child renewal order
321
322
*
323
+ * Prevents unnecessary order meta from polluting parent renewal orders,
324
+ * and set order number for subscription orders
325
+ *
322
326
* @since 1.3
323
327
* @param array $order_meta_query query for pulling the metadata
324
- * @param int $original_order_id Post ID of the order being used to purchased the subscription being renewed
325
- * @param int $renewal_order_id Post ID of the order created for renewing the subscription
326
- * @param string $new_order_role The role the renewal order is taking, one of 'parent' or 'child'
327
328
* @return string
328
329
*/
329
- public function subscriptions_remove_renewal_order_meta ( $ order_meta_query , $ original_order_id , $ renewal_order_id , $ new_order_role ) {
330
-
331
- $ order_meta_query .= " AND meta_key NOT IN ( '_order_number' ) " ;
332
-
333
- return $ order_meta_query ;
330
+ public function subscriptions_remove_renewal_order_meta ( $ order_meta_query ) {
331
+ return $ order_meta_query . " AND meta_key NOT IN ( '_order_number' ) " ;
334
332
}
335
333
336
334
@@ -402,7 +400,7 @@ private function minimum_wc_version_met() {
402
400
// if a plugin defines a minimum WC version, render a notice and skip loading the plugin
403
401
if ( defined ( 'self::MINIMUM_WC_VERSION ' ) && version_compare ( self ::get_wc_version (), self ::MINIMUM_WC_VERSION , '< ' ) ) {
404
402
405
- if ( is_admin () && ! defined ( ' DOING_AJAX ' ) && ! has_action ( 'admin_notices ' , array ( $ this , 'render_update_notices ' ) ) ) {
403
+ if ( is_admin () && ! is_ajax ( ) && ! has_action ( 'admin_notices ' , array ( $ this , 'render_update_notices ' ) ) ) {
406
404
407
405
add_action ( 'admin_notices ' , array ( $ this , 'render_update_notices ' ) );
408
406
}
@@ -466,7 +464,7 @@ private function install() {
466
464
467
465
foreach ( $ order_ids as $ order_id ) {
468
466
469
- if ( '' == get_post_meta ( $ order_id , '_order_number ' , true ) ) {
467
+ if ( '' === get_post_meta ( $ order_id , '_order_number ' , true ) ) {
470
468
add_post_meta ( $ order_id , '_order_number ' , $ order_id );
471
469
}
472
470
}
@@ -477,10 +475,10 @@ private function install() {
477
475
// and keep track of how far we made it in case we hit a script timeout
478
476
update_option ( 'wc_sequential_order_numbers_install_offset ' , $ offset );
479
477
480
- } while ( count ( $ order_ids ) == $ posts_per_page ); // while full set of results returned (meaning there may be more results still to retrieve)
478
+ } while ( count ( $ order_ids ) === $ posts_per_page ); // while full set of results returned (meaning there may be more results still to retrieve)
481
479
}
482
480
483
- if ( $ installed_version != WC_Seq_Order_Number::VERSION ) {
481
+ if ( $ installed_version !== WC_Seq_Order_Number::VERSION ) {
484
482
$ this ->upgrade ( $ installed_version );
485
483
486
484
// new version number
0 commit comments