Skip to content

Instantly share code, notes, and snippets.

@helgatheviking
Last active October 23, 2020 00:01
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 helgatheviking/c6a19c7a4e0d4088b00c848620a00fac to your computer and use it in GitHub Desktop.
Save helgatheviking/c6a19c7a4e0d4088b00c848620a00fac to your computer and use it in GitHub Desktop.
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