Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Display short descriptions in WooCommerce shop loops
<?php
/**
* Display short descriptions in loop
*/
function kia_display_short_desciption_in_loop() {
global $product;
$short_description = $product->get_short_description();
if ( ! empty( $short_description ) ) {
echo '<p class="info">' . $short_description . '</p>';
}
}
add_action( 'woocommerce_shop_loop_item_title', 'kia_display_short_desciption_in_loop', 20 );
/**
* Add short description to block grid.
* NB: This does NOT work for the All Products Grid since that is not customizable at all.
*
* @param string $html Rendered product output.
* @param object $data Product information.
* @param WC_Product $product Product object.
* @return string Rendered product output.
*/
function kia_display_short_desciption_in_block_grid( $html, $data, $product ) {
$short_description = $product->get_short_description();
if ( ! empty( $short_description ) ) {
$html = "<li class=\"wc-block-grid__product\">
<a href=\"{$data->permalink}\" class=\"wc-block-grid__product-link\">
{$data->image}
{$data->title}
</a>
<p class='info'>{$short_description}</p>
{$data->badge}
{$data->price}
{$data->rating}
{$data->button}
</li>";
}
return $html;
}
add_filter( 'woocommerce_blocks_product_grid_item_html', 'kia_display_short_desciption_in_block_grid', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment