Last active
January 4, 2024 03:53
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 " <br class='d1'/> "; | |
} | |
}else{ | |
return " <br class='else'/> "; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 " <br class='d1'/> "; | |
} | |
}else{ | |
return " <br class='else'/> "; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
";}}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 "
";}}