Skip to content

Commit 5770902

Browse files
authored
Merge pull request #145 from woocommerce/fix/unknow_device_type
Fixed get_random_device_type() output to match OrderAttributionMeta::get_device_type() possible return value.
2 parents 2702baf + 4a9a6c1 commit 5770902

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

includes/Generator/CustomerInfo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class CustomerInfo {
1616
* @return string|\WP_Error
1717
*/
1818
public static function get_valid_country_code( ?string $country_code = '' ) {
19-
$country_code = strtoupper( $country_code );
19+
$country_code = !empty( $country_code ) ? strtoupper( $country_code ) : '';
2020

2121
if ( $country_code && ! WC()->countries->country_exists( $country_code ) ) {
2222
$country_code = new \WP_Error(

includes/Generator/OrderAttribution.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,16 @@ public static function add_order_attribution_meta( $order, $assoc_args = array()
2424
return;
2525
}
2626

27+
$order_products = $order->get_items();
28+
29+
if ( empty( $order_products ) ) {
30+
return;
31+
}
32+
2733
$device_type = self::get_random_device_type();
2834
$source = 'woo.com';
2935
$source_type = self::get_source_type();
3036
$origin = self::get_origin( $source_type, $source );
31-
$order_products = $order->get_items();
3237
$product_url = get_permalink( $order_products[ array_rand( $order_products ) ]->get_id() );
3338
$utm_content = [ '/', 'campaign_a', 'campaign_b' ];
3439
$utm_content = $utm_content[ array_rand( $utm_content ) ];
@@ -217,26 +222,19 @@ public static function get_source( $source_type ) {
217222
/**
218223
* Get random device type based on the following distribution:
219224
* Mobile: 50%
220-
* Desktop: 30%
221-
* Tablet: 10%
222-
* Unknown: 10%
225+
* Desktop: 35%
226+
* Tablet: 15%
223227
*/
224228
public static function get_random_device_type() {
225229
$randomNumber = wp_rand( 1, 100 ); // Generate a random number between 1 and 100.
226230

227231
if ( $randomNumber <= 50 ) {
228232
return 'Mobile';
229-
}
230-
231-
if ( $randomNumber <= 80 ) {
233+
} elseif ( $randomNumber <= 85 ) {
232234
return 'Desktop';
233-
}
234-
235-
if ( $randomNumber <= 90 ) {
235+
} else {
236236
return 'Tablet';
237237
}
238-
239-
return 'Unknown';
240238
}
241239

242240
/**

0 commit comments

Comments
 (0)