Italian (Italy)
Knowledge Base  >  Vik Appointments  >  Hook  >  E-Mail  >  Before Send Attachment

apply_filters_ref_array( 'vikappointments_before_send_mail_attachment_{$type}', bool $sendarray &$attachments, object $data )

Fires while fetching the attachments to use for notification e-mails.


Description

Plugins can use this filter to manipulate at runtime the list of attachments to include within notification e-mails.

The dynamic portion of the hook name, $type, refers to the type of event that triggered the e-mail sending.
Here's a list of supported types:

  • customer
  • admin
  • cancellation
  • employee
  • waitlist
  • package
  • packadmin

This means that, for example, the notification e-mail sent to the customers will trigger a filter called vikappointments_before_send_mail_attachment_customer.

When registering an attachment, the file path should be set as a key of the array and the value should be 0 to auto-delete the file after sending the e-mail or 1 to always keep it.


Parameters

$send

(bool)  Use false to prevent the e-mail sending.

&$attachments

(array)  An associative array of attachments, where the key is the absolute path of the file and the value specifies whether the file is volatile or permanent.

$data

(mixed)  The entity to notify. In case of an appointment, the argument will be a VAPOrderAppointment object.

The hook might specify additional arguments, which can vary according to the current type.


Example

The example below explains the difference between volatile and permanent files.

/**
 * Triggers a filter to let the plugins be able to handle the attachments of the e-mail.
 *
 * The hook name is built as:
 * vikappointments_before_send_mail_attachment_[type]
 *
 * @param  boolean  $send          False to prevent the e-mail sending.
 * @param  array    &$attachments  An array of files to attach.
 * @param  object   $order         The appointment details.
 */
add_filter('vikappointments_before_send_mail_attachment_customer', function($send, &$attachments, $order)
{
    // create a new file and write there all the properties held by $order
    $tmp_path = dirname(__FILE__) . DIRECTORY_SEPARATOR . uniqid() . '.txt';
    $f = fopen($tmp_path, 'w');
    fwrite($f, print_r($order, true));
    fclose($f);
	
    // register file as volatile attachment, which will be auto-deleted after sending the e-mail
    $attachments[$tmp_path] = 0;
	
    // enter here the path of the file to include
    $permanent_file = 'path_to_file';

    // register a file as permanent attachment, which will be always kept in the file system
    $attachments[$permanent_file] = 1;

    return $send;
}, 10, 3);

Changelog

Version Description
1.2 Introduced.
Ultimo aggiornamento: 2023-04-06
Utile?