如何在电子邮件中显示ACF插件字段中的值?

时间:2017-12-11 作者:Nick

电子邮件仅显示订单标题。自定义字段中的所有值均为空。。。。。

add_action( \'save_post\', \'my_project_updated_send_email\' );
function my_project_updated_send_email( $post_id ) {

        if ( wp_is_post_revision( $post_id ) || get_post($post_id)->post_status != \'publish\' )
            return;

        $post_title = get_the_title( $post_id );

        $course_name = get_field(\'course_name\',$post_id,false);

        $order_status =  get_field(\'order_status\',$post_id,false);

        $order_price = get_field(\'order_cost\',$post_id,false);

        $subject = \'New course have been created\';

        $message = "New course have been created:\\n\\n";
        $message .= "Order number: " . $post_title . "\\n" .  "Course name: " . $course_name . "\\n" . "Course price: " .$order_price . "\\n" . "Order status: " . $order_status ;

        wp_mail( get_option(\'admin_email\'), $subject, $message );
    }

1 个回复
最合适的回答,由SO网友:Nick 整理而成

这是按功能和检查顺序排列的:

 if(is_user_logged_in()){
        $current_user = wp_get_current_user();
    }
    else {
        $user_id = get_post_field( \'post_author\', $post_id );
        $current_user = get_userdata($user_id);
    }

结束