English (United Kingdom)
Knowledge Base  >  Vik Appointments  >  Hooks  >  Fields  >  Mailing Subscription

apply_filters( 'vikappointments_display_mailing_subscription_input', string $html, object $user )

Fires while binding the values of the custom fields.


Description

Trigger hook to retrieve an optional field that could be used to confirm the subscription to a mailing list.

This event SHOULD NOT be used to dynamically add generic custom fields, which MUST be created from the configuration panel of VikAppointments or through the vikappointments_before_register_custom_fields hook.


Parameters

$html

(string)  The HTML to display as last field.

$user

(object)  An object holding the user details.


Example

The example below displays a checkbox that can be used to start/keep a mailing subscription.

NOTE: the management of the subscription should be made by using a different plugin.

/**
 * Trigger event to retrieve an optional field that could be used
 * to confirm the subscription to a mailing list.
 *
 * @param  string  $html  The HTML to display.
 * @param  object  $user  The user details.
 */
add_filter('vikappointments_display_mailing_subscription_input', function($html, $user)
{
    $subsribed = false;

    /**
     * @todo check if the customer is already subscribed to a mailing list
     */

    if ($subscribed)
    {
        // auto-check subscription field
        $checked = 'checked="checked"';
        $label   = __('I want to continue to be subscribed to the newsletter', 'my-plugin');
    }
    else
    {
        // leave subscription field unchecked
        $checked = '';
        $label   = __('I would like to subscribe to the newsletter (optional)', 'my-plugin');
    }

    // build field
    $field = '<input type="checkbox" name="subscr_accept" value="1" id="subscr_accept" ' . $checked . ' />'
        . "\n"
        . '<label for="subscr_accept">' . $label . '</label>';

    return $field;
}, 10, 2);

Changelog

Version Description
1.2 Changed $user argument from array to object.
1.0 Introduced.
Last Update: 2021-10-08
Helpful?