Straight from the WP Codex there is a command to trim the word count on text – commonly used for controlling the_excerpt length to customise ‘read more’ and ‘introduction’ type on a page.
$trimmed = wp_trim_words( $text, $num_words = 55, $more = null );
The above example will trim a
$text variable to 55 words and have nothing trailing.
Tip for new comers: Using wp_trim_words() on the_title returns an array and not a string, so it doesn’t work with.
Instead you are likely looking for:
echo wp_trim_words( get_the_title(), 55, null );
Creating a template to show only sold / out of stock items is sometimes neccesary when clients sell one-off items. I took the approach of creating a custom page template which allowed me to turn off “Show out of stock items” in all other WooCommerce pages. This allows visibility of these items on the specified page only.
I made a quick page template which would only get these products by using WordPress Meta Query properties in the loop and you can combine the meta key/values with the information found in a comment by Tareq on Meta Keys for attributes.
Here is the loop I created for this run:
$args = array( 'post_type' => 'product', 'posts_per_page' => 30, 'orderby' => 'date', 'order' => 'DESC', 'meta_query' => array(
'key' => '_stock_status',
'value' => 'outofstock',
'compare' => '='
$loop = new WP_Query( $args );
If you want to get items which are in stock only, you can change the value to “instock”.