2016-10-14 9 views
1

プラグインを使用して解決策を見つけようとしましたが、私が望むように機能しませんでした。または製品を更新することができます。WooCommerce電子メール通知新しい製品を追加するか、製品を更新するとすぐにすべての顧客に通知する

My機能

add_action('save_post', 'my_product_update'); 

function my_product_update($post) { 
    if($post->post_type == "product"){ 
     $pid=$post->ID; 

      // Send Email ? 

    } 
} 

答えて

0
// WP_User_Query arguments 
$args = array (
    'role' => 'customer', 
); 

// The User Query 
$user_query = new WP_User_Query($args); 

// The User Loop 
if (! empty($user_query->results)) { 
    foreach ($user_query->results as $user) { 

     $to = $user->user_email; 
     // create mail temelate and send mail 
     wp_mail($to, $subject, $message, $headers = '', $attachments = array()); 
    } 
} else { 
    // no users found 
} 
0

してくださいユーザーのカスタムポストタイプのためのワードプレスの次のアクションフック:

add_action('save_post_product', 'your_function_name'); 
add_action('publish_product', 'your_function_name'); 

function your_function_name($post_id) { 
    // do code here 
} 
+0

ニース、ありがとう。あなたはすべてのcustumersの電子メールを送信するアクションを知っていますか? – ctovelox

+0

すべてのユーザーに電子メールを送信するカスタムコードを記述する必要があります。私の別の答えをチェックしてください。 –

関連する問題