diff --git a/includes/Generator/CustomerInfo.php b/includes/Generator/CustomerInfo.php index 4357149..3725b14 100644 --- a/includes/Generator/CustomerInfo.php +++ b/includes/Generator/CustomerInfo.php @@ -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( diff --git a/includes/Generator/OrderAttribution.php b/includes/Generator/OrderAttribution.php index 47e4552..a856d3f 100644 --- a/includes/Generator/OrderAttribution.php +++ b/includes/Generator/OrderAttribution.php @@ -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 ) ]; @@ -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'; } /**