【发布时间】:2019-02-28 08:37:02
【问题描述】:
我正在使用 WooCommerce CLI 将包含产品的 CSV 导入 WooCommerce。这行得通,只是我不知道如何为导入的产品创建新类别。
我的产品存储在$product 数组中。 $product['category‘] 是一个带有类别名称的字符串。
wp wc product create --sku="'.$product['sku'].'" --type="simple" --name="'.$product['name'].'" --regular_price="'.$product['price'].'" --categories="'.$catid.'" --images="{'.$product['image'].'}" --user="'.$user.'"
起初我尝试使用类别名称,除非我发现 --categories 参数需要一个整数(或者可能是 JSON-Object,根据另一篇文章)。
因此,我使用以下代码将当前类别 ID 保存到一个变量中以在产品创建中使用(类别和文章处于循环中)。但它不能用作整数 (--categories=12) 或 JSON-Object [{"id" : 12}]。
$cat = shell_exec('wp wc product_cat create --name="'.$product['category'].'" --porcelain --user="'.$user.'"');
只是为了结束它。目前顺序是这样的:
- 创建类别并将当前类别 ID 保存到 $cat (works)
- 创建一个新产品(作品),但未设置类别。它被标记为“未分类”。
我知道,我可以稍后加载文章来设置类别。但我觉得这有点乱。
【问题讨论】:
标签: php wordpress woocommerce command-line-interface