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);
}
}
}
}
感谢您的回复,但每次我在帖子中进行任何类型的编辑时,我都会收到电子邮件。只有在点击更新按钮后,我才需要收到通知。谢谢。 – ctovelox
这很难......你可以注入jQuery代码到wp-admin编辑页面,执行一个额外的AJAX请求“onclick”。相反,您可以定义哪些属性需要更改才能生成电子邮件,比较'$ post_after'和'$ post_before'。 – giraff