shop_order
当创建帖子类型的新订单时,WooCommerce 会创建一个新帖子。所以我想使用 wordpresssave_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 <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
获取帖子链接。
有什么帮助吗?
谢谢