Wenn CAT 1 dann E -Mail -WooCommerce -Funktionen senden

function action_woocommerce_email_before_order_table( $order, $sent_to_admin, $plain_text, $email ) {   
    // Only for order completed email 
    if ( $email->id == 'customer_completed_order' ) {
        // Booleans
        $cat_one = false;
        $cat_two = false;
        $cat_three = false;
        $cat_four = false;
        
        // Output
        $output = '';
        
        // Loop through order items
        foreach ( $order->get_items() as $item ) {
            // Product ID
            $product_id = $item->get_variation_id() > 0 ? $item->get_variation_id() : $item->get_product_id();

            // Has term (product category)
            if ( has_term( 'cat-one', 'product_cat', $product_id ) ) {
                $cat_one = true;
            }
            
            if ( has_term( 'cat-two', 'product_cat', $product_id ) ) {
                $cat_two = true;
            }
            
            if ( has_term( 'cat-three', 'product_cat', $product_id ) ) {
                $cat_three = true;
            }
            
            if ( has_term( 'cat-four', 'product_cat', $product_id ) ) {
                $cat_four = true;
            }
        }
        
        // 1. ONLY CAT-ONE
        if ( $cat_one ) {
            $output = "SOME TEXT";
            
            // 2. CAT-ONE and any other Category
            if ( $cat_two || $cat_three || $cat_four ) {
                $output = "SOME OTHER TEXT";
            }
        } else {
            // 3. ALL CATEGORIES EXCEPT CAT-ONE
            if ( $cat_two && $cat_three && $cat_four ) {
                $output = "ANOTHER TEXT";
            }           
        }
        
        // Output
        echo $output;
    }
}
add_action( 'woocommerce_email_before_order_table', 'action_woocommerce_email_before_order_table', 10, 4 );
Creepy Cat