php - 如何在我的自定义 PHP 文件中使用一类 WooCommerce?(产品 CSV 导入器)
问题描述
我有一个 WooCommerce 网站,我需要通过 CSV 文件自动更新产品。为此,我创建了一个执行 PHP 文件的 cron 作业,它每小时创建一个 csv 文件(命名为:jsonproducts.csv)。
现在,我计划创建一个新的自定义 PHP 文件,该文件将使用 Woocommerce 的 WC_Product_CSV_Importer 类的 import() 方法。(类)
当我尝试执行此操作时,结果被导入:0,失败:0,更新:0,跳过:0。
我怎样才能成功执行这个?
<?php
include("wp-load.php");
require_once('wp-content/plugins/woocommerce/includes/import/class-wc-product-csv-importer.php');
$args = array(
'start_pos' => 0, // File pointer start.
'end_pos' => 5, // File pointer end.
'lines' => 5, // Max lines to read.
'mapping' => array(), // Column mapping. csv_heading => schema_heading.
'parse' => true, // Whether to sanitize and format data.
'update_existing' => true, // Whether to update existing items.
'delimiter' => ',', // CSV delimiter.
'prevent_timeouts' => false, // Check memory and time usage and abort if reaching limit.
'enclosure' => '"', // The character used to wrap text in the CSV.
'escape' => "\0", // PHP uses '\' as the default escape character. This is not RFC-4180 compliant. This disables the escape character.
);
$file = 'json2csv.csv';
$WC_Product_CSV_Importer = new WC_Product_CSV_Importer($file, $args);
var_dump($WC_Product_CSV_Importer->import());
?>
解决方案
推荐阅读
- node.js - 是否有代码模式可以将使用 async 函数创建的 bcrypt 哈希返回到单独的模块?
- java - 使用 Jackson 反序列化带有重复嵌套标签的 xml
- javascript - 添加respond_to时的ActionController::UnknownFormat
- unreal-engine4 - 如何获取对触发框的引用
- c++ - 如何在使用 GDB 遍历代码时禁用 C++ 模板中的单步执行?
- android - 使用 Burp 拦截时 Android 上的 TLS 证书错误 - 使用 Facebook 应用程序
- c# - C# Winform SQL Server 连接字符串
- java - 阿帕奇点燃;连接集群失败,连接失败
- javascript - Promise .then() 链:第二个 .then 在第一个之前运行?o.0
- java - 在 Junit 测试中打印出方法的输出