Skip to content

Commit 39e8617

Browse files
committed
[#7] Subscriptions: drop deprecated up for order meta query
1 parent 9893adf commit 39e8617

File tree

3 files changed

+34
-33
lines changed

3 files changed

+34
-33
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "woocommerce-sequential-order-numbers",
3-
"version": "1.6.0",
3+
"version": "1.6.1",
44
"author": "SkyVerge Team",
55
"homepage": "http://skyverge.com",
66
"repository": {

readme.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
Contributors: SkyVerge, maxrice, tamarazuk, chasewiseman, nekojira
33
Tags: woocommerce, order number
44
Requires at least: 4.0
5-
Tested up to: 4.4.1
5+
Tested up to: 4.4.2
66
Requires WooCommerce at least: 2.3
77
Tested WooCommerce up to: 2.5
8-
Stable tag: 1.6.0
8+
Stable tag: 1.6.1
99

1010
This plugin extends WooCommerce by setting sequential order numbers for new orders.
1111

@@ -54,7 +54,10 @@ This free version does not have that functionality, but it's included in the pre
5454

5555
== Changelog ==
5656

57-
= 1.6.0 - 2015.nn.nn =
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 =
5861
* Misc - WooCommerce Subscriptions: Use new filter hook wcs_renewal_order_created instead of deprecated woocommerce_subscriptions_renewal_order_created
5962
* Misc - WooCommerce 2.5 compatibility
6063
* Misc - Dropped WooCommerce 2.2 support

woocommerce-sequential-order-numbers.php

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Description: Provides sequential order numbers for WooCommerce orders
66
* Author: SkyVerge
77
* Author URI: http://www.skyverge.com
8-
* Version: 1.6.0
8+
* Version: 1.6.1
99
* Text Domain: woocommerce-sequential-order-numbers
1010
* Domain Path: /i18n/languages/
1111
*
@@ -37,11 +37,12 @@
3737

3838
class WC_Seq_Order_Number {
3939

40+
4041
/** version number */
41-
const VERSION = "1.6.0";
42+
const VERSION = '1.6.1';
4243

4344
/** 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';
4546

4647
/** minimum required wc version */
4748
const MINIMUM_WC_VERSION = '2.3';
@@ -72,24 +73,24 @@ public function initialize() {
7273
return;
7374
}
7475

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 );
7879
add_action( 'woocommerce_process_shop_order_meta', array( $this, 'set_sequential_order_number' ), 10, 2 );
7980

8081
// 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 );
8283

8384
// order tracking page search by order number
8485
add_filter( 'woocommerce_shortcode_order_tracking_order_id', array( $this, 'find_order_by_order_number' ) );
8586

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
8988
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 );
9191
} 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 );
9394
}
9495

9596
if ( is_admin() ) {
@@ -102,7 +103,7 @@ public function initialize() {
102103
}
103104

104105
// Installation
105-
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
106+
if ( is_admin() && ! is_ajax() ) {
106107
$this->install();
107108
}
108109
}
@@ -166,16 +167,16 @@ public function find_order_by_order_number( $order_number ) {
166167
* Set the _order_number field for the newly created order
167168
*
168169
* @param int $post_id post identifier
169-
* @param object $post post object
170+
* @param WP_Post $post post object
170171
*/
171172
public function set_sequential_order_number( $post_id, $post ) {
172173
global $wpdb;
173174

174-
if ( 'shop_order' == $post->post_type && 'auto-draft' != $post->post_status ) {
175+
if ( 'shop_order' === $post->post_type && 'auto-draft' !== $post->post_status ) {
175176

176177
$order_number = get_post_meta( $post_id, '_order_number', true );
177178

178-
if ( "" == $order_number ) {
179+
if ( '' === $order_number ) {
179180

180181
// attempt the query up to 3 times for a much higher success rate if it fails (due to Deadlock)
181182
$success = false;
@@ -226,7 +227,7 @@ public function get_order_number( $order_number, $order ) {
226227
public function woocommerce_custom_shop_order_orderby( $vars ) {
227228
global $typenow, $wp_query;
228229

229-
if ( 'shop_order' == $typenow ) {
230+
if ( 'shop_order' === $typenow ) {
230231
return $vars;
231232
}
232233

@@ -319,18 +320,15 @@ public function subscriptions_set_sequential_order_number( $renewal_order, $orig
319320
/**
320321
* Don't copy over order number meta when creating a parent or child renewal order
321322
*
323+
* Prevents unnecessary order meta from polluting parent renewal orders,
324+
* and set order number for subscription orders
325+
*
322326
* @since 1.3
323327
* @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'
327328
* @return string
328329
*/
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' )";
334332
}
335333

336334

@@ -402,7 +400,7 @@ private function minimum_wc_version_met() {
402400
// if a plugin defines a minimum WC version, render a notice and skip loading the plugin
403401
if ( defined( 'self::MINIMUM_WC_VERSION' ) && version_compare( self::get_wc_version(), self::MINIMUM_WC_VERSION, '<' ) ) {
404402

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' ) ) ) {
406404

407405
add_action( 'admin_notices', array( $this, 'render_update_notices' ) );
408406
}
@@ -466,7 +464,7 @@ private function install() {
466464

467465
foreach( $order_ids as $order_id ) {
468466

469-
if ( '' == get_post_meta( $order_id, '_order_number', true ) ) {
467+
if ( '' === get_post_meta( $order_id, '_order_number', true ) ) {
470468
add_post_meta( $order_id, '_order_number', $order_id );
471469
}
472470
}
@@ -477,10 +475,10 @@ private function install() {
477475
// and keep track of how far we made it in case we hit a script timeout
478476
update_option( 'wc_sequential_order_numbers_install_offset', $offset );
479477

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)
481479
}
482480

483-
if ( $installed_version != WC_Seq_Order_Number::VERSION ) {
481+
if ( $installed_version !== WC_Seq_Order_Number::VERSION ) {
484482
$this->upgrade( $installed_version );
485483

486484
// new version number

0 commit comments

Comments
 (0)