Jump to content

Force users to update or complete informations like phone number, address..


Kelby

Recommended Posts

9 hours ago, Kelby said:

How to force users to update or complete informations like phone number, address.. ?

the quick way, before they've registered, would be to ensure that those client fields aren't optional during registration and/or ordering...

https://docs.whmcs.com/Other_Tab#Optional_Client_Profile_Fields

but if they've registered before you've made those changes to settings, then the next step depends on how thorough you want to be... you can certainly, once they log in, redirect them to to the contact details page and force them to complete the required fields before they can do anything else... hooks to do that, or similar, have been previously posted.

Link to comment
Share on other sites

  • 4 years later...
Posted (edited)
On 5/16/2020 at 6:52 PM, Kelby said:

Hello,

How to force users to update or complete informations like phone number, address.. ?

Thanks

I think this might help, a hook to prevent purchases from being made until some fields in the profile are completed. 

Adjust it according to your needs.

<?php

use WHMCS\ClientArea;
use WHMCS\Database\Capsule;

add_hook('ShoppingCartValidateCheckout', 1, function($vars) {

    $client = Menu::context('client');

    if (!$client) {
        return; // Cliente no logueado.
    }

    $clientId = $client->id;

    // 1. Obtener datos estándar del cliente
    $clientData = Capsule::table('tblclients')->where('id', $clientId)->first();

    // 2. Obtener campos personalizados del cliente
    $customFields = Capsule::table('tblcustomfieldsvalues')
        ->join('tblcustomfields', 'tblcustomfields.id', '=', 'tblcustomfieldsvalues.fieldid')
        ->where('tblcustomfieldsvalues.relid', $clientId)
        ->where('tblcustomfields.type', 'client')
        ->get(['tblcustomfields.fieldname', 'tblcustomfieldsvalues.value']);

    $customFieldsArray = [];
    foreach ($customFields as $field) {
        $customFieldsArray[trim($field->fieldname)] = trim($field->value);
    }

    // 3. Definir qué campos son obligatorios
    $missingFields = [];

    // Teléfono estándar
    if (empty($clientData->phonenumber)) {
        $missingFields[] = 'Número de Teléfono';
    }

    // Campos personalizados exactos
    if (empty($customFieldsArray['Tipo de documento'])) {
        $missingFields[] = 'Tipo de Documento';
    }

    if (empty($customFieldsArray['Numero de documento'])) {
        $missingFields[] = 'Número de Documento';
    }

    if (empty($customFieldsArray['Tipo de Persona'])) {
        $missingFields[] = 'Tipo de Persona';
    }

    // 4. Mostrar error si algo falta
    if (!empty($missingFields)) {
        $fieldsList = implode(', ', $missingFields);
        return [
            "Para completar la compra, debe actualizar su perfil y completar los siguientes campos: <strong>$fieldsList</strong>. <a href='clientarea.php?action=details'>Actualizar ahora</a>"
        ];
    }

});

image.png.0d2df2969e012162cf763c001ed05c8b.png

Edited by JesusSuarz
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated