在WooCommerce加售之前显示自定义属性(链接的产品)
答
如果你看看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');
这意味着在挂钩,显示以下内容:
- 优先(为10的优先级)产物标签,
- 然后(为15的优先级)的加售,
- 而完成(带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 + ...
@LoicTheAztec,谢谢您的指导 – pipelian
行..位置想通了,但现在我不能显示文章的自定义属性,我有这一块我已经移动到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