Created
January 10, 2018 13:06
-
-
Save rashmimalpande/3ac08670357551d1665123dd588c6b0f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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