2016-12-12 8 views
1

投稿商品のみが編集されていないときにフックオプションを取得する方法がいくつか失敗しました。私はwoocommerceを使用しています。 私の主な試みです。商品の投稿が編集されたときにフック

add_action('updated_product_meta', 'my_product_edited'); 

function my_product_edited($post) { 

    if ($post->post_type == "product") { 
     $productId = $post->ID; 

     $args = array (
      'search' => 'myusername' 
     ); 

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

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

      global $post; 

      $post_title = get_the_title($post_id); 
      $tld_prod_url = esc_url(get_permalink($post->ID)); 
      $subject = "Product Updated Notification"; 

      foreach ($user_query->results as $user) { 

       $to = $user->user_email; 
       $body .= "The following product was updated: \n\n" . $post_title . "\n" . $tld_prod_url . "\n\nThanks" ; 

       wp_mail($to, $subject, $body); 
      } 

     } 

    } 

} 

答えて

1

フックはpost_updated命名されています

add_action('post_updated', 'my_product_edited'); 

function my_product_edited($post_id, $post_after, $post_before) { 

    // $post_after : Post as it is saved now in the DB  
    // $post_before : Post as it was before the update 
} 

Codexを参照してください。

+0

返信いただきありがとうございますが、私は投稿で編集を行うたびにメールを受け取ります。更新ボタンをクリックした後に通知を受け取る必要があります。ありがとう。 – ctovelox

+0

これは難しいです... wp-admin編集ページにjQueryコードを挿入して、追加のAJAXリクエスト "onclick"を実行することができます。代わりに、 '$ post_after'と' $ post_before'を比較して、電子メールを生成するためにどのプロパティを変更する必要があるかを定義することができます。 – giraff

関連する問題