WordPress | Add Link Back to the Order in WooCommerce New Order Notifications Email
A customer with a woocommerce project, request if is possibile customize the content of “New order email”.
He need to add :
– Link to product page
– More evident link to order detail.
Here an example of standard woocommerce confirmation mail :
Let’s start by adding link to order detail :
Open your theme function.php and scroll down to the end of the file.
Add this code:
add_action( 'woocommerce_email_after_order_table', 'add_custom_link_back_to_order', 10, 2 ); function add_custom_link_back_to_order( $order, $is_admin ) { // Check if is admin email if ( ! $is_admin ) { return; } // Separated this section from the other content $link = '<br/><p>'; // Add the anchor link to the order page $link .= '<a style="width:100%; display:block; text-align:center;" href="'. admin_url( 'post.php?post=' . absint( $order->id ) . '&action=edit' ) .'" >'; // Link text $link .= __( 'Clicca per visualizzare i detagli dell’ ordine', 'your_domain' ); // Close the link $link .= '</a>'; // Close the paragraph $link .= '</p>'; // Return the link into the email echo $link; }
Basically, this action, add a link to the order details page in the confirma mail after “order table” ( woocommerce_email_after_order_table ).
here you can see how mail looks like after this implementation.
Now we need to add a link to the product page on the product name inside confirmation mail:
One more time open your theme funciotns.php and after the “add_action” that we had just added, paste this code
add_filter( 'woocommerce_order_item_name', 'display_product_title_link', 10, 2 ); function display_product_title_link( $item_name, $item ) { $_product = wc_get_product( $item['variation_id'] ? $item['variation_id'] : $item['product_id'] ); $link = get_permalink( $_product->get_id() ); return '<a href="'. $link .'" rel="nofollow">'. $item_name .'</a>'; }
This filter wrap the Item name inside a link to the item detail page.
That’s all, here you can see how mail appear after the customizations :
That’s All !!