Add tracking event on order search.

This commit is contained in:
Timmy Crawford 2020-05-07 12:05:11 -07:00
parent 43ab840e1a
commit 2420b8013d
1 changed files with 20 additions and 0 deletions

View File

@ -21,6 +21,26 @@ class WC_Orders_Tracking {
// WC_Meta_Box_Order_Actions::save() hooks in at priority 50.
add_action( 'woocommerce_process_shop_order_meta', array( $this, 'track_order_action' ), 51 );
add_action( 'load-post-new.php', array( $this, 'track_add_order_from_edit' ), 10 );
add_filter( 'woocommerce_shop_order_search_results', array( $this, 'track_order_search' ), 10, 3 );
}
/**
* Send a track event when on the Order Listing page, and search results are being displayed.
*
* @param array $order_ids Array of order_ids that are matches for the search.
* @param string $term The string that was used in the search.
* @param array $search_fields Fields that were used in the original search.
*/
public function track_order_search( $order_ids, $term, $search_fields ) {
$screen = get_current_screen();
// We only want to record this track when the filter is executed on the order listing page.
if ( 'edit-shop_order' === $screen->id ) {
// we are on the order listing page, and query results are being shown.
WC_Tracks::record_event( 'orders_view_search' );
}
return $order_ids;
}
/**