In this example, let’s assume that our table contains the fields: unit_price, quantity and total. We want to automatically calculate the value of the total field by multiplying quantity and unit_price.
Open the tablename.php on your hooks folder.
function
tablename_before_insert(&
$data
,
$memberInfo
, &
$args
){
$data
[
'total'
] =
$data
[
'quantity'
] *
$data
[
'unit_price'
];
return
true;
}