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])); ?>
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
Related
I'm currently doing this if statement here, I wanted to simplify it into a loop. I try putting it into an array for the client_fullname and etc. but turns out only string form can be done. I wanted to simplicity this coding into a loop but i have no idea how to do it.
<tr class="sale" data-id="<?= $sale['id']; ?>">
<td><?= $pagination->offset + $key + 1; ?></td>
<?php if ($checked_columns['client_fullname']): ?>
<td><?= $sale['client_fullname']; ?></td>
<?php endif; ?>
<?php if ($checked_columns['client_email']): ?>
<td> <?php echo $sale['client_email']; ?></td>
<?php endif; ?>
<?php if ($checked_columns['client_phone_number']): ?>
<td> <?php echo $sale['client_phone_number']; ?></td>
<?php endif; ?>
<?php if ($checked_columns['total_amount']): ?>
<td><?= $sale['total_amount']; ?></td>
<?php endif; ?>
<?php if ($checked_columns['total_sales_amount']): ?>
<td><?= $sale['total_sales_amount']; ?></td>
<?php endif; ?>
<?php if ($checked_columns['first_date_buy']): ?>
<td><?= $sale['first_date_buy']; ?></td>
<?php endif; ?>
<?php if ($checked_columns['created_at']): ?>
<td><?= $sale['created_at']; ?></td>
<?php endif ?>
</tr>
You can reference the below example to achieve your desired output.
<?php
foreach($checked_columns as $key=>$column){
if ($column){
if ($key == 'client_email' || $key == 'client_phone_number'){?>
<td> <?= $sale[$key]; ?></td>
<?php }else{?>
<td><?= $sale[$key]; ?></td><?php
}
}
<?php
while($row = mysqli_fetch_array($results)){
?>
<tbody>
<tr>
<td> <?php echo $row['Product_ID'] ?></td>
<td> <?php echo $row['Product_Name'] ?></td>
<td> <?php echo $row['Product_Price'] ?></td>
<td> <?php echo $row['Product_Stock'] ?></td>
<td> <button type="submit" name="add" id="<?php $row['Product_ID'] ?>" onclick="func(<?php $row['Product_ID'] ?>)"> Add </button></td>
</tr>
<?php } ?>`
<script type="text/javascript" method="post">
function func(id){
window.alert(id);
};
</script>
Is there a way I could store id of my button named add?
I've to store multiple product ids and use them in a receipt that would be generated using product ids. the method of the form is POST but I don't know how to get the id
Replace this
func(<?php $row['Product_ID'] ?>)
With This
func(<?php echo $row['Product_ID']; ?>)
Here is the query statement that I have. For some reason it works for another table I have but doesn't work with this table. I checked phpmyadmin to see if I would create an error but there were zero errors.
$Store_ID = filter_input(INPUT_POST,'Store_ID',FILTER_VALIDATE_INT);
//DELETE the Store
$query="DELETE FROM store_location WHERE Store_ID = :Store_ID";
$statement2=$db->prepare($query);
$statement2->bindValue(':Store_ID',$Store_ID);
$statement2->execute();
$statement2->closeCursor();
Here is the table code for the Delete Button
<?php foreach ($stores as $s) : ?>
<tr>
<td><?php echo $s['Store_ID']; ?></td>
<td><?php echo $s['Loc_Street']; ?></td>
<td><?php echo $s['Loc_City']; ?></td>
<td><?php echo $s['Loc_State']; ?></td>
<td><?php echo $s['Rent']; ?></td>
<td><?php echo $s['License']; ?></td>
<td><?php echo $s['Inspect']; ?></td>
<td><form action="stores.php" method="post">
<input type ="hidden" name ="Store_ID" value ="<?php echo $s['Store_ID']; ?>"/>
<input type="button" name="delete" value="Delete"/>
</form></td>
</tr>
<?php endforeach; ?>
</table>
form.php
<div> Leaving From
<input type="text" class="from" name="source_point" id="source_point" title="Departure Place" required/>
</div>
<div class="right"><b>Going To
<input type="text" class="to" name="destination" id="destination" title="Arrival Place" required />
</div>
search.php
<table>
<tr>
<td>Sl No.</td>
<td>Bus Operator</td>
<td>Bus No. </td>
</tr>
<?php
$s=mysql_query("SELECT * FROM bus_detail where source_point='$_SESSION[source_point]' && destination_point='$_SESSION[destination]'");
while($row=mysql_fetch_array($s))
{
?>
<tr>
<td> </td>
<td><?php echo $row['bus_name'];?> </td>
<td><?php echo $row['bus_no'];?></td>
</tr>
<?php }?>
</table>
I want to display serial numbers from 1 according to the search results, in the empty <td> field, not any random number.. It should be serial numbers in proper format ...
It is as simple as adding a counter variable.
<?php
$s=mysql_query("SELECT * FROM bus_detail where source_point='$_SESSION[source_point]' && destination_point='$_SESSION[destination]'");
$counter = 0;
while($row=mysql_fetch_array($s))
{
?>
<tr>
<td><?php echo ++$counter; ?></td>
<td><?php echo $row['bus_name'];?> </td>
<td><?php echo $row['bus_no'];?></td>
</tr>
<?php }?>
You need to go through the basics if you couldn't figure this out.
You can add incremental value inside the loop
In your search.php, include
$i=1;
while($row=mysql_fetch_array($s))
{
?>
<tr>
<td><?php echo $i </td>
<td><?php echo $row['bus_name'];?> </td>
<td><?php echo $row['bus_no'];?></td>
</tr>
<?php $i++ }?>
</table>
user a count variable as initialize with 0 and increment it by 1 in each row display and you can print the serial no as this way.
<table>
<tr>
<td>Sl No.</td>
<td>Bus Operator</td>
<td>Bus No. </td>
</tr>
<?php
$count = 0;
$s=mysql_query("SELECT * FROM bus_detail where source_point='$_SESSION[source_point]' && destination_point='$_SESSION[destination]'");
while($row=mysql_fetch_array($s))
{
$count+=1;
?>
<tr>
<td><?php echo $count; ?></td>
<td><?php echo $row['bus_name'];?> </td>
<td><?php echo $row['bus_no'];?></td>
</tr>
<?php }?>
</table>
On the view if i post like this it works, but i want each column individually in this controller. i can do this on first foreach but on second one i want how to do that when i am using $field_name - what code do i need to add to this?
<?php foreach($formates as $formate): ?>
<tr>
<?php foreach($fields as $field_name => $field_display): ?>
<td>
<?php echo $formate->$field_name(HERE i want individualy ?>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
controller
$data['fields'] = array(
'FID' => 'ID',
'title' => 'Title',
'category' => 'Category',
'dep_id' => 'Department',
'bf_linkpdf' => 'pdf',
'bf_linkxls' => 'xls',
'bf_linkdoc' => 'doc'
);
on the view i want to list them indevidualy
<?php foreach($formates as $formate): ?>
<tr>
<?php foreach($fields as $field_name => $field_display): ?>
<td>
<?php echo $formate->$field_name->FID ?>
<?php echo $formate->$field_name->title ?>
<?php echo $formate->$field_name->category ?>
<?php echo $formate->$field_name->dep_id ?>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
regards
thanks in advance.
On the view I added the following and it started working.
<?php foreach($formates as $formate): ?>
<tr>
<td><?php echo $formate->id; ?></td>
<td><?php echo $formate->title; ?></td>
<td><?php echo $formate->category; ?></td>
<td><?php echo $formate->dep_id; ?></td>
</tr>
<?php endforeach; ?>
i don't know why are you using the first loop formats , since your array is field..you can just do
<?php foreach($fields as $field): ?>
<td>
<?php echo $field['FID'] ?>
<?php echo $field['title'] ?>
<?php echo $field['category'] ?>
<?php echo $field['dep_id'] ?>
</td>
<?php endforeach; ?>
OR
each fields name and display in each <tr>
<?php foreach($fields as $field_name => $field_display): ?>
<tr>
<td>
<?php echo $field_name ?>
</td>
<td><?php echo $field_display ?></td>
</tr>
<?php endforeach; ?>