2016-03-15 132 views
2

嗨我在我的網站中使用此Woocommerce插件。我想要的是在單個產品中顯示我的自定義字段。Woocommerce單一產品選項卡中的自定​​義字段

enter image description here

我知道我必須使用掛鉤這一點,但根本不知道到底什麼鉤來使用。在woocommerce模板中,我找到了tabs.php文件。

下面的代碼

$tabs = apply_filters('woocommerce_product_tabs', array()); 

if (! empty($tabs)) : ?> 

<div class="woocommerce-tabs wc-tabs-wrapper"> 
    <ul class="tabs wc-tabs"> 
     <?php foreach ($tabs as $key => $tab) : ?> 
      <li class="<?php echo esc_attr($key); ?>_tab"> 
       <a href="#tab-<?php echo esc_attr($key); ?>"><?php echo apply_filters('woocommerce_product_' . $key . '_tab_title', esc_html($tab['title']), $key); ?></a> 
      </li> 
     <?php endforeach; ?> 
    </ul> 
    <?php foreach ($tabs as $key => $tab) : ?> 
     <div class="panel entry-content wc-tab" id="tab-<?php echo esc_attr($key); ?>"> 
      <?php call_user_func($tab['callback'], $key, $tab); ?> 
     </div> 
    <?php endforeach; ?> 
</div> 

誰能幫助我?

+0

您需要提供更多的細節......怎麼樣你添加自定義字段......你想要的顯示?也包括你到目前爲止嘗試過什麼...... – Reigel

回答

2

複製wp-content/plugins/woocommerce/templates/single-product/tabs/description.phpwp-content/themes/[active theme]/woocommerce/single-product/tabs/description.php

創建文件夾如果需要的話,現在編輯文件,並添加以顯示您的自定義字段的邏輯。

+0

試過了,我想顯示一個函數,但它顯示錯誤。 –

+0

提供有關自定義字段的詳細信息,您是如何定義它們的,或者您是否使用插件。 –

2

試試這個。

在functions.php文件add_action('woocommerce_after_single_product_summary', 'action_woocommerce_after_single_product_summary', 10, 2);

該功能用來顯示說明標籤 自定義值,然後打印自定義字段按您的要求添加一個鉤。

// define the woocommerce_after_single_product_summary callback 
function action_woocommerce_after_single_product_summary($woocommerce_output_product_data_tabs, $int) { 
    // if you have defined custom post type 
    echo get_post_meta($post_id, $key, $single); 

    // OR 
    // if you are using acf 
    echo $field = get_field($field_name, $post_id, $format_value); 
}; 

// add the action 
add_action('woocommerce_after_single_product_summary', 'action_woocommerce_after_single_product_summary', 10, 2); 
相關問題