当帖子产品仅被编辑而不添加时,我尝试了几种不成功的方法来获取 Hook 选项,我正在使用 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 );
}
}
}
}
最佳答案
该 Hook 名为 post_updated
:
add_action( 'post_updated', 'my_product_edited', 10, 3);
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 .
关于php - 编辑产品帖子时 Hook ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41108430/