【问题标题】:Woocommerce rest api category and image upload/add problemWoocommerce rest api 类别和图片上传/添加问题
【发布时间】: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

我已经添加了一个系列并尝试了很多次,但我无法成功。你能帮助我吗?如何进行单一选择并添加产品?

【问题讨论】:

    标签: php arrays rest post


    【解决方案1】:

    您提供的 HTML 代码表明有两个不同的复选框组。如果你想做一个。保持所有名称属性相同。

    <input type ="checkbox" name="test[]" id="test1" value="16" />
    <input type ="checkbox" name="test[]" id="test2" value="17" />
    

    当没有选中复选框时,PHP 将不会收到任何名为 test 的 POST 数据。要对此进行检查,您可能需要在使用前进行检查。

    if(isset($_POST['test'])){
         foreach($_POST['test'] as $report_id){
            echo "$report_id was checked! ";
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-05
      • 2015-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-19
      相关资源
      最近更新 更多