编辑产品帖子时挂钩

时间:2016-12-12 19:49:52

标签: php wordpress woocommerce

我已经尝试了几种不成功的方法来获得一个钩子选项,只有编辑后产品没有添加,我正在使用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 个答案:

答案 0 :(得分: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