Jump to content

Get products that belong to a TAG


cimita

Recommended Posts

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 );

 

Edited by cimita
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.