2017-08-14 76 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

相关问题