Jump to content

Adding custom field value to Product Name


JGolder

Recommended Posts

Hello Team,

I would like to display the customfield values next to the products. Under the page: clientssummary (picture is attached)

Unfortunately, I can not continue.

It already works under clientservices.
Here is my script for the clientservice site:

<?php

if ( !defined('WHMCS')) {
    header("Location: ../../index.php");
}

use WHMCS\Database\Capsule;

if($_REQUEST['getAll'] == '1')
{
    $newAll = [];
    $gotCustomFieldID = [1,26,10,11,20,21];

 
    $getCustomFieldID = Capsule::table('tblcustomfields')
        ->select('id')
        ->where('tblcustomfields.type','product')
        ->where('tblcustomfields.fieldname','Location Name')
        ->where('tblcustomfields.fieldtype','text')
        ->get();
        foreach ($getCustomFieldID as $data)
        {
            $gotCustomFieldID[] = $data->id;
        }

    foreach ($gotCustomFieldID as $customFieldID)
    {
        $all = Capsule::table('tblcustomfieldsvalues')
            ->join('tblhosting', 'tblcustomfieldsvalues.relid', '=', 'tblhosting.id')
            ->where('fieldid', $customFieldID )
            ->where('userid', $_REQUEST['userid'] )
            ->get();

        $all    = json_decode( json_encode( $all ) , true );
        foreach($all as $a)
        {
            $newAll[$a['relid']] = $a['value'];
        }
    }

    ob_clean();
    echo json_encode(array( "all" => $newAll ));
    die;

}

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

    if( $vars['filename'] == 'clientsservices' )
    {
        echo '<script>
            document.addEventListener("DOMContentLoaded", function(){ 
            $.post(window.location,
            { getAll: 1 },
            function(data, status){

            var data = JSON.parse(data);
            var first = [];

            setInterval(function() {

                var x = document.querySelectorAll("[data-value]");
		

                for (var i = 1; i < x.length ; i++) {
                 
                    if(typeof first[x[i].dataset.value] === "undefined")
                    {
                        first[x[i].dataset.value] = x[i].innerText;
                    }
                    if(typeof data.all[x[i].dataset.value] !== "undefined" && data.all[x[i].dataset.value] != "")
                    {
                        x[i].innerText = first[x[i].dataset.value] + " - " + data.all[x[i].dataset.value];
                    } 
                }     
              }, 100);
                });   
        });
        </script>';
    }

    if( $vars['filename'] == 'clientssummary' )
    {
        echo '<script>
            document.addEventListener("DOMContentLoaded", function(){ 
            $.post(window.location,
            { getAll: 1 },
            function(data, status){

            var data = JSON.parse(data);
            var first = [];

            setInterval(function() {

                var x = document.querySelectorAll("[data-value]");

                for (var i = 1; i < x.length ; i++) {
                 
                  
                        first[x[i].dataset.value] = x[i].innerText;
                    
                   
                        x[i].innerText = first[x[i].dataset.value] + " - " + data.all[x[i].dataset.value];
                    
                }     
              }, 100);
                });   
        });
        </script>';
    }
    
});

I need a script so I can display the custom field values next to the products. on the side clientssummary (picture is attached)

customer overiew.JPG

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