• Resolved Dennis Dallau

    (@yorlinqnl)


    I am working on a booking system and I use a select field (STATUS) to activate the form email actions.

    When a new booking is made it will trigger a ‘CREATE POST action’, a ‘BOOKING RECEIVED email to the guest’ and a ‘NEW BOOKING email to admin’. Great so far but I would like other created email actions to be triggered after I update the post with the booking details.

    F.I. When I set the status field to CONFIRMED and update the post I would like to trigger a ‘BOOKING CONFIRMED email to guest’ action.

    I have tried tons of things and can’t get it to work. Let me give what I have so far:

    // Add bookings as custom post type
    function yl_custom_post_type_bookings() {
     
    	$labels = array(
    		'name'                => _x( 'Bookings', 'Post Type General Name', 'yorlinq' ),
    		'singular_name'       => _x( 'Booking', 'Post Type Singular Name', 'yorlinq' ),
    		'menu_name'           => __( 'Bookings', 'yorlinq' ),
    		'parent_item_colon'   => __( 'Parent Booking:', 'yorlinq' ),
    		'all_items'           => __( 'All Bookings', 'yorlinq' ),
    		'view_item'           => __( 'View Bookings', 'yorlinq' ),
    		'add_new_item'        => __( 'Add New Booking', 'yorlinq' ),
    		'add_new'             => __( 'Add New', 'yorlinq' ),
    		'edit_item'           => __( 'Edit Booking', 'yorlinq' ),
    		'update_item'         => __( 'Update Booking', 'yorlinq' ),
    		'search_items'        => __( 'Search Booking', 'yorlinq' ),
    		'not_found'           => __( 'Not found', 'yorlinq' ),
    		'not_found_in_trash'  => __( 'Not found in Trash', 'yorlinq' ),
    	);
    	$args = array(
    		'label'               => __( 'booking', 'yorlinq' ),
    		'description'         => __( 'Post Type for Bookings', 'yorlinq' ),
    		'labels'              => $labels,
    		'supports'            => array( 'title', 'editor', 'author', 'thumbnail', 'custom-fields', ),
    		'hierarchical'        => false,
    		'rewrite'             => array('slug' => '/reserveringen'),
    		'public'              => true,
    		'show_ui'             => true,
    		'show_in_menu'        => true,
    		'show_in_nav_menus'   => true,
    		'show_in_admin_bar'   => true,
    		'menu_position'       => 45,
    		'menu_icon'           => 'dashicons-calendar-alt',
    		'can_export'          => true,
    		'has_archive'         => true,
    		'exclude_from_search' => false,
    		'publicly_queryable'  => true,
    		'capability_type'     => 'page',
    	);
    	register_post_type( 'booking', $args );
     
    }
     
    // Hook into the 'init' action
    add_action( 'init', 'yl_custom_post_type_bookings', 0 );
    
    // Email action: New booking to admin
    function yl_send_admin_email_new_booking($args, $form, $action) {
        // Retrieve user input
        $status = get_field('bookings_field_status');
        if ($status === 'pending') {
            return $args;
        }
    }
    
    add_filter('acfe/form/submit/email_args/action=bookings-email-admin-new-booking', 'yl_send_admin_email_new_booking', 10, 4);
    
    // Email action: Booking received to guest
    function yl_send_customer_email_status_pending($args, $form, $action) {
        // Retrieve user input
        $status = get_field('bookings_field_status');
        if ($status === 'pending') {
            return $args;
        }
    }
    
    add_filter('acfe/form/submit/email_args/action=bookings-email-customer-pending', 'yl_send_customer_email_status_pending', 10, 4);
    
    // Email action: Booking confirmed to guest
    function yl_send_customer_email_status_confirmed($args, $form, $action) {
    	// Retrieve user input
    	$status = get_field('bookings_field_status');
    	if ($status === 'confirmed') {
    		return $args;
        }
    }
    
    add_filter('acfe/form/submit/email_args/action=bookings-email-customer-confirmed', 'yl_send_customer_email_status_confirmed', 10, 4);
    
    // Email action: Booking changed to guest
    function yl_send_customer_email_status_changed($args, $form, $action) {
        // Retrieve user input
        $status = get_field('bookings_field_status');
        if ($status === 'changed') {
            return $args;
        }
    }
    
    add_filter('acfe/form/submit/email_args/action=bookings-email-customer-changed', 'yl_send_customer_email_status_changed', 10, 4);
    
    // Email action: Booking canceled by guest
    function yl_send_customer_email_status_canceled_by_guest($args, $form, $action) {
        // Retrieve user input
        $status = get_field('bookings_field_status');
        if ($status === 'canceled by guest') {
            return $args;
        }
    }
    
    add_filter('acfe/form/submit/email_args/action=bookings-email-customer-canceled-by-guest', 'yl_send_customer_email_status_canceled_by_guest', 10, 4);
    
    // Email action: Booking canceled by us
    function yl_send_customer_email_status_canceled_by_us($args, $form, $action) {
        // Retrieve user input
        $status = get_field('bookings_field_status');
        if ($status === 'canceled by us') {
            return $args;
        }
    }
    
    add_filter('acfe/form/submit/email_args/action=bookings-email-customer-canceled-by-us', 'yl_send_customer_email_status_canceled_by_us', 10, 4);

    Hope you can help me out. Surely I will add the working code afterwards here so others can use this.

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Trigger email action after updating (custom) post’ is closed to new replies.