I made this shortcode to show the total value of an order to users.
It does work to display the value, however it keeps giving me this error message when I try to access my website "There has been a critical error on this website. Please check your site admin email inbox for instructions."
The error seems to be in this line $order_line_items = $order->get_items();
.
Error details emailed to me by Wordpress.
An error of type E_ERROR was caused in line 67 of the file /home/example.com/wp-content/themes/hello-theme-child-master/functions.php. Error message: Uncaught Error: Call to a member function get_items() on bool in /home/ example.com/wp-content/themes/hello-theme-child-master/functions.php:67
Stack trace:
#0 /home/ example.com/wp-includes/shortcodes.php(356): getOrderItemList('', '', 'order-line-item')
#1 [internal function]: do_shortcode_tag(Array)
#2 /home/example.com/wp-includes/shortcodes.php(228): preg_replace_callback('/\\[(\\[?)(order\\...', 'do_shortcode_ta...', '
Code
function getOrderItemList() {
// get order ID.
$order_id = absint( $wp->query_vars['order-received'] );
$order = wc_get_order( $order_id );
$order_line_items = $order->get_items();
$total = $order->get_total();
return $total;
}
add_shortcode( 'order-line-item', 'getOrderItemList' );
Thank you