How to Require A Minimum Description Character Count in Osclass
on :January 27, 2024, 9:34 pm #771
I know we can control the max characters used in the description but how can one require a minimum character count for the description? Sometimes people just put a few words and it does not look very good. I would like to require a description of at least 1000 characters.
Thank you.
Re: How to Require A Minimum Description Character Count in Osclass
on :January 28, 2024, 11:26 am #772
In your theme functions.php or index.php from an active plugin add the next code
function cbk_min_description_text($flash_error, $item) {
$minValue = 1000;
if (isset($item['description'])) {
$error = '';
foreach ($item['description'] as $key => $value) {
$count = strlen($value);
if ($count < $minValue) {
$error = sprintf(_m('Description too short (%s).'), $minValue);
break;
}
}
}
$flash_error .= $error;
return $flash_error;
}
osc_add_filter('pre_item_add_error', 'cbk_min_description_text');
$minValue = 1000; here you change the minimum characters
Re: How to Require A Minimum Description Character Count in Osclass
on :January 28, 2024, 3:30 pm #773
Thank you! I will try that out and report back.
Re: How to Require A Minimum Description Character Count in Osclass
on :January 29, 2024, 7:37 pm #775
I put this in functions.php and it worked perfectly! Thank you!