-
Notifications
You must be signed in to change notification settings - Fork 10.7k
/
OrderAttribution.php
92 lines (76 loc) · 2.09 KB
/
OrderAttribution.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\Internal\Admin\Orders\MetaBoxes;
use Automattic\WooCommerce\Internal\Traits\OrderAttributionMeta;
use WC_Order;
/**
* Class OrderAttribution
*
* @since 8.5.0
*/
class OrderAttribution {
use OrderAttributionMeta;
/**
* OrderAttribution constructor.
*/
public function __construct() {
$this->set_fields_and_prefix();
}
/**
* Format the meta data for display.
*
* @since 8.5.0
*
* @param array $meta The array of meta data to format.
*
* @return void
*/
public function format_meta_data( array &$meta ) {
if ( array_key_exists( 'device_type', $meta ) ) {
switch ( $meta['device_type'] ) {
case 'Mobile':
$meta['device_type'] = __( 'Mobile', 'woocommerce' );
break;
case 'Tablet':
$meta['device_type'] = __( 'Tablet', 'woocommerce' );
break;
case 'Desktop':
$meta['device_type'] = __( 'Desktop', 'woocommerce' );
break;
default:
$meta['device_type'] = __( 'Unknown', 'woocommerce' );
break;
}
}
}
/**
* Output the attribution data metabox for the order.
*
* @since 8.5.0
*
* @param WC_Order $order The order object.
*
* @return void
*/
public function output( WC_Order $order ) {
$meta = $this->filter_meta_data( $order->get_meta_data() );
// If we don't have any meta to show, return.
if ( empty( $meta ) ) {
esc_html_e( 'No order source data available.', 'woocommerce' );
return;
}
$this->format_meta_data( $meta );
// No more details if there is only the origin value - this is for unknown source types.
$has_more_details = array( 'origin' ) !== array_keys( $meta );
// For direct, web admin, or mobile app orders, also don't show more details.
$simple_sources = array( 'typein', 'admin', 'mobile_app' );
if ( isset( $meta['source_type'] ) && in_array( $meta['source_type'], $simple_sources, true ) ) {
$has_more_details = false;
}
$template_data = array(
'meta' => $meta,
'has_more_details' => $has_more_details,
);
wc_get_template( 'order/attribution-details.php', $template_data );
}
}