The issue seems complex to me and I have only some ideas, but I am not experienced enough to develop them on my own. I would love some guidance on this.
So, I want to insert additional order metadata into an existing order. Let's say the process looks like that:
Checkout with all the needed info -> External app opens -> User inputs data and clicks save -> External app adds the input to the database for the current order
I have already studied wp_postmeta table. I have general idea on how to get data from input forms into the database. Small example from HTML form:
<input type="text" name="cprawy" id="cprawy" value="-1" maxlength="5">
<input type="text" name="clewy" id="clewy" value="1" maxlength="5">
Then there is process.php file, in which the data is inserted. Of course I have connected the database, skipped that part of the code. And here it all goes into uncharted territory for me.
$clewy = $_POST ['clewy'];
$cprawy = $_POST ['cprawy'];
$query = "INSERT INTO wp_postmeta (meta_key, meta_value)
VALUES ('".$_POST["billing_clewy"]."','".$_POST["billing_cprawy"]."')";
I am almost certain that the above code is wrong on some levels.
Also, I somehow need to fetch the order ID and connect above items with it, so it displays correctly on the order fields in WooCommerce.
Is there anyone here that could help me with this?
Thanks in advance, Tomasz