Skip to content

Instantly share code, notes, and snippets.

@jasperf
Last active January 4, 2024 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasperf/85ed09a5360c11a4c45fa123f8537e3d to your computer and use it in GitHub Desktop.
Save jasperf/85ed09a5360c11a4c45fa123f8537e3d to your computer and use it in GitHub Desktop.
Short description display count filter for Restaurant for WooCommerce Plugin (v2 is new version)
<?php
add_filter('wc_rms_change_short_desc_disp_count', 'wc_rms_change_short_desc_disp_count_updated', 100, 2);
/**
* Filter callback function for modifying the short description displayed count.
*
* This function is hooked to the 'wc_rms_change_short_desc_disp_count' filter
* and is designed to modify the short description of a WooCommerce product.
*
* @param string $desc The original short description of the product.
* @param object $prod The WooCommerce product object.
* @return string Modified short description or a placeholder string if not applicable.
*/
function wc_rms_change_short_desc_disp_count_updated($desc, $prod){
if(is_object($prod))
{
$desc = get_the_excerpt($prod->get_id());
$desc = wp_strip_all_tags($desc);
//$desc = trim($desc);
$descLen = strlen($desc);
if($descLen > 1){
if($descLen > 80)
{
$desc = substr($desc, 0, 80);
$last_space_position = strrpos($desc, ' ');
if ($last_space_position !== false) {
$desc = substr($desc, 0, $last_space_position);
if($descLen > strlen($desc)){
$desc = $desc."...";
}
}
}
return $desc;
}else{
return "&nbsp;<br class='d1'/>&nbsp;";
}
}else{
return "&nbsp;<br class='else'/>&nbsp;";
}
}
<?php
add_filter('wc_rms_change_short_desc_disp_count', 'wc_rms_change_short_desc_disp_count_updated', 100, 2);
function wc_rms_change_short_desc_disp_count_updated($short_desc, $prod){
if(is_object($prod))
{
$desc = get_the_excerpt($prod->get_id());
$desc = wp_strip_all_tags($desc);
//$desc = trim($desc);
$descLen = strlen($desc);
if($descLen > 1){
if($descLen > 80)
{
$desc = substr($desc, 0, 80);
$last_space_position = strrpos($desc, ' ');
if ($last_space_position !== false) {
$desc = substr($desc, 0, $last_space_position);
if($descLen > strlen($desc)){
$desc = $desc."...";
}
}
}
return $desc;
}else{
return "&nbsp;<br class='d1'/>&nbsp;";
}
}else{
return "&nbsp;<br class='else'/>&nbsp;";
}
}
@Apetree100122
Copy link

get_id());$desc = wp_strip_all_tags($desc);//$desc = trim($desc);$descLen = strlen($desc);if($descLen > 1){ if($descLen > 80){$desc = substr($desc, 0, 80);$last_space_position = strrpos($desc, ' ');if ($last_space_position !== false) { $desc = substr($desc, 0,$last_space_position);if($descLen > strlen($desc)){$desc = $desc."...";}} }return $desc;}else{return " 
 ";}}else{return " 
 ";}} functions.php @@ -0,0 +1,33 @@ get_id()) $desc = wp_strip_all_tags($desc);//$desc = trim($desc); $descLen = strlen($desc);if($descLen > 1){ if($descLen > 80) {$desc = substr($desc, 0, 80); $last_space_position = strrpos($desc, ' ');if ($last_space_position!==false) {$desc=substr($desc,0,$last_space_position);if($descLen> strlen($desc)){$desc =$desc."...";}}}return $desc;}else{return " 
 ";}}else{ return " 
 ";}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment