// افزایش حافظه برای پردازش محصولات لوازم خانگی
define('WP_MEMORY_LIMIT', '512M');
// غیرفعال کردن کرون داخلی و جایگزینی با کرون واقعی (سرعت سایت را 30% بالا میبرد)
define('DISABLE_WP_CRON', true);
// محدود کردن تعداد نسخههای پیشنویس برای سبک ماندن دیتابیس
define('WP_POST_REVISIONS', 3);
// فعال کردن کش داخلی
define('WP_CACHE', true);
';
echo '';
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1,
);
$products = new WP_Query($args);
if ($products->have_posts()) {
while ($products->have_posts()) {
$products->the_post();
$product = wc_get_product(get_the_ID());
if (!$product || $product->get_price() <= 0) continue;
$availability = $product->is_in_stock() ? 'instock' : 'outofstock';
$image = wp_get_attachment_image_url($product->get_image_id(), 'full');
echo '';
echo '' . get_the_ID() . '';
echo '';
echo '' . round($product->get_price()) . '';
echo '' . get_permalink() . '';
echo '' . esc_url($image) . '';
echo '' . $availability . '';
echo '';
}
}
wp_reset_postdata();
echo '';
$xml_output = ob_get_clean();
file_put_contents($cache_file, $xml_output);
header('Content-Type: application/xml; charset=utf-8');
echo $xml_output;
'product',
'post_status' => 'publish',
'posts_per_page' => -1,
];
$query = new WP_Query($args);
echo '';
echo '';
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$product = wc_get_product(get_the_ID());
if (!$product) continue;
$price = (float) $product->get_price();
if ($price <= 0) continue;
$image = wp_get_attachment_image_url($product->get_image_id(), 'full');
echo '';
echo '' . get_the_ID() . '';
echo '';
echo '' . intval($price) . '';
echo '' . esc_url(get_permalink()) . '';
echo '' . esc_url($image) . '';
echo '' . ($product->is_in_stock() ? 'instock' : 'outofstock') . '';
echo '';
}
wp_reset_postdata();
}
echo '';
$content = ob_get_clean();
file_put_contents($cache_file, $content);
echo $content;
get_attribute('pa_brand');
if(!$brand) $brand='Generic';
return tr_clean($brand);
}
function tr_category($id){
$terms=get_the_terms($id,'product_cat');
if(!$terms) return 'عمومی';
return tr_clean($terms[0]->name);
}
function tr_gtin($product){
$gtin=$product->get_meta('_gtin');
if(!$gtin) $gtin=$product->get_meta('_barcode');
return $gtin;
}
/* QUERY */
$products=$wpdb->get_results("
SELECT ID,post_title
FROM {$wpdb->posts}
WHERE post_type='product'
AND post_status='publish'
");
/* XML */
$fp=fopen($tmp_file,'w');
fwrite($fp,"\n");
fwrite($fp,"\n");
$used=[];
foreach($products as $row){
$product=wc_get_product($row->ID);
if(!$product) continue;
$title=tr_title($row->post_title);
$brand=tr_brand($product);
$cat=tr_category($row->ID);
$url=get_permalink($row->ID);
$img=tr_image($row->ID);
if($product->is_type('variable')){
$vars=$product->get_available_variations();
foreach($vars as $v){
$var=wc_get_product($v['variation_id']);
if(!$var) continue;
if(!$var->is_in_stock()) continue;
$price=$var->get_price();
if($price<=0) continue;
$price=tr_price($price);
$id=$var->get_id();
if(isset($used[$id])) continue;
$sku=$var->get_sku();
$gtin=tr_gtin($var);
fwrite($fp,"\n");
fwrite($fp,"{$id}\n");
fwrite($fp,"\n");
fwrite($fp,"\n");
fwrite($fp,"\n");
fwrite($fp,"{$price}\n");
fwrite($fp,"IRR\n");
fwrite($fp,"{$url}\n");
fwrite($fp,"{$img}\n");
if($sku)
fwrite($fp,"{$sku}\n");
if($gtin)
fwrite($fp,"{$gtin}\n");
fwrite($fp,"instock\n");
fwrite($fp,"".get_bloginfo('name')."\n");
fwrite($fp,"\n");
$used[$id]=true;
}
}else{
if(!$product->is_in_stock()) continue;
$price=$product->get_price();
if($price<=0) continue;
$price=tr_price($price);
$id=$product->get_id();
if(isset($used[$id])) continue;
$sku=$product->get_sku();
$gtin=tr_gtin($product);
fwrite($fp,"\n");
fwrite($fp,"{$id}\n");
fwrite($fp,"\n");
fwrite($fp,"\n");
fwrite($fp,"\n");
fwrite($fp,"{$price}\n");
fwrite($fp,"IRR\n");
fwrite($fp,"{$url}\n");
fwrite($fp,"{$img}\n");
if($sku)
fwrite($fp,"{$sku}\n");
if($gtin)
fwrite($fp,"{$gtin}\n");
fwrite($fp,"instock\n");
fwrite($fp,"".get_bloginfo('name')."\n");
fwrite($fp,"\n");
$used[$id]=true;
}
}
fwrite($fp,"");
fclose($fp);
/* SAVE */
if(file_exists($tmp_file) && filesize($tmp_file)>500){
rename($tmp_file,$cache_file);
readfile($cache_file);
}else{
if(file_exists($cache_file)){
readfile($cache_file);
}
}
کالایی در این صفحه موجود نیست