WordPress post update AFTER ACF field updates

前端 未结 2 1228
天涯浪人
天涯浪人 2021-01-26 12:04

The code below sends out an email every time I (change the STATUS field and then) safe/update the post. But it\'s not working the way I want and I know whats\'s wrong:

T

相关标签:
2条回答
  • 2021-01-26 12:31

    The complete working code (for those who like to use):

    add_action('acf/save_post', 'yl_send_booking_email_after_status_update', 5);
    function yl_send_booking_email_after_status_update( $post_id ) {
    
        // Get submitted values.
        $values = $_POST['acf'];
    
        // Check if a specific value was updated.
        if ( isset($_POST['acf']['field_5ed8117407663']) ) {
    
            $booking_status = $_POST['acf']['field_5ed8117407663'];
            $send_email     = $_POST['acf']['field_5ed81174076ac'];
    
            if ( $send_email == 'yes' ) {
    
                $to = $_POST['acf']['field_5ed41758ed4b5'];
    
                if ( $booking_status == 'confirmed' ) {
                    $subject = $_POST['acf']['field_5ed81174076f2'];
                    $message = $_POST['acf']['field_5ed8117407741'];
                } elseif ( $booking_status == 'changed' ) {
                    $subject = $_POST['acf']['field_5ed8117407788'];
                    $message = $_POST['acf']['field_5ed81174077df'];
                } elseif ( $booking_status == 'canceled by guest' ) {
                    $subject = $_POST['acf']['field_5ed8117407829'];
                    $message = $_POST['acf']['field_5ed8117407870'];
                } else {
                    $subject = $_POST['acf']['field_5ed81174078b7'];
                    $message = $_POST['acf']['field_5ed81174078fd'];
                }
    
                $headers = array
                    (
                    'From: ' . get_bloginfo('name') . ' <' . get_bloginfo('admin_email') . '>',
                    'Bcc: ' . get_bloginfo('admin_email'),
                    'X-Mailer: PHP/' . phpversion(),
                    'MIME-Version: 1.0',
                    'Content-type: text/html; charset=iso-8859-1'
                );
                $headers = implode( "\r\n" , $headers );
    
                wp_mail( $to, $subject, $message, $headers );
    
            }
    
        }
    }
    
    0 讨论(0)
  • 2021-01-26 12:36

    UPDATE 2 Got it working. Code below:

    add_action('acf/save_post', 'yl_send_booking_email_after_status_update', 5);
    function yl_send_booking_email_after_status_update( $post_id ) {
    
        // Get submitted values.
        $values = $_POST['acf'];
    
        // Check if a specific value was updated.
        if( isset($_POST['acf']['field_5ed8117407663']) ) {
    
            $to         = $_POST['acf']['field_5ed41758ed4b5'];
            $subject    = $_POST['acf']['field_5ed81174076f2'];
            $message    = $_POST['acf']['field_5ed8117407741'];
    
            $headers = array
                (
                'From: ' . get_bloginfo('name') . ' <' . get_bloginfo('admin_email') . '>',
                'Bcc: ' . get_bloginfo('admin_email'),
                'X-Mailer: PHP/' . phpversion(),
                'MIME-Version: 1.0',
                'Content-type: text/html; charset=iso-8859-1'
            );
            $headers = implode( "\r\n" , $headers );
    
            wp_mail( $to, $subject, $message, $headers );
    
        }
    }
    
    0 讨论(0)
提交回复
热议问题