In Woocommerce, I am using YITH WooCommerce Brands plugin to handle product brands.
I'm currently struggling with a fixed text That I want under my short description in WooCommerce. I want to display dynamically the product name in that text (which works), but also the product category name [CATEGORY_NAME]
and brand name [BRAND_NAME]
.
But I can't seem to get those to work.
Based on this answer thread: Add Text under Single Product Short Description in Woocommerce
Here is my code version:
// Add text after short description
add_action( 'woocommerce_single_product_summary', 'custom_single_product_summary', 2 );
function custom_single_product_summary(){
global $product;
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
add_action( 'woocommerce_single_product_summary', 'custom_single_excerpt', 20 );
}
function custom_single_excerpt(){
global $post, $product;
$short_description = apply_filters( 'woocommerce_short_description', $post->post_excerpt );
if ( ! $short_description )
return;
// The custom text
$custom_text = 'Zoekt u naast de '.$product->get_name().' andere [PRODUCT_CATEGORY] van dit merk? Bekijk dan eens de gehele collectie van [BRAND_NAME]. Powerlight is officieel dealer van [BRAND_NAME]. Heeft u een specifieke vraag over dit product? Neem gerust eens contact op met onze <span style="text-decoration: underline;"><a href="https://power-light.nl/contact/">klantenservice</a></span>. Onze adviseurs staan graag voor u klaar.';
?>
<div class="woocommerce-product-details__short-description">
<?php echo $short_description . $custom_text; // WPCS: XSS ok. ?>
</div>
<?php
}
Any idea's how I can display the product category name and the product brand name in my custom text?
$terms = get_the_terms( $product->get_id(), 'product_cat' );
it will return you terms of that specific product then you have to just get its name – raju_odi