I am trying to get order details to display a summary on my thank you page. The issue I am having is that this code snippet I have is breaking my wordpress. I have the stacktrace but I am unsure on how to fix it. The code to me looks correct so ensure why it's not working. Does anybody have any idea what is the meaning of this stacktrace and how I can fix it?
An error of type E_ERROR was caused in line 7 of the file /home4/xxx/public_html/staging/4326/wp-content/plugins/code-snippets/php/snippet-ops.php(446) : eval()'d code. Error message: Uncaught Error: Call to a member function get_items() on boolean in /home4/xxx/public_html/staging/4326/wp-content/plugins/code-snippets/php/snippet-ops.php(446) : eval()'d code:7
Stack trace:
#0 /home4/xxx/public_html/staging/4326/wp-includes/shortcodes.php(343): order_table_summary('', '', 'order_table_sum...')
#1 [internal function]: do_shortcode_tag(Array)
#2 /home4/xxx/public_html/staging/4326/wp-includes/shortcodes.php(218): preg_replace_callback('/\\[(\\[?)(order_...', 'do_shortcode_ta...', '\n
My code:
function order_table_summary(){
$order = wc_get_order($order_id);
// Get and Loop Over Order Items
foreach ( $order->get_items() as $item_id => $item ) {
echo $item->get_name() . $item->get_quantity. $item->get_total();
}
}
add_shortcode('order_table_summary', 'order_table_summary');
UPDATE Adding the shortcode