| @@ -106,15 +106,15 @@ | ||
| 106 | 106 | * @return int|null Product ID if found, null if no match |
| 107 | 107 | */ |
| 108 | 108 | public static function mxchat_extract_product_id_from_message($message) { |
| 109 | 109 | if (!function_exists('wc_get_products')) { |
| 110 | - //error_log("WooCommerce is not active or not available."); | |
| 110 | + error_log("WooCommerce is not active or not available."); | |
| 111 | 111 | return null; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | // Clean and normalize input |
| 115 | 115 | $message = sanitize_text_field(strtolower($message)); |
| 116 | - //error_log("Product extraction message: " . $message); | |
| 116 | + error_log("Product extraction message: " . $message); | |
| 117 | 117 | |
| 118 | 118 | // Get all published products |
| 119 | 119 | $products = wc_get_products([ |
| 120 | 120 | 'status' => 'publish', |
| @@ -121,9 +121,9 @@ | ||
| 121 | 121 | 'limit' => -1, |
| 122 | 122 | 'return' => 'objects' |
| 123 | 123 | ]); |
| 124 | 124 | |
| 125 | - //error_log("Total products to search: " . count($products)); | |
| 125 | + error_log("Total products to search: " . count($products)); | |
| 126 | 126 | |
| 127 | 127 | // Store all matches with their scores |
| 128 | 128 | $matches = []; |
| 129 | 129 | |
| @@ -128,9 +128,9 @@ | ||
| 128 | 128 | $matches = []; |
| 129 | 129 | |
| 130 | 130 | // Search terms (original message and name-only version) |
| 131 | 131 | $search_terms = explode(' ', $message); |
| 132 | - //error_log("Search terms: " . implode(', ', $search_terms)); | |
| 132 | + error_log("Search terms: " . implode(', ', $search_terms)); | |
| 133 | 133 | |
| 134 | 134 | foreach ($products as $product) { |
| 135 | 135 | $score = 0; |
| 136 | 136 | $product_name = strtolower($product->get_name()); |
| @@ -187,9 +187,14 @@ | ||
| 187 | 187 | 'name' => $product_name, |
| 188 | 188 | 'consecutive_matches' => $max_consecutive |
| 189 | 189 | ]; |
| 190 | 190 | |
| 191 | - // error_log(sprintf("Product '%s' scored %f with %d consecutive matches", $product_name, $score, $max_consecutive)); | |
| 191 | + error_log(sprintf( | |
| 192 | + "Product '%s' scored %f with %d consecutive matches", | |
| 193 | + $product_name, | |
| 194 | + $score, | |
| 195 | + $max_consecutive | |
| 196 | + )); | |
| 192 | 197 | } |
| 193 | 198 | } |
| 194 | 199 | } |
| 195 | 200 | |
| @@ -204,13 +209,19 @@ | ||
| 204 | 209 | |
| 205 | 210 | // Return the best match if we found any |
| 206 | 211 | if (!empty($matches)) { |
| 207 | 212 | $best_match = $matches[0]; |
| 208 | - // error_log(sprintf("Selected best match: '%s' (ID: %d) with score %f and %d consecutive matches", $best_match['name'], $best_match['product_id'], $best_match['score'], $best_match['consecutive_matches'])); | |
| 213 | + error_log(sprintf( | |
| 214 | + "Selected best match: '%s' (ID: %d) with score %f and %d consecutive matches", | |
| 215 | + $best_match['name'], | |
| 216 | + $best_match['product_id'], | |
| 217 | + $best_match['score'], | |
| 218 | + $best_match['consecutive_matches'] | |
| 219 | + )); | |
| 209 | 220 | return $best_match['product_id']; |
| 210 | 221 | } |
| 211 | 222 | |
| 212 | - //error_log("No product matches found"); | |
| 223 | + error_log("No product matches found"); | |
| 213 | 224 | return null; |
| 214 | 225 | } |
| 215 | 226 | |
| 216 | 227 | |