我想使用cron作业在woocommerce中插入50k产品。数据将来自json API。因此,请指导我如何完成这项工作?
$fileContents = file_get_contents(ABSPATH.'json_array.txt');
if ($fileContents === false)
{
echo 'ERROR!';
}
else
{
$data = json_decode($fileContents, true);
// count($data['DataList']; output 50000
for($i=0;$i<count($data['DataList']);$i++)
{
$Shape = $data->DataList[$i]->Shape;
$Size = $data->DataList[$i]->Size;
$Color = $data->DataList[$i]->Color;
$Clarity = $data->DataList[$i]->Clarity;
$objProduct = new WC_Product();
$objProduct->set_name($ReportNo); //Set product name.
$objProduct->set_status('publish');
$objProduct->set_featured(TRUE);
$objProduct->set_catalog_visibility('visible');
$new_product_id = $objProduct->save();
}
}