public function onBeforeSendMailAttachment{$type}(array &$attachments, object $data) : bool

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 onBeforeSendMailAttachmentCustomer.

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

&$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.

Return Value

Boolean. Use false to prevent the e-mail sending.


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:
 * onBeforeSendMailAttachment[TYPE]
 *
 * @param   array    &$attachments  An array of files to attach.
 * @param   object   $order         The appointment details.
 *
 * @return  boolean  False to prevent the e-mail sending.
 */
public function onBeforeSendMailAttachmentCustomer(&$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 attachments, 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 true;
}

Changelog

VersionDescription
1.7 Introduced.
Last Update: 2021-10-08 13:17
Helpful?
This site uses cookies. By continuing to browse you accept their use. Further information