Guest User

Untitled

a guest
Jan 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. <?php
  2. add_action( 'woocommerce_email_order_meta', 'ts_email', 10, 4 );
  3. function ts_email( $order, $sent_to_admin, $plain_text, $email ) {
  4. $items = $order->get_items();
  5.  
  6. foreach ($items as $key => $item) {
  7. $product_name = $item['name'];
  8. $product_id = $item['product_id'];
  9. $terms = get_the_terms( $product_id, 'product_cat' );
  10.  
  11. $args = array(
  12. 'post_type' => 'product',
  13. 'posts_per_page' => 10,
  14. 'product_cat' => $terms[0]->slug
  15. );
  16.  
  17. $loop = new WP_Query( $args );
  18. echo 'Here are few more products based on your recent purchase';
  19.  
  20. while ( $loop->have_posts() ) : $loop->the_post();
  21. global $product;
  22. echo '<br><a href="'.get_permalink().'">' . get_the_title().'</a>';
  23. endwhile;
  24.  
  25. wp_reset_query();
  26. }
  27. }
Add Comment
Please, Sign In to add comment