[英]Add specific product attribute after title on Woocommerce single products
In woocommerce, I am trying to include "brand name" product attributes after the product name/title or underneath in single product page as below;在woocommerce中,我试图在产品名称/标题之后或在单个产品页面下方包含“品牌名称”产品属性,如下所示;
Super Shark Mop - Tesco Express超级鲨鱼拖把 - Tesco Express
I would like this brand attribute to be automatically added to title once the product is created.我希望在创建产品后将此品牌属性自动添加到标题中。 Any help is appreciated.
任何帮助表示赞赏。
This is quiet easy using the following code that will remove the product title to replace it with a custom title including the product attribute "brand name" after it:使用以下代码将删除产品标题以将其替换为包含产品属性“品牌名称”的自定义标题,这很容易使用以下代码:
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
add_action( 'woocommerce_single_product_summary', 'custom_template_single_title', 5 );
function custom_template_single_title() {
global $product;
$brand_name = $product->get_attribute('brand-name');
echo '<h1 class="product_title entry-title">';
the_title();
if( $brand_name )
echo ' - ' . $brand_name;
echo '</h1>';
}
Code goes in function.php file of your active child theme (or active theme).代码位于活动子主题(或活动主题)的 function.php 文件中。 Tested and works.
测试和工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.