I need to display some order details on a page of my site.
I found the code that does what I need:
function get_order_details($order_id) {
$order = wc_get_order( $order_id );
$order_meta = get_post_meta($order_id);
echo '<h3>THE ORDER META DATA (Using the array syntax notation):</h3>';
echo '_billing_first_name: ' . $order_meta[_billing_first_name][0] . '<br>';
echo '_billing_last_name: ' . $order_meta[_billing_last_name][0] . '<br>';
echo '_billing_address_index: ' . $order_meta[_billing_address_index][0] . '<br>';
echo '_shipping_address_index: ' . $order_meta[_shipping_address_index][0] . '<br>';
echo '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <br><br>';
}
get_order_details(100);
If insert this code into the function.php
, it works. Information about the order is inserted on all pages at the top, directly above the header.
I want something else, but I do not know how to do it. The site has a page where there is a form:
<form action="/wp-content/themes/storefront/order_number.php" method="post">
<label for="order_number">Order number</label><br>
<input type="text" name="order_number" size="30"><br>
<input type="submit" id="submit" value="Find and output"><br>
</form>
What I have tried:
1) Add this function in custom file "order_number.php
", but it did not work.
An error occurs:
Fatal error: Call to undefined function wc_get_order () in Z: \ home \ magazinehard.ru \ www \ wp-content \ themes \ storefront \ order_number.php on line 4.
2) Add "include 'functions.php'" in "order_number.php
".
An error occurs:
Fatal error: Call to undefined function wp_get_theme() in Z:\home\magazinehard.ru\www\wp-content\themes\storefront\functions.php on line 11.
How can I make this function work in the file "order_number.php
". Or it is possible to use only the necessary function from a file "functions.php
", and others to ignore?
If all this is not possible, are there any other ways to display the details of the order on the page?
I am not really skilled in PHP, but I needed to write a diploma project.
Any help is appreciated.