Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 发布帖子时,WP/Woo向自定义元收件人发送电子邮件_Wordpress_Woocommerce - Fatal编程技术网

Wordpress 发布帖子时,WP/Woo向自定义元收件人发送电子邮件

Wordpress 发布帖子时,WP/Woo向自定义元收件人发送电子邮件,wordpress,woocommerce,Wordpress,Woocommerce,我想在woo新产品发布后发送一封电子邮件。收件人电子邮件将添加到产品中的自定义元中。下面是到目前为止我在functions.php中的内容。如果我在功能中添加手动电子邮件,它会工作,但不幸的是,我无法获得帖子元。这是因为该功能是在产品正在保存/尚未保存时触发的吗?我怎样才能做到这一点 function set_mail_html_content_type() { return 'text/html'; } function notify_owner($post_id) { if

我想在woo新产品发布后发送一封电子邮件。收件人电子邮件将添加到产品中的自定义元中。下面是到目前为止我在functions.php中的内容。如果我在功能中添加手动电子邮件,它会工作,但不幸的是,我无法获得帖子元。这是因为该功能是在产品正在保存/尚未保存时触发的吗?我怎样才能做到这一点

function set_mail_html_content_type() {
    return 'text/html';
}
function notify_owner($post_id) {
    if ( get_post_type($post_id) == 'product' ) {
        $post = get_post($post_id);
        $owner_email = get_post_meta($post_id, 'my_custom_meta_here', true);
        $subject = "Hello";
        $message = "<p>Message goes here.</p>";
        add_filter('wp_mail_content_type', 'set_mail_html_content_type');
        wp_mail($owner_email, $subject, $message);
        remove_filter('wp_mail_content_type', 'set_mail_html_content_type');
    }
}
add_action('pending_to_publish', 'notify_owner');
add_action('draft_to_publish', 'notify_owner');
add_action('future_to_publish', 'notify_owner');
add_action('private_to_publish', 'notify_owner');
add_action('auto-draft_to_publish', 'notify_owner');

用于回调函数的转换post状态操作钩子将
$post
用作
WP\u post
对象,但您使用的
$post\u id
是错误的。因此,对于您的案例,您可以使用以下选项:

1.执行动作挂钩

函数集\邮件\ html\内容\类型(){
返回“text/html”;
}
函数通知所有者($post){
如果($post->post_type=='product'){
$owner\u email=get\u post\u meta($post->ID,'my\u custom\u meta\u here',true);
$subject=“你好”;
$message=“消息在此处显示。

”; 添加过滤器(“wp邮件内容类型”、“设置邮件内容类型”); wp_邮件($owner_email,$subject,$message); 删除过滤器(“wp邮件内容类型”、“设置邮件内容类型”); } } 添加行动(“待发布”、“通知所有者”); 添加行动(“发布草案”、“通知所有者”); 添加行动(“未来发布”、“通知所有者”); 添加行动(“私有发布”、“通知所有者”); 添加操作(“自动起草到发布”、“通知所有者”);
2.执行动作挂钩

函数集\邮件\ html\内容\类型(){
返回“text/html”;
}
函数通知所有者($post){
$owner\u email=get\u post\u meta($post->ID,'my\u custom\u meta\u here',true);
$subject=“你好”;
$message=“消息在此处显示。

”; 添加过滤器(“wp邮件内容类型”、“设置邮件内容类型”); wp_邮件($owner_email,$subject,$message); 删除过滤器(“wp邮件内容类型”、“设置邮件内容类型”); } 添加行动(“发布产品”、“通知所有者”);
global $post;
$owner_email = get_post_meta($post->ID, 'my_custom_meta_here', true);
$owner_email = get_post_meta(get_the_ID(), 'my_custom_meta_here', true);