Last active
October 23, 2020 00:01
-
-
Save helgatheviking/c6a19c7a4e0d4088b00c848620a00fac to your computer and use it in GitHub Desktop.
Display short descriptions in WooCommerce shop loops
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 | |
/** | |
* 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