I'm trying to insert a shortcode in the woocommerce view-order.php template but it doesn't work. This is the reference template: https://woocommerce.github.io/code-reference/files/woocommerce-templates-myaccount-view-order.html
In the functions.php file I wrote the following code:
add_shortcode( 'order_view_id' , 'order_view_01' );
function order_view_01(){
$customer_id = get_current_user_id();
$order = new WC_Order( $order_id ); //I think this is the problem I don't know if that's right
return $order->get_id();
}
The shortcode shows the number 0, so I'm not getting the order id which in my case is 40001.
To structure the code I followed these references:
Maybe I should change the line that affects the $order
part, but I'm not sure.
I don't understand where I'm wrong, does anyone kindly have a suggestion?