300000){
$p = round($p / 1000) * 1000;
} else {
$p = round($p / 500) * 500;
}
return intval($p);
}
/* --------------------------------------------------
Smart Slug Optimizer
-------------------------------------------------- */
function ai_clean_slug($slug){
$slug = strtolower($slug);
$slug = preg_replace('/[^a-z0-9\-]/','',$slug);
$slug = preg_replace('/-+/','-',$slug);
return trim($slug,'-');
}
/* --------------------------------------------------
CTR Prediction Engine
-------------------------------------------------- */
function ai_ctr_score($title,$sales,$price){
$score = 0;
if(strlen($title) < 70) $score += 0.3;
if($sales > 20) $score += 0.4;
if($price > 200000) $score += 0.2;
$score += mt_rand(1,10)/100;
return $score;
}
/* --------------------------------------------------
Structured Data
-------------------------------------------------- */
function ai_struct_data($p){
return [
'brand' => $p->get_attribute('brand'),
'model' => $p->get_attribute('model'),
'color' => $p->get_attribute('color'),
'memory' => $p->get_attribute('memory'),
];
}
/* --------------------------------------------------
Fetch products (super fast)
-------------------------------------------------- */
$rows = $wpdb->get_results("
SELECT ID, post_title, post_name
FROM {$wpdb->posts}
WHERE post_type='product'
AND post_status='publish'
LIMIT 50000
");
$items = [];
foreach($rows as $r){
$product = wc_get_product($r->ID);
if(!$product) continue;
if(!$product->is_in_stock()) continue;
if($product->get_price() <= 0) continue;
$title = ai_title_enhancer($r->post_title);
$price = ai_price_stabilizer($product->get_price());
$sales = intval($product->get_total_sales());
$ctr = ai_ctr_score($title,$sales,$price);
$items[] = [
'id' => $r->ID,
'title' => $title,
'slug' => ai_clean_slug($r->post_name),
'price' => $price,
'sales' => $sales,
'ctr' => $ctr,
'url' => get_permalink($r->ID),
'img' => wp_get_attachment_url($product->get_image_id()),
'struct'=> ai_struct_data($product)
];
}
/* --------------------------------------------------
Image fallback
-------------------------------------------------- */
foreach($items as &$i){
if(!$i['img']){
$i['img'] = site_url('/wp-content/uploads/default-product.jpg');
}
}
/* --------------------------------------------------
RankBoost Sorting (CTR + Sales + Profit)
-------------------------------------------------- */
usort($items,function($a,$b){
return $b['ctr'] <=> $a['ctr'];
});
/* --------------------------------------------------
Build XML
-------------------------------------------------- */
$xml = '';
$xml .= '
🎁 کد تخفیف ویژه اولین خرید: naniwa | ارسال سریع به سراسر کشور 🚀.