2015-11-02 60 views
3

如果沒有評論,我已成功刪除評論選項卡標題上的(0)。在市場營銷中 - 最好的做法是不要顯示產品有0條評論。這裏是一個在WooCommerce插件文件WC-模板function.php發現,我已經把我的子主題的functions.php文件中的代碼:刪除WooCommerce Reviews選項卡上的(0)

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()), 

如果語句添加一個檢查,如果沒有意見,在該行改變這個上面一行像上面:

title' => sprintf(__('Reviews', 'woocommerce'), 

回答

2

這是相當簡單。您可以更改標籤的標題:

add_filter('woocommerce_product_tabs', 'wp_woo_rename_reviews_tab', 98); 
function wp_woo_rename_reviews_tab($tabs) { 
    global $product; 
    $check_product_review_count = $product->get_review_count(); 
    if ($check_product_review_count == 0) { 
     $tabs['reviews']['title'] = 'Reviews'; 
    } else { 
     $tabs['reviews']['title'] = 'Reviews('.$check_product_review_count.')'; 
    } 
    return $tabs; 
} 

+0

啊 - 做到了。感謝你的幫助Alex。 – Shinosky

+0

謝謝剪切。我想如果審查0然後隱藏總數。我的意思是評論 目前還沒有評論。會隱藏。任何想法如何 – pagol

+0

@pagol如果任何人如果因隱藏而無法進入評論選項卡,他們將如何發佈評論? – Shinosky