Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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();
- }
- }
Add Comment
Please, Sign In to add comment