【发布时间】:2017-04-20 22:27:45
【问题描述】:
当创建 shop_order 帖子类型的新订单时,WooCommerce 会创建一个新帖子。所以我想使用 wordpress save_post action hook 发送订单通知邮件。
我写了以下代码:
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 <foo@bar.com>';
$to = 'foo@bar.com';
$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 <foo@bar.com>';
$to = 'foo@bar.com';
$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
标签: php wordpress woocommerce orders email-notifications