English (United Kingdom)
Knowledge Base  >  Vik Restaurants  >  Hooks  >  Purchase  >  Take-Away  >  Prepare Fields

do_action_ref_array( 'vikrestaurants_prepare_fields_save_order', array &$fields, array &$args )

Fires after fetching the custom fields set in request.


Description

Trigger hook to manipulate the custom fields array and the billing information of the customer, extrapolated through the rules of the custom fields.

In case you are using a third-party plugin to collect the details of the customer, it is possible to inject into the $args array all the information that you wish to register.


Parameters

&$fields

(array)  An associative array containing the custom fields entered by the customer. The array keys match the names of the custom fields, the values match the details specified by the customer instead.

&$args

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


Example

Assuming that no custom fields are used, the system auto-injects the phone number of the customer into the array holding the billing details.

/**
 * Trigger event to manipulate the custom fields array and the
 * billing information of the customer, extrapolated from the rules
 * of the custom fields.
 *
 * @param  array  &$fields  The custom fields values.
 * @param  array  &$args    The billing array.
 */
add_action('vikrestaurants_prepare_fields_save_order', function(&$fields, &$args) {
    // get details of the current user
    $user = wp_get_current_user();

    if (!$user) {
        return false;
    }

    // assume that the phone number is contained within the details of the currently logged-in user
    if (empty($args['purchaser_phone'])) {
        $args['purchaser_phone'] = $user->phone;
    }
}, 10, 2);

Changelog

Version Description
1.3 Introduced.
Last Update: 2023-12-27
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.