Italian (Italy)
Knowledge Base  >  Vik Restaurants  >  Hooks  >  Campi  >  Mailing Subscription

apply_filters( 'vikrestaurants_display_mailing_subscription_input', string $fieldarray $user )

Fires after displaying the custom fields in the front-end.


Description

This filter can be used to display an optional field to confirm the subscription to a mailing list.

This hook SHOULD NOT be used to dynamically add generic custom fields, which MUST be created from the configuration panel of VikRestaurants.

IMPORTANT WARNING: This filter has been officially deprecated since the 1.3 release and will be no longer supported starting from the 1.4 version of VikRestaurants. You should rather use the other documented actions and filters to properly register new custom fields.


Parameters

$field

(string)  The HTML of the field to display.

$user

(array)  An associative array containing the details of the customer.


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

/**
 * Displays the input that will be used to confirm the subscription
 * to the the mailing lists.
 *
 * @param  string  $field  The HTML of the field to display.
 * @param  array   $user   The customer data.
 */
add_filter('vikrestaurants_display_mailing_subscription_input', function($field, $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', 'myplugin');
    }
    else
    {
        // leave subscription field unchecked
        $checked = '';
        $label   = __('I would like to subscribe to the newsletter (optional)', 'myplugin');
    }

    // 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.3 This filter has been officially deprecated and will be no longer supported starting from the 1.4 version.
1.0 Introduced.
Ultimo aggiornamento: 2023-12-28
Utile?
This site uses cookies. By continuing to browse you accept their use. Further information