English (United Kingdom)
Knowledge Base  >  Vik Appointments  >  Hooks  >  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.
Last Update: 2023-04-06
Helpful?

This website uses cookies

This website uses cookies and similar technologies. Some of these technologies are necessary for the proper functioning of the website (Essential). Other technologies are used to evaluate user behavior (Analysis), to integrate external media or for advertising purposes. If you agree, these technologies are activated. For details, please refer to the privacy policy. From this same page you can also update/revoke your consent. If you do not give your consent, only cookies with essential functions will be activated.

We use technologies from the USA on our website. If you give your consent, you therefore consent at the same time to your data being transferred to the USA. We would like to point out that the USA does not have a level of data protection comparable to that of the EU and that any US company can be obliged by state authorities to hand over your data without you having any effective legal protection against this.