English (United Kingdom)
Knowledge Base  >  Vik Restaurants  >  Hooks  >  Mail  >  Notifications  >  Before Send Subject

apply_filters_ref_array( 'vikrestaurants_before_send_mail_subject_{$group}_{$type}', bool $sendstring &$subject, object $data )

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


Description

Plugins can use this filter to manipulate at runtime the subject to use for e-mail notifications.

The dynamic portion of the hook name, $group, refers to the section of the plugin sending the e-mail.
Here's a list of supported groups:

  • restaurant
  • takeaway

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 (restaurant & take-away)
  • admin (restaurant & take-away)
  • cancellation (restaurant & take-away)
  • review (take-away only)
  • stock (take-away only)

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


Parameters

$send

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

&$subject

(string)  The current subject of the e-mail. Since the argument is passed as reference, it is possible to manipulate it.

$data

(mixed)  The entity to notify. In case of a restaurant reservation, the argument will be a VREOrderRestaurant object.

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


Example

The example below uses a different e-mail subject depending on the status of the order. The new subject is applied only to the notification e-mail sent to the customers for take-away orders.

/**
 * Triggers a filter to let the plugins be able to handle the subject of the e-mail.
 *
 * The hook name is built as:
 * vikrestaurants_before_send_mail_subject_[restaurant|takeaway]_[type]
 *
 * @param  bool    $send      False to prevent the e-mail sending.
 * @param  string  &$subject  The current e-mail subject.
 * @param  object  $order     The take-away order details.
 */
add_filter('vikrestaurants_before_send_mail_subject_takeaway_customer', function($send, &$subject, $order) {
    if ($order->statusRole == 'APPROVED') {
        $subject = __('Your order has been confirmed', 'myplugin');
    } elseif ($order->statusRole == 'PENDING') {
        if ($order->payment) {
            $subject = __('Your order requires a payment', 'myplugin');
        } else {
            $subject = __('Your order is waiting for a manual approval', 'myplugin');
        }
    }

    return $send;
}, 10, 3);

Changelog

Version Description
1.0 Introduced.
Last Update: 2024-01-03
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.