Skip to content

Commit

Permalink
[#7] Subscriptions: drop deprecated up for order meta query
Browse files Browse the repository at this point in the history
  • Loading branch information
unfulvio committed Feb 4, 2016
1 parent 9893adf commit 39e8617
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "woocommerce-sequential-order-numbers",
"version": "1.6.0",
"version": "1.6.1",
"author": "SkyVerge Team",
"homepage": "http://skyverge.com",
"repository": {
Expand Down
9 changes: 6 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
Contributors: SkyVerge, maxrice, tamarazuk, chasewiseman, nekojira
Tags: woocommerce, order number
Requires at least: 4.0
Tested up to: 4.4.1
Tested up to: 4.4.2
Requires WooCommerce at least: 2.3
Tested WooCommerce up to: 2.5
Stable tag: 1.6.0
Stable tag: 1.6.1

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

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

== Changelog ==

= 1.6.0 - 2015.nn.nn =
= 1.6.1 - 2016.02.04 =
* Misc - WooCommerce Subscriptions: Use new hook wcs_renewal_order_meta_query instead of deprecated woocommerce_subscriptions_renewal_order_meta_query

= 1.6.0 - 2016.01.20 =
* Misc - WooCommerce Subscriptions: Use new filter hook wcs_renewal_order_created instead of deprecated woocommerce_subscriptions_renewal_order_created
* Misc - WooCommerce 2.5 compatibility
* Misc - Dropped WooCommerce 2.2 support
Expand Down
56 changes: 27 additions & 29 deletions woocommerce-sequential-order-numbers.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Provides sequential order numbers for WooCommerce orders
* Author: SkyVerge
* Author URI: http://www.skyverge.com
* Version: 1.6.0
* Version: 1.6.1
* Text Domain: woocommerce-sequential-order-numbers
* Domain Path: /i18n/languages/
*
Expand Down Expand Up @@ -37,11 +37,12 @@

class WC_Seq_Order_Number {


/** version number */
const VERSION = "1.6.0";
const VERSION = '1.6.1';

/** version option name */
const VERSION_OPTION_NAME = "woocommerce_seq_order_number_db_version";
const VERSION_OPTION_NAME = 'woocommerce_seq_order_number_db_version';

/** minimum required wc version */
const MINIMUM_WC_VERSION = '2.3';
Expand Down Expand Up @@ -72,24 +73,24 @@ public function initialize() {
return;
}

// set the custom order number on the new order. we hook into wp_insert_post for orders which are created
// from the frontend, and we hook into woocommerce_process_shop_order_meta for admin-created orders
add_action( 'wp_insert_post', array( $this, 'set_sequential_order_number' ), 10, 2 );
// Set the custom order number on the new order. we hook into wp_insert_post for orders which are created
// from the frontend, and we hook into woocommerce_process_shop_order_meta for admin-created orders
add_action( 'wp_insert_post', array( $this, 'set_sequential_order_number' ), 10, 2 );
add_action( 'woocommerce_process_shop_order_meta', array( $this, 'set_sequential_order_number' ), 10, 2 );

// return our custom order number for display
add_filter( 'woocommerce_order_number', array( $this, 'get_order_number' ), 10, 2 );
add_filter( 'woocommerce_order_number', array( $this, 'get_order_number' ), 10, 2 );

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

// WC Subscriptions support: prevent unnecessary order meta from polluting parent renewal orders, and set order number for subscription orders
add_filter( 'woocommerce_subscriptions_renewal_order_meta_query', array( $this, 'subscriptions_remove_renewal_order_meta' ), 10, 4 );

// WC Subscriptions support
if ( self::is_wc_subscriptions_version_gte_2_0() ) {
add_filter( 'wcs_renewal_order_created', array( $this, 'subscriptions_set_sequential_order_number' ), 10, 2 );
add_filter( 'wcs_renewal_order_meta_query', array( $this, 'subscriptions_remove_renewal_order_meta' ) );
add_filter( 'wcs_renewal_order_created', array( $this, 'subscriptions_set_sequential_order_number' ), 10, 2 );
} else {
add_action( 'woocommerce_subscriptions_renewal_order_created', array( $this, 'subscriptions_set_sequential_order_number' ), 10, 2 );
add_filter( 'woocommerce_subscriptions_renewal_order_meta_query', array( $this, 'subscriptions_remove_renewal_order_meta' ) );
add_action( 'woocommerce_subscriptions_renewal_order_created', array( $this, 'subscriptions_set_sequential_order_number' ), 10, 2 );
}

if ( is_admin() ) {
Expand All @@ -102,7 +103,7 @@ public function initialize() {
}

// Installation
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
if ( is_admin() && ! is_ajax() ) {
$this->install();
}
}
Expand Down Expand Up @@ -166,16 +167,16 @@ public function find_order_by_order_number( $order_number ) {
* Set the _order_number field for the newly created order
*
* @param int $post_id post identifier
* @param object $post post object
* @param WP_Post $post post object
*/
public function set_sequential_order_number( $post_id, $post ) {
global $wpdb;

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

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

if ( "" == $order_number ) {
if ( '' === $order_number ) {

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

if ( 'shop_order' == $typenow ) {
if ( 'shop_order' === $typenow ) {
return $vars;
}

Expand Down Expand Up @@ -319,18 +320,15 @@ public function subscriptions_set_sequential_order_number( $renewal_order, $orig
/**
* Don't copy over order number meta when creating a parent or child renewal order
*
* Prevents unnecessary order meta from polluting parent renewal orders,
* and set order number for subscription orders
*
* @since 1.3
* @param array $order_meta_query query for pulling the metadata
* @param int $original_order_id Post ID of the order being used to purchased the subscription being renewed
* @param int $renewal_order_id Post ID of the order created for renewing the subscription
* @param string $new_order_role The role the renewal order is taking, one of 'parent' or 'child'
* @return string
*/
public function subscriptions_remove_renewal_order_meta( $order_meta_query, $original_order_id, $renewal_order_id, $new_order_role ) {

$order_meta_query .= " AND meta_key NOT IN ( '_order_number' )";

return $order_meta_query;
public function subscriptions_remove_renewal_order_meta( $order_meta_query ) {
return $order_meta_query . " AND meta_key NOT IN ( '_order_number' )";
}


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

if ( is_admin() && ! defined( 'DOING_AJAX' ) && ! has_action( 'admin_notices', array( $this, 'render_update_notices' ) ) ) {
if ( is_admin() && ! is_ajax() && ! has_action( 'admin_notices', array( $this, 'render_update_notices' ) ) ) {

add_action( 'admin_notices', array( $this, 'render_update_notices' ) );
}
Expand Down Expand Up @@ -466,7 +464,7 @@ private function install() {

foreach( $order_ids as $order_id ) {

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

} while ( count( $order_ids ) == $posts_per_page ); // while full set of results returned (meaning there may be more results still to retrieve)
} while ( count( $order_ids ) === $posts_per_page ); // while full set of results returned (meaning there may be more results still to retrieve)
}

if ( $installed_version != WC_Seq_Order_Number::VERSION ) {
if ( $installed_version !== WC_Seq_Order_Number::VERSION ) {
$this->upgrade( $installed_version );

// new version number
Expand Down

0 comments on commit 39e8617

Please sign in to comment.