2017-08-14 78 views
1

我設法顯示自定義屬性,但它們在鏈接的產品後顯示,我如何讓它們顯示在前?在WooCommerce加售之前顯示自定義屬性(鏈接的產品)

左邊:我目前有,右期望的結果

感謝 enter image description here

+0

@LoicTheAztec,謝謝您的指導 – pipelian

+0

行..位置想通了,但現在我不能顯示文章的自定義屬性,我有這一塊我已經移動到mu functions.php文件的單product.php上的代碼:add_action('woocommerce_after_single_product_summary','custom_code_after_single_product_summary',12); function custom_code_after_single_product_summary(){ global $ product; // ===>您的代碼在這裏 \t echo'

產品ID:'。 get_post_meta($ post-> ID,'TABLE',true)。'

'; \t } – pipelian

回答

1

如果你看看woocommerce模板內容單product.php你會看到:

/** 
* woocommerce_after_single_product_summary hook. 
* 
* @hooked woocommerce_output_product_data_tabs - 10 
* @hooked woocommerce_upsell_display - 15 
* @hooked woocommerce_output_related_products - 20 
*/ 
do_action('woocommerce_after_single_product_summary'); 

這意味着在掛鉤,顯示以下內容:

  1. 優先(爲10的優先級)產物標籤,
  2. 然後(爲15的優先級)的加售,
  3. 而完成(帶20的優先級)相關產品。

所以,如果你想顯示的產品標籤和加售之間的自定義代碼,則需要使用woocommerce_after_single_product_summary行動掛鉤鉤住11之間的優先級的自定義功能,以14

你可以這樣來做:

add_action('woocommerce_after_single_product_summary', 'custom_code_after_single_product_summary', 12); 
function custom_code_after_single_product_summary() { 
    global $product; 

    // Set here your post "meta_key" for your custom product attribute 
    $meta_key1 = 'pa_when-to-use'; 

    // Your code (related to your comment): 
    echo get_post_meta($product->get_id(), $meta_key1, true); 
} 

代碼放在您的活動子主題(或主題)的function.php文件或也以任何插件文件。

測試和工程上WooCommerce 3 + ...

+0

好的..位置已經算出來了,但現在我無法顯示帖子的自定義屬性,我在single-product.php上有這段代碼:<?php echo get_post_meta($ post-> ID,'TABLE',true); ?>,其中'TABLE'是自定義屬性的名稱 – pipelian

+0

非常感謝! – pipelian

相關問題