I have a problem with Woocommerce to find a good solution, I am looking to have my line breaks in this product extract space. I would also like to be able to use lists. Despite my search in the plugin, I can't find any strip_tags that could be the cause of removing them, and also overriding a filter, I have tested many codes by going through Google without success.
This solution not working for me. woocommerce product excerpt description (short)
The short description is controlled by the short description input field for each product. So you can make your changes there for each product which require some manual work.
However, you can automatically convert each sentence in the short description into a list item. One way you can achieve this by adding a function to split the description at each period (".") symbol, and wrap each resulting sentence in <li>
tags.
The below code will:
wpautop
filter: removes the automatic paragraph tags added by WordPress..
) symbol. It is important that you add the period symbol at the end of each sentence, as this is what determines where the list tag ends.<li>
tags.<ul>
)./* Automatically convert each sentence in the short description into a list item */
// Remove the wpautop filter for the short description
remove_filter('woocommerce_short_description', 'wpautop');
// Add the custom filter to apply the function to the short description
add_filter('woocommerce_short_description', 'custom_list_item_converter_short_description', 10, 1);
function custom_list_item_converter_short_description($the_excerpt) {
// Split the excerpt into sentences at each period symbol and filter out empty elements
$sentences = array_filter(array_map('trim', explode('.', $the_excerpt)));
// Wrap each sentence in <li> tags and combine them into a single string with <ul> tags
$formatted_excerpt = '<ul><li>' . implode('.</li><li>', $sentences) . '.</li></ul>';
// Return the formatted excerpt
return $formatted_excerpt;
}
I have tested this code and it works on my end. You should add it in the functions.php
file of your active child theme.
Removing this code will revert back to normal settings.