In an online store, every interaction with customers done via email counts—especially when it comes to order management. If a customer places an order, but for some reason, payment doesn’t go through or it is not done. What happens next? Typically, they receive a bland email notifying them that their order is on hold.
This type of email leaves customers feeling disconnected and unsure of what to do next. But what if we could turn those mundane emails into exciting opportunities to engage and reassure? That’s what we are going to see in today’s WooCommerce customization post.
Solution: Add Customer’s Account link in WooCommerce Pending Order Emails
The code will simply add a ‘My Account’ link to the on-hold order status email so that customers when clicking on the link, will be redirected to their personal account page.
add_action('woocommerce_email_after_order_table', 'ts_add_my_account_link_to_on_hold_email', 10, 4); function ts_add_my_account_link_to_on_hold_email($order, $sent_to_admin, $plain_text, $email) { // Check if the email is for an on-hold order and it's not sent to admin if ($email->id == 'customer_on_hold_order' && !$sent_to_admin) { // Get the customer's ID $customer_id = $order->get_customer_id(); // Check if customer ID is valid if ($customer_id) { // Get the My Account URL $my_account_url = get_permalink(get_option('woocommerce_myaccount_page_id')); // Generate the link $my_account_link = '<a href="' . $my_account_url . '">' . __('My Account', 'woocommerce') . '</a>'; // Get the order status $order_status = wc_get_order_status_name('on-hold'); // Output the message echo '<p>' . sprintf(__('Your payment is still pending. To complete your order that is still on %s, please visit %s.', 'woocommerce'), $order_status, $my_account_link) . '</p>'; } } }
Output
When an order is in a pending status, customers receive an on-hold email notification. This code integrates the customer’s ‘My Account’ link into their on-hold order status emails.
Customers will be redirected to their personal account page once the ‘My Account’ is clicked on the email.
Similarly, if you’re looking to add product links as call to action via email, you can look into our post that explains how to adds product links in processing order emails.