Revise excluded order statuses for order attribution customer history (#42999)
* Better align excluded order statuses with WC Reports * Update Tracks data to match updated customer order history count * Add changelog * Clarify code comment * Exclude `checkout-draft` for block checkout/API orders. * Remove unecessary array_map Co-authored-by: Bartosz Budzanowski <bartosz.budzanowski@automattic.com> * Use existing method to get un-prefixed order statuses --------- Co-authored-by: Bartosz Budzanowski <bartosz.budzanowski@automattic.com>
This commit is contained in:
parent
8e351f2f15
commit
cb0c42180a
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: update
|
||||
|
||||
Revise excluded order statuses for customer history.
|
|
@ -411,7 +411,8 @@ class OrderAttributionController implements RegisterHooksInterface {
|
|||
'session_pages' => $source_data['session_pages'] ?? 0,
|
||||
'session_count' => $source_data['session_count'] ?? 0,
|
||||
'order_total' => $order->get_total(),
|
||||
'customer_order_count' => $customer_info['order_count'],
|
||||
// Add 1 to include the current order (which is currently still Pending when the event is sent).
|
||||
'customer_order_count' => $customer_info['order_count'] + 1,
|
||||
'customer_registered' => $order->get_customer_id() ? 'yes' : 'no',
|
||||
);
|
||||
$this->proxy->call_static( WC_Tracks::class, 'record_event', 'order_attribution', $tracks_data );
|
||||
|
|
|
@ -4,6 +4,7 @@ declare( strict_types=1 );
|
|||
namespace Automattic\WooCommerce\Internal\Traits;
|
||||
|
||||
use Automattic\WooCommerce\Vendor\Detection\MobileDetect;
|
||||
use Automattic\WooCommerce\Admin\API\Reports\Controller as ReportsController;
|
||||
use Exception;
|
||||
use WC_Meta_Data;
|
||||
use WC_Order;
|
||||
|
@ -385,13 +386,19 @@ trait OrderAttributionMeta {
|
|||
* @return array Order count, total spend, and average spend per order.
|
||||
*/
|
||||
private function get_customer_history( $customer_identifier ): array {
|
||||
/*
|
||||
* Exclude the statuses that aren't valid for the Customers report.
|
||||
* 'checkout-draft' is the checkout block's draft order status. `any` is added by V2 Orders REST.
|
||||
* @see /Automattic/WooCommerce/Admin/API/Report/DataStore::get_excluded_report_order_statuses()
|
||||
*/
|
||||
$all_order_statuses = ReportsController::get_order_statuses();
|
||||
$excluded_statuses = array( 'pending', 'failed', 'cancelled', 'auto-draft', 'trash', 'checkout-draft', 'any' );
|
||||
|
||||
// Get the valid customer orders.
|
||||
$args = array(
|
||||
'limit' => - 1,
|
||||
'return' => 'objects',
|
||||
// Don't count cancelled or failed orders.
|
||||
'status' => array( 'pending', 'processing', 'on-hold', 'completed', 'refunded' ),
|
||||
'status' => array_diff( $all_order_statuses, $excluded_statuses ),
|
||||
'type' => 'shop_order',
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue