Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get View Order URL for custom email in WooCommerce

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.

like image 577
Rana Ghosh Avatar asked Dec 04 '16 12:12

Rana Ghosh


People also ask

How do I find my WooCommerce order URL?

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.

How do I find order details by order ID in WooCommerce?

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)...

How do you show orders in WooCommerce?

Go to: WooCommerce > Orders. Select Screen Options in the top right corner. Select which Columns to show.


1 Answers

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.

like image 97
indextwo Avatar answered Nov 15 '22 05:11

indextwo