@@ -109,6 +109,16 @@ public function register() {
109
109
$ this ->get_woocommerce_settings_fields ();
110
110
}
111
111
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
+
112
122
/**
113
123
* Check if plugin dependencies are satisfied and add an admin notice if not
114
124
*
@@ -327,6 +337,13 @@ public function exclude_order_comment_types( $comment_types ) {
327
337
return $ comment_types ;
328
338
}
329
339
340
+ /**
341
+ * Clears logged order
342
+ */
343
+ public function flush_logged_order () {
344
+ $ this ->order_update_logged = false ;
345
+ }
346
+
330
347
/**
331
348
* Log Order major status changes ( creating / updating / trashing )
332
349
*
@@ -337,6 +354,7 @@ public function exclude_order_comment_types( $comment_types ) {
337
354
* @param \WP_Post $post Post object.
338
355
*/
339
356
public function callback_transition_post_status ( $ new , $ old , $ post ) {
357
+
340
358
// Only track orders.
341
359
if ( 'shop_order ' !== $ post ->post_type ) {
342
360
return ;
@@ -357,9 +375,10 @@ public function callback_transition_post_status( $new, $old, $post ) {
357
375
return ;
358
376
}
359
377
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 ) ) {
361
380
return ;
362
- } elseif ( ' auto-draft ' === $ old && ' publish ' === $ new ) {
381
+ } elseif ( in_array ( $ old, $ start_statuses , true ) && ! in_array ( $ new, $ start_statuses , true ) ) {
363
382
/* translators: %s: an order title (e.g. "Order #42") */
364
383
$ message = esc_html_x (
365
384
'%s created ' ,
@@ -375,7 +394,7 @@ public function callback_transition_post_status( $new, $old, $post ) {
375
394
'stream '
376
395
);
377
396
$ action = 'trashed ' ;
378
- } elseif ( 'trash ' === $ old && ' publish ' === $ new ) {
397
+ } elseif ( 'trash ' === $ old && ! in_array ( $ new, $ start_statuses , true ) ) {
379
398
/* translators: %s: an order title (e.g. "Order #42") */
380
399
$ message = esc_html_x (
381
400
'%s restored from the trash ' ,
@@ -390,10 +409,7 @@ public function callback_transition_post_status( $new, $old, $post ) {
390
409
'Order title ' ,
391
410
'stream '
392
411
);
393
- }
394
-
395
- if ( empty ( $ action ) ) {
396
- $ action = 'updated ' ;
412
+ $ action = 'updated ' ;
397
413
}
398
414
399
415
$ order = new \WC_Order ( $ post ->ID );
@@ -468,6 +484,7 @@ public function callback_deleted_post( $post_id ) {
468
484
* @param string $new New status.
469
485
*/
470
486
public function callback_woocommerce_order_status_changed ( $ order_id , $ old , $ new ) {
487
+
471
488
// Don't track customer actions.
472
489
if ( ! is_admin () ) {
473
490
return ;
@@ -488,19 +505,21 @@ public function callback_woocommerce_order_status_changed( $order_id, $old, $new
488
505
$ old_status_name = $ old_status ->name ;
489
506
}
490
507
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 ()
496
513
);
497
-
498
- $ order = new \WC_Order ( $ order_id );
499
- $ order_title = esc_html__ ( 'Order number ' , 'stream ' ) . ' ' . esc_html ( $ order ->get_order_number () );
500
514
$ order_type_name = esc_html__ ( 'order ' , 'stream ' );
501
515
502
516
$ 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
+ ),
504
523
array (
505
524
'post_title ' => $ order_title ,
506
525
'old_status_name ' => $ old_status_name ,
0 commit comments