如何排除 WooCommerce 结帐发送用户个人资料更改电子邮件?

How can I exclude WooCommerce checkout from sending user profile change emails?

我们有一家连接到商品管理软件的商店。它通过 csv (WP All Export) 导出数据。

现在我们有一个功能,可以在配置文件数据更改时用文本填充用户描述字段。

只有具有此文本的用户才会导出到 csv 中,一旦导出,文本就会消失,直到下一次更改才会导出。它还会在数据更改时触发电子邮件。

问题是: 每次用户订购东西时也会发送此电子邮件,即使他的个人资料数据保持不变。必须避免这种情况。

有没有办法阻止结帐触发此电子邮件?

提到的功能如下:

function my_profile_update( $user_id ) {    
    
    if (!defined( 'WP_IMPORTING' ) ) { 
    
        $user_geaendert = get_user_meta( $user_id, 'user_geaendert', false );

        if (!strpos($user_geaendert, 'Export')) {

            update_user_meta( $user_id, 'description', 'seit letztem Export geändert ' . date("Y-m-d H:i:s"));          
            
            $to = 'email@email.de';
            $subject = "Benutzerdaten geändert";
            $message =  'Benutzer mit der ID '.$user_id.' hat seine Daten geändert. domain.com/wp-admin/user-edit.php?user_id='.$user_id;       
            
            wp_mail($to, $subject, $message);
            
        }
    }   else {
        
            update_user_meta( $user_id, 'description', '');
    }
}
add_action( 'profile_update', 'my_profile_update' );
//add_action( 'edit_user_profile_update', 'my_profile_update' );
//add_action( 'personal_options_update', 'my_profile_update' );


function user_role_update( $user_id, $new_role ) {
        
    
        $site_url = get_bloginfo('wpurl');  
        $user_info = get_userdata( $user_id );
    
    
        $user_meta  =   get_userdata($user_id); 
        $user_roles =   $user_meta->roles; 
        
        if (in_array("customer", $user_roles)){
            $user_roles = 'customer';
        }
    
    
        if (get_user_meta( $user_id, 'anu_new_user_pass' , true ) != '' && $user_roles == 'customer') {
            
            $to = $user_info->user_email;
            $subject = "Freischaltung bei XXX";
            $message = "Sehr geehrte/r Nutzer/in,

    Ihr Benutzerkonto auf xxx.de wurde nun von uns freigeschaltet.

    Bitte loggen Sie sich mit Ihren Zugangsdaten ein. Ihre Kundennummer finden Sie in Ihrem Benutzerprofil.<br><br>
    Login: domain.com/mein-konto/ <br>
    Benutzername: ".get_user_meta( $user_id, 'nickname' , true ) . "<br>
    Passwort: ".get_user_meta( $user_id, 'anu_new_user_pass' , true );
            
            
            wp_mail($to, $subject, $message);
            
        }
        
}
add_action( 'set_user_role', 'user_role_update', 10, 2);
  • 已添加 is_checkout() - Returns 查看结帐页面时为真。
  • 代码已通过添加注释和解释进行清理
function my_profile_update( $user_id ) {    
    // NOT defined
    if ( ! defined( 'WP_IMPORTING' ) ) { 
        // Get user meta
        $user_geaendert = get_user_meta( $user_id, 'user_geaendert', false );

        // Find the position of the first occurrence of a substring in a string, Returns FALSE if the needle was not found.
        if ( ! strpos( $user_geaendert, 'Export' ) ) {
            // Update user meta
            update_user_meta( $user_id, 'description', 'seit letztem Export geändert ' . date( 'Y-m-d H:i:s' ) ); 

            // NOT on the checkout page
            if ( ! is_checkout() ) {       
                // Mail parameters
                $to = 'email@email.de';
                $subject = "Benutzerdaten geändert";
                $message =  'Benutzer mit der ID ' . $user_id . ' hat seine Daten geändert. domain.com/wp-admin/user-edit.php?user_id=' . $user_id;
                
                // Sends an email, similar to PHP’s mail function.
                wp_mail( $to, $subject, $message );
            }               
        }
    } else {
        // Update user meta
        update_user_meta( $user_id, 'description', '');
    }
}
add_action( 'profile_update', 'my_profile_update' );