3
WooCommerce在創建新訂單時創建新帖子shop_order
帖子類型。所以我想用wordpress save_post
動作鉤發送訂單通知郵件。WooCommerce - 通過「save_post」掛鉤更新訂單時發送通知電子郵件
我寫了下面的代碼:
add_action('save_post', 'notify_shop_owner_new_order', 10, 3);
function notify_shop_owner_new_order($post_ID, $post) {
if($post->post_type == 'shop_order') {
$headers = 'From: foo <[email protected]>';
$to = '[email protected]';
$subject = sprintf('New Order Received');
$message = sprintf ('Hello, musa ! Your have received a new order from .Check it out here :');
wp_mail($to, $subject, $message, $headers);
}
}
但它不工作。
如果下面我用不用是檢查型工作原理:
add_action('save_post', 'notify_shop_owner_new_order', 10, 3);
function notify_shop_owner_new_order($post_ID, $post) {
$headers = 'From: foo <[email protected]>';
$to = '[email protected]';
$subject = sprintf('New Order Received');
$message = sprintf ('Hello, musa ! Your have received a new order from .Check it out here :');
wp_mail($to, $subject, $message, $headers);
}
我不明白是什麼問題。我需要使用功能參數$post
和$post_id
來獲得帖子鏈接。
任何幫助?
感謝
你爲什麼不使用默認的woocommerce訂單通知? –
某些自定義帖子類型正在被註冊爲「public」設置爲false。 –
請檢查'$ post-> post_status' –