Skip to content

Commit 9d911a3

Browse files
committed
woocommmerce connector test updated.
1 parent bf53c45 commit 9d911a3

File tree

2 files changed

+378
-28
lines changed

2 files changed

+378
-28
lines changed

connectors/class-connector-woocommerce.php

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ public function register() {
109109
$this->get_woocommerce_settings_fields();
110110
}
111111

112+
/**
113+
* Unregister connection callbacks
114+
*/
115+
public function unregister() {
116+
parent::unregister();
117+
118+
remove_filter( 'wp_stream_posts_exclude_post_types', array( $this, 'exclude_order_post_types' ) );
119+
remove_action( 'wp_stream_comments_exclude_comment_types', array( $this, 'exclude_order_comment_types' ) );
120+
}
121+
112122
/**
113123
* Check if plugin dependencies are satisfied and add an admin notice if not
114124
*
@@ -327,6 +337,13 @@ public function exclude_order_comment_types( $comment_types ) {
327337
return $comment_types;
328338
}
329339

340+
/**
341+
* Clears logged order
342+
*/
343+
public function flush_logged_order() {
344+
$this->order_update_logged = false;
345+
}
346+
330347
/**
331348
* Log Order major status changes ( creating / updating / trashing )
332349
*
@@ -337,6 +354,7 @@ public function exclude_order_comment_types( $comment_types ) {
337354
* @param \WP_Post $post Post object.
338355
*/
339356
public function callback_transition_post_status( $new, $old, $post ) {
357+
340358
// Only track orders.
341359
if ( 'shop_order' !== $post->post_type ) {
342360
return;
@@ -357,9 +375,10 @@ public function callback_transition_post_status( $new, $old, $post ) {
357375
return;
358376
}
359377

360-
if ( in_array( $new, array( 'auto-draft', 'draft', 'inherit' ), true ) ) {
378+
$start_statuses = array( 'auto-draft', 'inherit', 'new' );
379+
if ( in_array( $new, $start_statuses, true ) ) {
361380
return;
362-
} elseif ( 'auto-draft' === $old && 'publish' === $new ) {
381+
} elseif ( in_array( $old, $start_statuses, true ) && ! in_array( $new, $start_statuses, true ) ) {
363382
/* translators: %s: an order title (e.g. "Order #42") */
364383
$message = esc_html_x(
365384
'%s created',
@@ -375,7 +394,7 @@ public function callback_transition_post_status( $new, $old, $post ) {
375394
'stream'
376395
);
377396
$action = 'trashed';
378-
} elseif ( 'trash' === $old && 'publish' === $new ) {
397+
} elseif ( 'trash' === $old && ! in_array( $new, $start_statuses, true ) ) {
379398
/* translators: %s: an order title (e.g. "Order #42") */
380399
$message = esc_html_x(
381400
'%s restored from the trash',
@@ -390,10 +409,7 @@ public function callback_transition_post_status( $new, $old, $post ) {
390409
'Order title',
391410
'stream'
392411
);
393-
}
394-
395-
if ( empty( $action ) ) {
396-
$action = 'updated';
412+
$action = 'updated';
397413
}
398414

399415
$order = new \WC_Order( $post->ID );
@@ -468,6 +484,7 @@ public function callback_deleted_post( $post_id ) {
468484
* @param string $new New status.
469485
*/
470486
public function callback_woocommerce_order_status_changed( $order_id, $old, $new ) {
487+
471488
// Don't track customer actions.
472489
if ( ! is_admin() ) {
473490
return;
@@ -488,19 +505,21 @@ public function callback_woocommerce_order_status_changed( $order_id, $old, $new
488505
$old_status_name = $old_status->name;
489506
}
490507

491-
/* translators: %1$s: an order title, %2$s: order status, %3$s: another order status (e.g. "Order #42", "processing", "complete") */
492-
$message = esc_html_x(
493-
'%1$s status changed from %2$s to %3$s',
494-
'1. Order title, 2. Old status, 3. New status',
495-
'stream'
508+
$order = new \WC_Order( $order_id );
509+
$order_title = sprintf(
510+
/* translators: %d: Order number */
511+
__( 'Order number %d', 'stream' ),
512+
$order->get_order_number()
496513
);
497-
498-
$order = new \WC_Order( $order_id );
499-
$order_title = esc_html__( 'Order number', 'stream' ) . ' ' . esc_html( $order->get_order_number() );
500514
$order_type_name = esc_html__( 'order', 'stream' );
501515

502516
$this->log(
503-
$message,
517+
/* translators: %1$s: an order title, %2$s: order status, %3$s: another order status (e.g. "Order #42", "processing", "complete") */
518+
esc_html_x(
519+
'%1$s status changed from %2$s to %3$s',
520+
'1. Order title, 2. Old status, 3. New status',
521+
'stream'
522+
),
504523
array(
505524
'post_title' => $order_title,
506525
'old_status_name' => $old_status_name,

0 commit comments

Comments
 (0)