有没有办法在每次用户输入WooCommerce后端的产品时触发功能


is there any way to trigger a function everytime a user enter in a product of woocommerce's backend?

我想要一个函数,每当wordpress的用户(后端(进入管理区域并进入产品帖子(修改它或类似(时触发。

我想知道用户等等...(我已经有那部分了(

我不知道如何调用该函数。我正在使用woocommerce。

到目前为止,我尝试的是:

function product_cpt_columns($columns) {
        echo "test";
    }
    add_filter('manage_product_posts_columns' , 'product_cpt_columns');
在此

链接中引用 http://codex.wordpress.org/Plugin_API/Filter_Reference/manage_edit-post_type_columns

但是不起作用..我正在将其插入激活的插件主文件中。有什么想法吗?

谢谢。

据我所知,你用错了钩子。 每次创建或更新帖子时都会触发save_post

或者更具体地说,您可以使用仅在创建或更新产品帖子时触发的save_post_product

例如:

add_action( 'save_post_product', 'so_27303738_save_product' );
function so_27303738_save_product( $post_id ){
  if( has_term( 'bacon', 'product_cat', $post_id ) ){
     // do something special if the product category is bacon
  }
}