While product recommendations influence customers to reorder related products, there are many other ways to display upsell products on different parts of the site, like sidebars, cart pages, or product pages. In this post, let’s customize to show these upsell products on the My Account Orders page for ‘processing’ order status as well.
Yes, you hear it right. Customers will mostly check their processing orders, and placing upsell products here will motivate them to purchase the recommended products.
Note: To test the output make sure that the products ordered have been configured with upsell products. To know how to link upsell products to a specific product, get a quick view by looking into the output section of this link.
Solution: Upsell Product Suggestions based on Order Status
The code snippet will add the related products for ‘processing’ order status on the view order page.
add_action( 'woocommerce_view_order', 'ts_upsell_on_processing_orders', 3 ); function ts_upsell_on_processing_orders( $order_id ) { $order = wc_get_order( $order_id ); // Check if the order status is 'processing' if ( $order && 'processing' === $order->get_status() ) { $cross_ids = array(); $items = $order->get_items(); foreach ( $items as $item ) { $product_crosssell_ids = get_post_meta( $item->get_product_id(), '_crosssell_ids', true ); if ( is_array($product_crosssell_ids) && !empty($product_crosssell_ids) ) { $cross_ids = array_unique( array_merge( $product_crosssell_ids, $cross_ids ) ); } } if ( !empty( $cross_ids ) ) { $upsell_cross = new WP_Query( array( 'post_type' => array( 'product', 'product_variation' ), 'post_status' => 'publish', 'post__in' => $cross_ids, 'orderby' => 'post__in' ) ); if ( $upsell_cross->have_posts() ) { echo '<section class="upsell-cross-products"><h2>Present for you!</h2><div class="woocommerce columns-3">'; woocommerce_product_loop_start(); while ( $upsell_cross->have_posts() ) : $upsell_cross->the_post(); $product = wc_get_product( $upsell_cross->post->ID ); if ( $product->is_type( 'variable' ) ) { continue; } if ( !$product->is_in_stock() ) { continue; } wc_get_template_part( 'content', 'product' ); endwhile; woocommerce_product_loop_end(); woocommerce_reset_loop(); wp_reset_postdata(); echo '</div></section>'; } } } }
Output
When a customer views their processing orders from the “My Account” orders page, if there are any related products (cross-sell products) associated with those orders, they will be displayed under a section “Related Products”.
We have a lot more WooCommerce My Account Page Customizations covered for you. Take a look at it to deliver a personalized experience to your customers.