php - I cant delete Woocommerce rest api product from form
Get the solution ↓↓↓I create delete form but no delete with woocommerce rest api error"Warning: http_build_query() expects parameter 1 to be array, string given in" and "C:\xampp\htdocs\api-woocommerce\vendor\automattic\woocommerce\src\WooCommerce\HttpClient\HttpClient.php on line 138" I dont understad.I can share form and php code;
<?php $i = 1; ?>
<?php foreach ( $data as $row ) : ?>
<tr>
<td><?= $i; ?></td>
<td>
<?= $row['id']; ?>
</td><td>
<?= $row['name']; ?>
</td><td>
<?= $row['permalink']; ?>
</td>
</td>
<td><?= $row['date_created']; ?></td>
<td><?= $row['status']; ?></td>
<td><?= $row['price']; ?></td>
<td><form action="delete_connect.php" name="delete" method="GET">
<input type="checkbox" name="id" value="<?= $row['id']; ?>"/>
</td>
</tr>
<?php $i++; ?>
<?php endforeach; ?>
<td><input type="submit" name="gönder"/></td></form>
and delete_connect.php;
<?php
$PRODUCT_ID = $_GET['id'];
?>
<?php echo json_encode($woocommerce->delete('products/',$PRODUCT_ID,['force' => true])); ?>
Answer
Solution:
Try changing
<?php echo json_encode($woocommerce->delete('products/',$PRODUCT_ID,['force' => true])); ?>
to
<?php echo json_encode($woocommerce->delete('products/'.$PRODUCT_ID,['force' => true])); ?>
assuming your using this
https://woocommerce.github.io/woocommerce-rest-api-docs/?php#delete-a-product
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: filter_sanitize_string deprecated
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.