there are many ways to improve the customer experience and increase sales. One such way is to show related products on WooCommerce order emails.
By default, the WooCommerce order emails only include the products that the customer has purchased. However, showing related products can be a powerful way to promote additional products that the customer may be interested in, based on their previous purchase.
Show Similar Items in WooCommerce Customer Order Processing Email
<?php
add_action( 'woocommerce_email_after_order_table', 'cxc_add_releted_product_specific_email_call_back', 20, 4 );
function cxc_add_releted_product_specific_email_call_back( $order, $sent_to_admin, $plain_text, $email ) {
if ( $email->id == 'customer_processing_order' ) {
$cxc_related = array();
if( $order->get_items() ){
foreach ( $order->get_items() as $item_id => $item ) {
$cxc_related = array_merge( wc_get_related_products( $item->get_product_id() ), $cxc_related );
}
}
if ( ! $cxc_related ){ return; }
shuffle( $cxc_related );
$cxc_related = array_unique( $cxc_related );
echo '<h2>You May Also Like</h2>';
$html = '';
$col = 1;
$cols = 3;
$limit = 3;
$html .= '<div><table style="table-layout:fixed;width:100%;margin-bottom:30px;"><tbody>';
if( $cxc_related ){
foreach ( array_slice( $cxc_related, 0, $limit ) as $product_id ) {
$product = wc_get_product( $product_id );
$html .= ( $col + $cols - 1 ) % $cols === 0 ? '<tr>' : '';
$html .= '<td style="text-align:center;vertical-align:bottom;border:1px solid #7f54b3;">';
$html .= $product->get_image();
$html .= '<h3 style="text-align:center;">' . $product->get_title() . '</h3>';
$html .= '<p>' . $product->get_price_html() . '</p>';
$html .= '<p><a href="' . get_permalink( $product_id ) . '">' . __( 'Read more', 'woocommerce' ) . '</a></p></td>';
$html .= $col % $cols === 0 ? '</tr>' : '';
$col++;
}
}
$html .= '</tbody></table></div>';
echo $html;
}
}
?>
By showing related products on WooCommerce order emails in WordPress, you can encourage customers to make additional purchases, and increase the overall revenue of your e-commerce store. Give it a try and see how it works for your store!
FAQs
What are related products on WooCommerce order emails?
Related products on WooCommerce order emails are additional products that are shown to customers based on their previous purchases, in order to encourage them to make additional purchases.
What criteria can I use to display related products on WooCommerce order emails?
You can choose to display related products based on a variety of criteria, such as product category, tag, or even a specific product ID.
Will displaying related products on WooCommerce order emails increase sales?
Showing related products on WooCommerce order emails can be a powerful way to promote additional products and encourage customers to make additional purchases, which can increase sales and revenue for your e-commerce store.