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