In Woocommerce, Currently I have a form where the customer inputs an order number, their name and their post number. The code goes through this code and if everything is correct, the customer is shown the items he has ordered, which leads to my problem:
In the WooCommerce tables, both the price, and the quantity of the are in the same column, and I can't seem to get the values individually.
I have tried different ways to do my current query, but this is the latest one I have been closest to success:
$sql2 = "SELECT *
FROM wp_woocommerce_order_items
LEFT JOIN wp_woocommerce_order_itemmeta ON wp_woocommerce_order_items.order_item_id = wp_woocommerce_order_itemmeta.order_item_id
WHERE wp_woocommerce_order_items.order_id = $ordernumber
AND (meta_key IN ('_line_total', '_qty'))";
Also I'm printing the results with a foreach loop: (Also sorry for the Finnish bits in the picture and the code)
foreach ($res2 as $row) {
echo "<input type='checkbox' name='productinfo[]'><label> Tuotenimi: " . $row['order_item_name'] . "<br /> Kappalehinta: " . $row['meta_value'] ." €"
. "<br /><br />";
}
However, the problem with this code is, that adding the "_qty" column to the AND clause causes the results to come out as double as seen here (Also sorry for the mostly Finnish website):
I'd like to be able to print the quantity and price as individual elements/variables and to be able to additions with the prices, to get the total price of all of the products.
Please ask me anything if the code or the question is confusing!
UPDATE
So I was adviced by Dipmala to use group by which helped me to get the right amount of results. However, I still don't know how to print the quantity as separate with the price. /Puppe