當 woocommerce 產品被保存時,我需要保存一些選項。
有什么辦法嗎?
uj5u.com熱心網友回復:
你可以使用save_post動作鉤子!
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);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/334765.html
標籤:php WordPress的 求购 钩子商务
下一篇:json編碼特定物件的屬性
