在 woocommerce 保存产品时执行操作
Do an action when woocomerce saves a product
我需要在保存 woocommerce 产品时保存一些选项。
有什么办法吗?
您可以使用 save_post
动作挂钩!
保存产品后,您可以使用此样板执行自定义工作!
add_action('save_post', 'do_some_custom_work');
function do_some_custom_work( $post_id )
{
if ('product' == get_post_type($post_id)) {
// Do what is necessary here!
die('You hit the right hook!!!');
}
}
注:
- 除了
$post_ID
之外,您还可以将 $post
和 $update
传递给您的回调函数。请阅读文档了解更多详情!
add_action('save_post', 'do_some_custom_work', 10, 3);
function do_some_custom_work( $post_id, $post, $update )
{
if ('product' == get_post_type($post_id)) {
// Do what is necessary here!
die('You hit the right hook!!! This is the product id: ' . $post->ID);
}
}
我需要在保存 woocommerce 产品时保存一些选项。
有什么办法吗?
您可以使用 save_post
动作挂钩!
保存产品后,您可以使用此样板执行自定义工作!
add_action('save_post', 'do_some_custom_work');
function do_some_custom_work( $post_id )
{
if ('product' == get_post_type($post_id)) {
// Do what is necessary here!
die('You hit the right hook!!!');
}
}
注:
- 除了
$post_ID
之外,您还可以将$post
和$update
传递给您的回调函数。请阅读文档了解更多详情!
add_action('save_post', 'do_some_custom_work', 10, 3);
function do_some_custom_work( $post_id, $post, $update )
{
if ('product' == get_post_type($post_id)) {
// Do what is necessary here!
die('You hit the right hook!!! This is the product id: ' . $post->ID);
}
}