【发布时间】:2016-02-02 22:03:27
【问题描述】:
当没有评论时,我已成功删除评论标签标题上的 (0)。在市场营销中 - 最好不要显示产品有 0 条评论。这是我放置在 WooCommerce 插件文件 wc-template-function.php 中的子主题的 functions.php 文件中的代码:
if ( ! function_exists( 'woocommerce_default_product_tabs' ) ) {
/**
* Add default product tabs to product pages.
*
* @param array $tabs
* @return array
*/
function woocommerce_default_product_tabs( $tabs = array() ) {
global $product, $post;
// Description tab - shows product content
if ( $post->post_content ) {
$tabs['description'] = array(
'title' => __( 'Description', 'woocommerce' ),
'priority' => 10,
'callback' => 'woocommerce_product_description_tab'
);
}
// Additional information tab - shows attributes
if ( $product && ( $product->has_attributes() || ( $product->enable_dimensions_display() && ( $product->has_dimensions() || $product->has_weight() ) ) ) ) {
$tabs['additional_information'] = array(
'title' => __( 'Additional Information', 'woocommerce' ),
'priority' => 20,
'callback' => 'woocommerce_product_additional_information_tab'
);
}
// Reviews tab - shows comments
if ( comments_open() ) {
$check_product_review_count = $product->get_review_count();
if ( $check_product_review_count == 0 ) {
$tabs['reviews'] = array(
'title' => sprintf( __( 'Reviews', 'woocommerce' ) ),
'priority' => 30,
'callback' => 'comments_template'
);
}
else {
$tabs['reviews'] = array(
'title' => sprintf( __( 'Reviews (%d)', 'woocommerce', $product->get_review_count() ), $product->get_review_count() ),
'priority' => 30,
'callback' => 'comments_template'
);
}
}
return $tabs;
}
}
我的问题是 - 这是在不更改 woocommerce 核心文件的情况下修改它的最有效方法吗?函数“woocommerce_default_product_tabs”是一个可插入函数,但似乎我可以以某种方式使用过滤器,而不是将整个函数复制到我的子主题中并从那里进行编辑。我只需要得到这行代码:
title' => sprintf( __( 'Reviews (%d)', 'woocommerce', $product->get_review_count() ),
并添加一个 if 语句来检查是否没有 cmets 来更改上面的行,就像上面的行一样:
title' => sprintf( __( 'Reviews', 'woocommerce' ),
【问题讨论】:
标签: php wordpress function woocommerce review