Hi,
I'm trying to display the products for a certain tag in the email for new order in wooCommerce. For example, I want that when a client buys a product with a certain tag, all the products that have that tag to be added automatically to the order email too.
For now I achieved to display the tag in the email but not the products that have that tag. I don't know how get the products that belongs to that tag and add them to the cart to so I can display them in the email.
Any help as small as it may be, it is very welcomed, please. I'm a bit stuck. I'm not very skilled in php...
Thank you very much
function email_products_per_tag( $order, $item ) {
$items = $order->get_items();
foreach ( $items as $item ) {
$terms = wp_get_post_terms( $item['product_id'], 'product_tag' );
foreach($terms as $term){
$term_names[] = $term->name; // Product tag Name
// $item2 = 'product_tag'=> ; // not very sure about this line...
}
}
}
add_action( 'woocommerce_email_after_order_table', 'email_products_per_tag', 10, 4 );