diff --git a/admin/class-informatiq-sp-admin.php b/admin/class-informatiq-sp-admin.php index 5ba71f45..005777de 100644 --- a/admin/class-informatiq-sp-admin.php +++ b/admin/class-informatiq-sp-admin.php @@ -922,11 +922,23 @@ class Informatiq_SP_Admin { ); } - // Sort by potential gain (highest first). + // Sort by predicted conversion change (highest first), products without data last. usort( $comparison, function( $a, $b ) { - $gain_a = $a['potential_gain'] ?? 0; - $gain_b = $b['potential_gain'] ?? 0; - return $gain_b <=> $gain_a; + // Products without insight data go to the end. + if ( ! $a['has_insight'] && $b['has_insight'] ) { + return 1; + } + if ( $a['has_insight'] && ! $b['has_insight'] ) { + return -1; + } + if ( ! $a['has_insight'] && ! $b['has_insight'] ) { + return 0; + } + + // Sort by predicted conversion change (highest first). + $conv_a = $a['predicted_conversions_change'] ?? -999; + $conv_b = $b['predicted_conversions_change'] ?? -999; + return $conv_b <=> $conv_a; } ); wp_send_json_success( array(