public function onToggleUserProfileFields(array &$allowed, object $customer) : void

Fires before displaying the form to edit the user billing details.


Description

Trigger hook to toggle the visibility of certain fields from the User Profile page. It is possible to access this section from the All Orders page, by clicking the My Profile button.

In example, by using the code below, the user profile won't display the SSN field anymore.

$allowed['ssn'] = false;
// or
unset($allowed['ssn']);

Parameters

&$allowed

(array)  An associative array containing all the allowed fields, where the key is the field identifier and the value represents its visibility.

  • avatar - the profile image of the user;
  • country - the dropdown to pick the country;
  • state - the text field to enter the state/province;
  • city - the text field to enter the city name;
  • address - the text field to enter the address field;
  • address2 - the text field to enter an additional information of the address;
  • zip - the text field to enter the ZIP code;
  • company - the text field to enter the company name;
  • vatnum - the text field to enter the VAT number;
  • ssn - the text field to enter the SSN/Fiscal Code.

It is not possible to hide the following fields: name, e-mail and phone number.

Assigning new attributes to the array will have no effect.

$customer

(object)  The details of the currently logged-in user.

Return Value

None.


Example

The following example hides the SSN field only if empty.

/**
 *  Trigger hook to toggle the visibility of certain fields.
 *
 * @param   array    &$allowed  An array of allowed fields.
 * @param   object   $customer  The customer details.
 *
 * @return  void
 */
public function onToggleUserProfileFields(&$allowed, $customer)
{
    // check whether the SSN field is empty
    if (empty($customer->ssn))
    {
        // hide field
        $allowed['ssn'] = false;
    }
}

Changelog

VersionDescription
1.7 Introduced.
Last Update: 2021-10-11 10:15
Helpful?