I’m building an online store and I have a private page where admins can scan a QR code and it displays the order details of the order assigned to that QR code. Admins can also set the status of the order on that page. I managed to display order notes in that page too. I also would like to add a form (textarea + submit button) to add a order note to the order, because our online store is about services, and I want to be able to put a note when the order is partially redeemed, so we don’t have to go to the desktop -> orders -> the order and add the note. Could somebody help me? I would need a code to directly add it where I want it, I mean, not in functions.php, a code for the custom template of the page (page-scanqr.php). Any help would be appreciated!
EDIT: I saw this and I thought that maybe it could help me somehow, but I don’t know how to apply it so it runs after pressing the submit button and sends the textarea text as a new order note: https://stackoverflow.com/a/49508808/12459095
As I say, I want to apply somehow this function. But I want to run it after pressing the button “submit” and I want it to pick the text from the text area and send it to wordpress as a new order note.
function add_redeeming_notes( $order_id ) {
$order = new WC_Order( $order_id );
// The text for the note
$note = __("I WANT THIS TO PICK THE TEXT FROM THE TEXTAREA");
// Add the note
$order->add_order_note( $note );
EDIT 2: I also show you the code that allows me to display the orders note, in case it could be helpful.
<?php
$order_notes = get_private_order_notes( $order_id );
foreach($order_notes as $note){
$note_id = $note['note_id'];
$note_date = $note['note_date'];
$note_author = $note['note_author'];
$note_content = $note['note_content'];
// Outputting each note content for the order
echo '<p>'.$note_date.' - '.$note_content.'</p>';
} ?>
2
Answers
Here is some psuedo code from my comment above:
That right there will store it. To get it, do this:
Hope that helps.
EDIT:*
WC stores the order notes in the ‘comments’ table. The orders are post types themselves of ‘shop_order’. Simply insert shop_order notes into the comments table as necessary using the order ID set to the ‘comment_post_ID’ field in the ‘comments’ table. Done and done.
Add the follows codes snippet in your custom page template. or you can replace follows code in your template form structure –