[Appointments+] Include additional field in subject line?

Is it possible to include (the placeholder for) an additional field in the subject line of an email? This would help my client quite a lot.

  • Konstantinos Xenos
    • Rubber Duck Debugger

    Hey mpress ,

    You can add this mu-plugin to enable support for Additional Fields placeholders on email subjects.

    How to install:
    Always make sure to keep a backup of your site before changing/adding custom code.

    1] Navigate to your /wp-content/ directory and create a new one named mu-plugins if it doesn't exist.
    2] Inside the mu-plugins folder create a file named app-fields-in-subjects.php
    3] Edit the file and copy / paste this code snippet inside.

    <?php
    
    add_filter(
    	'wp_mail',
    	function( $args ) {
    		if( isset( $_POST['app_id'] ) && ! empty( $_POST['app_id'] ) ) {
    			$old_subject = $args['subject'];
    
    			if( array_key_exists( 'additional_fields', $_POST ) && ! empty( $_POST['additional_fields'] ) ) {
    				$fields = array();
    				$values = array();
    				foreach( $_POST['additional_fields'] as $key => $value ) {
    					$target_field = 'FIELD_' . strtoupper( $key );
    					array_push( $fields, $target_field );
    					array_push( $values, $value );
    				}
    
    				$args['subject'] = str_replace( $fields, $values, $old_subject );
    			}
    		}
    
    		return $args;
    	}
    );

    4] Save and close the file.
    5] The final path should look like /wp-content/mu-plugins/app-fields-in-subjects.php
    6] Everything should work after that automatically.

    If you add any of the additional fields placeholders in the Appointments -> Settings -> General / Notifications fields they should be automatically replaced.

    I've tested this extensively but as always setups might differ so tell me if you need further help with this!

    Regards,
    Konstantinos

  • Konstantinos Xenos
    • Rubber Duck Debugger

    Yes please mpress , it would be the best way so I can help out. Also as a note I'll create a "dummy" appointment with any user that you'll provide so I can invoke the e-mails and see what's being sent if that's ok.

    You can send me the information needed privately through our contact form at https://premium.wpmudev.org/contact/#i-have-a-different-question by following this example:

    Subject: "Attn: Konstantinos Xenos"
    
    - Admin login ( if Multisite please provide Super Admin details ):
    Admin Username:
    Admin Password:
    Login URL:
    
    - FTP credentials
    Hostname:
    Username:
    Password:
    Port:
    Key-File ( and password ) if needed
    
    - Link back to this thread for reference
    - Any other relevant URLs -or- information regarding the issue that was not included in this thread

    Regards,
    Konstantinos

  • Konstantinos Xenos
    • Rubber Duck Debugger

    Hi mpress ,

    I've taken another look and made some changes since it's a multisite ( I was testing on a single site ).

    The snippet should be working as expected now but please note that the fields will working on Confirmation & Removal e-mails only, not on Reminders as they are automated and they would require plugin changes for that part.

    Could you please give it another test yourself just to be sure if that covers the needs?

    Regards,
    Konstantinos

  • mpress
    • Code Wrangler

    Hi Konstantinos,

    I can confirm that it's working now. Thanks. But... I was in particular interested in seeing it working for the reminders, as these are sent 24hrs in advance to the facility dept/hosts, taking care of the coffee and tea...
    Now they have to actually look into the contents of the email. I was trying to avoid that.

    Anyway, I need to give this another thought. But you have done what I asked for, thanks very much for your help. I'll close this thread.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.