Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion includes/Generator/CustomerInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CustomerInfo {
* @return string|\WP_Error
*/
public static function get_valid_country_code( ?string $country_code = '' ) {
$country_code = strtoupper( $country_code );
$country_code = !empty( $country_code ) ? strtoupper( $country_code ) : '';

if ( $country_code && ! WC()->countries->country_exists( $country_code ) ) {
$country_code = new \WP_Error(
Expand Down
22 changes: 10 additions & 12 deletions includes/Generator/OrderAttribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ public static function add_order_attribution_meta( $order, $assoc_args = array()
return;
}

$order_products = $order->get_items();

if ( empty( $order_products ) ) {
return;
}

$device_type = self::get_random_device_type();
$source = 'woo.com';
$source_type = self::get_source_type();
$origin = self::get_origin( $source_type, $source );
$order_products = $order->get_items();
$product_url = get_permalink( $order_products[ array_rand( $order_products ) ]->get_id() );
$utm_content = [ '/', 'campaign_a', 'campaign_b' ];
$utm_content = $utm_content[ array_rand( $utm_content ) ];
Expand Down Expand Up @@ -217,26 +222,19 @@ public static function get_source( $source_type ) {
/**
* Get random device type based on the following distribution:
* Mobile: 50%
* Desktop: 30%
* Tablet: 10%
* Unknown: 10%
* Desktop: 35%
* Tablet: 15%
*/
public static function get_random_device_type() {
$randomNumber = wp_rand( 1, 100 ); // Generate a random number between 1 and 100.

if ( $randomNumber <= 50 ) {
return 'Mobile';
}

if ( $randomNumber <= 80 ) {
} elseif ( $randomNumber <= 85 ) {
return 'Desktop';
}

if ( $randomNumber <= 90 ) {
} else {
return 'Tablet';
}

return 'Unknown';
}

/**
Expand Down