Search
 
SCRIPT & CODE EXAMPLE
 

PHP

if cat 1 then send email woocommerce functions

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

PREVIOUS NEXT
Code Example
Php :: php radian to cosine 
Php :: remove dashboard mya ccount 
Php :: laravel email forgot password 
Php :: Laravel group collection and sort by the biggest value 
Php :: SymfonyStyle 
Php :: registerd navigations file uploadid 
Php :: undefined offset: 7 in d:xamphtdocsphpfunctionfunction.php on line 137 
Php :: How to send JSON format data in postman to django models that have a foreign key to another model 
Php :: codeigniter validate integer in php 
Php :: retrievemultipleimage from database in laravel 
Php :: SQLSTATE[42S02]: Base table or view not found: 1146 Table many to many in laravel 
Php :: short isset and not empty php 8 
Php :: How to validate Envato Purchase Code in PHP 
Php :: parameterize constructor mpdf php 
Php :: joomla k2 api 
Php :: filter elementor 
Php :: Laravel Dropzone Attachment Required is not working as expected 
Php :: display rounded price get_price php 
Php :: require_once in class php 
Php :: null coalesce operator in php (laravel) 
Php :: wp retrieve acf by category name 
Php :: how to prevent iframe for your site by PHP 
Php :: php store html in varible 
Php :: Call to undefined function can() laravel spatie 
Php :: when user click back clear form data laravel 
Php :: objeto php em sessão 
Php :: @parent, @include, @show blade in laravel 
Php :: how to auto calculate price in mysql table and php 
Php :: return false inside loop of function php 
Php :: elasticsearch php search date range 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =