Skip to content

Instantly share code, notes, and snippets.

@rashmimalpande
Created January 10, 2018 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rashmimalpande/3ac08670357551d1665123dd588c6b0f to your computer and use it in GitHub Desktop.
Save rashmimalpande/3ac08670357551d1665123dd588c6b0f to your computer and use it in GitHub Desktop.
<?php
add_action( 'woocommerce_email_order_meta', 'ts_email', 10, 4 );
function ts_email( $order, $sent_to_admin, $plain_text, $email ) {
$items = $order->get_items();
foreach ($items as $key => $item) {
$product_name = $item['name'];
$product_id = $item['product_id'];
$terms = get_the_terms( $product_id, 'product_cat' );
$args = array(
'post_type' => 'product',
'posts_per_page' => 10,
'product_cat' => $terms[0]->slug
);
$loop = new WP_Query( $args );
echo 'Here are few more products based on your recent purchase';
while ( $loop->have_posts() ) : $loop->the_post();
global $product;
echo '<br><a href="'.get_permalink().'">' . get_the_title().'</a>';
endwhile;
wp_reset_query();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment