Skip to content

Commit

Permalink
Merge pull request #851 from jamesgol/woo_order_status
Browse files Browse the repository at this point in the history
Fix order status log for WooCommerce >= 2.2
  • Loading branch information
Luke Carbis committed Jul 27, 2016
2 parents 030299e + 531d073 commit ed02eda
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions connectors/class-connector-woocommerce.php
Expand Up @@ -54,6 +54,8 @@ class Connector_Woocommerce extends Connector {

private $settings = array();

private $plugin_version = null;

public function register() {
parent::register();

Expand All @@ -72,6 +74,7 @@ public function is_dependency_satisfied() {
global $woocommerce;

if ( class_exists( 'WooCommerce' ) && version_compare( $woocommerce->version, self::PLUGIN_MIN_VERSION, '>=' ) ) {
$this->plugin_version = $woocommerce->version;
return true;
}

Expand Down Expand Up @@ -413,14 +416,21 @@ public function callback_woocommerce_order_status_changed( $order_id, $old, $new
return;
}

$old_status = wp_stream_is_vip() ? wpcom_vip_get_term_by( 'slug', $old, 'shop_order_status' ) : get_term_by( 'slug', $old, 'shop_order_status' );
$new_status = wp_stream_is_vip() ? wpcom_vip_get_term_by( 'slug', $new, 'shop_order_status' ) : get_term_by( 'slug', $new, 'shop_order_status' );

// Don't track new statuses
if ( ! $old_status ) {
if ( empty( $old ) ) {
return;
}

if ( version_compare( $this->plugin_version, '2.2', '>=' ) ) {
$old_status_name = strtolower( wc_get_order_status_name( $old ) );
$new_status_name = strtolower( wc_get_order_status_name( $new ) );
} else {
$old_status = wp_stream_is_vip() ? wpcom_vip_get_term_by( 'slug', $old, 'shop_order_status' ) : get_term_by( 'slug', $old, 'shop_order_status' );
$new_status = wp_stream_is_vip() ? wpcom_vip_get_term_by( 'slug', $new, 'shop_order_status' ) : get_term_by( 'slug', $new, 'shop_order_status' );
$new_status_name = strtolower( $new_status->name );
$old_status_name = strtolower( $old_status->name );
}

$message = esc_html_x(
'%1$s status changed from %2$s to %3$s',
'1. Order title, 2. Old status, 3. New status',
Expand All @@ -430,8 +440,6 @@ public function callback_woocommerce_order_status_changed( $order_id, $old, $new
$order = new \WC_Order( $order_id );
$order_title = esc_html__( 'Order number', 'stream' ) . ' ' . esc_html( $order->get_order_number() );
$order_type_name = esc_html__( 'order', 'stream' );
$new_status_name = strtolower( $new_status->name );
$old_status_name = strtolower( $old_status->name );

$this->log(
$message,
Expand Down

0 comments on commit ed02eda

Please sign in to comment.