Sorry, pre_item_edit and pre_item_add are deprecated .
use item_add_prepare_data and item_edit_prepare_data instead
In your theme's functions.php file, add to the end
EDITED I reversed the mc_edit_filter_description($aItem) and mc_add_filter_description($aItem) functions
I splitted mc_add_metas in mc_add_metas_item_edit and mc_add_metas_item_add <?php
function endsWith($haystack, $needle)
{
$length = strlen($needle);
return $length === 0 ||
(substr($haystack, -$length) === $needle);
}
function mc_add_metas_item_add($desc, $aItem) {
$_meta = Field::newInstance()->findByCategory($aItem['catId']);
$meta = Params::getParam("meta");
foreach($_meta as $_m) {
$meta[$_m['pk_i_id']] = (isset($meta[$_m['pk_i_id']]))?$meta[$_m['pk_i_id']]:'';
}
$d = '\n\n ';
$mField = Field::newInstance();
foreach($meta as $k => $v) {
$field = $mField->findByPrimaryKey($k);
$d = $d . $field['s_name'] .': ' .$v. '\n';
}
if(endsWith($desc, $d))
return $desc;
else return $desc . $d;
}
function mc_add_metas_item_edit($desc, $itemId) {
$metas = Item::newInstance()->metaFields($item_Id);
$d = '\n\n ';
foreach($metas as $m) {
$d = $d . $m["s_name"] .': ' .$m["s_value"] . '\n';
}
if(endsWith($desc, $d))
return $desc;
else return $desc . $d;
}
function mc_edit_filter_description($aItem) {
foreach(@$aItem['description'] as $key => $value) {
$aItem['description'][$key] = mc_add_metas_item_edit($value,$aItem['idItem']);
}
return $aItem;
}
function mc_add_filter_description($aItem) {
foreach(@$aItem['description'] as $key => $value) {
$aItem['description'][$key] = mc_add_metas_item_add($value,$aItem);
}
return $aItem;
}
osc_add_filter('item_add_prepare_data', 'mc_add_filter_description');
osc_add_filter('item_edit_prepare_data', 'mc_edit_filter_description');
?>
or if you don't want the custom field's name there remove
$m["s_name"] .': ' .
and
$field['s_name'] .': ' .
After this you must update the descriptions in your db by editing and saving each item.Step 2
You would want to remove the added text from description when displaying the description to the public and to the owner when it edits hi's item.
You can do that with a function
Put this before the above code in functions.php
<?php
function mc_hide_metas($desc, $itemId) {
$metas = Item::newInstance()->metaFields($item_Id);
$d = '\n\n ';
foreach($metas as $m) {
$d = $d . $m["s_name"] .': ' .$m["s_value"] . '\n';
}
if(endsWith($desc, $d))
return str_replace($d,'',$desc);
else return $desc;
}
?>
or if you don't want the custom field's name there remove
$m["s_name"] .': ' .
and call this function where the description is shown. Have a look here
https://stackoverflow.com/questions/43015613/how-to-modify-ft-min-word-len-4-to-ft-min-word-len-1-so-that-osclass-3-7-1-can-sAnd see where I call 'removeunderline(' for description.
If you do this admin and user side the solution will work if the item is edited and it's category is changed and or it's custom fields are changed.If the admin makes the editing and the above function can't be called from oc-admin/themes/modern... files, the last function from above must be placed in /oc-includes/osclass/helpers/hSearch.php and removed from functions.php file.