Ad

Show The Meta Description Of A Woocommerce Product Under The Title In The Product Category Overview

- 1 answer

I'm searching for an option to show the meta description of a Woocommerce product under the title in the product category overview. The code below in the functions.php of the theme repeat the SKU what the title is of the product. Wondering how to replace this with the meta description:

add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_after_shop_loop_item_sku_in_cart', 20, 1);
function woocommerce_after_shop_loop_item_sku_in_cart( $template )  {
global $product;
$sku = $product->get_sku();
echo $sku;
}

Thanks

Ad

Answer

You can access a short description using post->post_excerpt. check below code.

add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_after_shop_loop_item_sku_in_cart', 20, 1);
function woocommerce_after_shop_loop_item_sku_in_cart( $template )  {
    global $product;
    $sku = $product->get_sku();
    echo $sku;
    echo "</br>";
    echo get_post_meta( $product->get_id(), '_yoast_wpseo_metadesc', true );
}
Ad
source: stackoverflow.com
Ad