I want to get the URL of the Order Details page from where user can see their order details, because using some 3rd party API I send mail to the customer after the product is shipped.
I tried this code
$order = wc_get_order(109);
$public_view_order_url = esc_url( $order->get_view_order_url() );
echo $public_view_order_url; //http://example.com/my-account/view-order/109/
but the URL generated by ^^ above code only works for logged in customer. Is it possible to get a Public URL so that user don't have to logged in because most of the customer don't have any account. I know for security reason email id and invoice number is needed.
One solution that I think is by creating an custom page which will accept order_id
, order_key
and email_id
in GET parameter and query it and display the result; the whole thing I have to create but is there any WooCommerce function/hook for this?
I googled it and also spend time in Woo doc but the result was negative,
Any help or suggation will be very helpfull for me.
Thanks.
We can use the wc_get_endpoint_url function to get the order received page URL. To show this under your order list on the my-account page, you have to edit the template – woocommerce/templates/my-account/orders.
You have access to $order_id variable If you have access to the order ID (once again, usually the do_action or apply_filters might give you this), you have to get the order object first. Then do the exact same things as above. $order = wc_get_order( $order_id ); // Now you have access to (see above)...
Go to: WooCommerce > Orders. Select Screen Options in the top right corner. Select which Columns to show.
Not sure if I'm missing something, but it sounds like what you want can be achieved with the Order Received
URL:
$order->get_checkout_order_received_url()
This would give you something like https://example.com/checkout/order-received/12345/?key=wc_order_1ab2cd3ef4g
, which is a direct link to the order receipt shown after a successfully processed order.
This link will show billing & shipping details, order details & payment method by default, and doesn't require that the customer has an account or for them to be logged in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With