【发布时间】:2021-05-17 20:55:48
【问题描述】:
我可以为 woocommerce rest api.name、价格或描述编写产品表单,但是,如果我添加到单个类别或仅添加到单个图像链接,则响应错误。首先我可以共享表单;
<input type ="checkbox" name="test1" id="test1" value="16" /><br>///value is category id
<input type ="checkbox" name="test2" id="test2" value="17" /><br>///value is category id
和php post sciprt;
$test1 = $_POST['test1'];
$test2 = $_POST['test2'];
$data =
[
'categories' => [
[
'id' => $_POST['test1'],
],
[
'id' => $_POST['test2'],
]
],
];
<?php echo json_encode($woocommerce->POST('products', $data)); ?>
如果我只能选择“test1”或“test2”按钮,会出现以下错误代码
Notice: Undefined index: test2
Notice: Undefined index: test1
我已经添加了一个系列并尝试了很多次,但我无法成功。你能帮助我吗?如何进行单一选择并添加产品?
【问题讨论】: