[英]Add product page title to WooCommerce product description heading
What I'm trying to achieve in WooCommerce is that on the single product page, the Description tab, I'm trying to add the product page title before the word Description.我试图在 WooCommerce 中实现的是,在单个产品页面的“描述”选项卡上,我试图在“描述”一词之前添加产品页面标题。
Here is my current WooCommerce code:这是我当前的 WooCommerce 代码:
defined( 'ABSPATH' ) || exit;
global $post;
$heading = apply_filters( 'woocommerce_product_description_heading', __( 'Description', 'woocommerce' ) ); ?>
<?php if ( $heading ) : ?>
<h2>PRODUCT PAGE TITLE HERE <?php echo esc_html( $heading ); ?></h2>
<?php endif; ?>
<?php the_content(); ?>
The problem here, however, is that:然而,这里的问题是:
As a result, id like the tab to go from Description to BLACK NIKE SHOES Description结果,从描述到黑色耐克鞋描述的标签标识为 go
Example:例子:
Any advice?有什么建议吗?
Via the woocommerce_product_description_heading
filter hook you can use global $product
and $product->get_name()
.通过
woocommerce_product_description_heading
过滤器挂钩,您可以使用global $product
和$product->get_name()
。 This result can then be added to the existing string.然后可以将此结果添加到现有字符串中。
So you get:所以你得到:
function filter_woocommerce_product_description_heading( $heading ) {
global $product;
// Is a WC product
if ( is_a( $product, 'WC_Product' ) ) {
// Get title and append to existing string
$heading = $product->get_name() . ' ' . $heading;
}
return $heading;
}
add_filter( 'woocommerce_product_description_heading', 'filter_woocommerce_product_description_heading', 10, 1 );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.