php - 编辑产品帖子时 Hook

标签 php wordpress woocommerce

当帖子产品仅被编辑而不添加时,我尝试了几种不成功的方法来获取 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/

相关文章:

php - 在订单详情中的订单项目表中显示产品元数据

ajax - WooCommerce 以编程方式从购物车中删除

wordpress - 如何排除将特定产品 ID 添加到 WooCommerce 中的数组中

css - H5 标签在页面之间显示不同的大小 - Wordpress 主题开发

php - MySQL数据库同步

php - 允许网站 URL 中的所有字符有哪些安全风险?

php - 如何确保视频已被观看

javascript - 如何根据条件更改 URL

asp.net - IIS7 上 WordPress 的 URL 重写

php - 如何使用 php/.htaccess 文件从 mysql 数据库中获取文件名来提供文件夹中的文件?