简体   繁体   English

在 Woocommerce 单个产品的标题后添加特定的产品属性

[英]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.

相关问题 在 Woocommerce 单个产品的标题前添加链接的特定产品属性 - Add linked specific product attribute before title on Woocommerce single products 在WooCommerce单品页的相关商品标题添加URL - Add relative URL to related products title on WooCommerce single product page Woocommerce添加到购物车产品仅限4种特定产品 - Woocommerce Add to cart product Restriction to 4 specific products 将 WooCommerce 产品标题限制为特定长度(并添加“...”) - Limit WooCommerce product title to a specific length (and add '...') 在单个产品页面中显示特定产品属性值的相关产品 - Display Related products for a specific product attribute value in single product pages 根据特定产品属性值显示 WooCommerce 相关产品 - Display WooCommerce related products based on specific product attribute value 隐藏 WooCommerce 可变产品上的特定产品属性下拉列表 - Hide specific product attribute dropdown on WooCommerce variable products 在 WooCommerce 购物车页面的购物车商品名称后添加产品 ID 用于特定产品 - Add the product ID after the cart item name in WooCommerce cart page for specific products 将特定产品的多个选项卡添加到 WooCommerce 单个产品页面 - Adding multiple tabs for specific products to WooCommerce single product pages 将产品附加字段添加到WooCommerce上的特定产品 - Add a product add-on field to specific products on WooCommerce
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM