Woocommerce - 如何在产品摘要之后但在描述之前显示内容?

Woocommerce - How to display content after product summary but before the description?

我想在我的单个产品页面上的产品摘要下方和带有评论的选项卡上方显示一些内容

我使用 this 指南作为钩子的参考,所以我认为 woocommerce_after_single_product_summary 是正确的。但是,唉,它在产品页面的底部显示了我的内容。

我使用的完整代码是:

function product_summary() {
    echo '<h2>Test!</h2>';
}

add_action( 'woocommerce_after_single_product_summary', 'product_summary', 11);

我尝试过的所有其他钩子都可以完美运行,所以我不明白为什么这个不行。我确实使用了插件 'custom tabs',所以这可能会干扰 (?)

第 3 方插件当然可能会干扰默认顺序,但在您的情况下,问题似乎是优先事项。

默认情况下 woocommerce_after_single_product_summary 操作有 3 个挂钩:

  • woocommerce_output_product_data_tabs - 10
  • woocommerce_upsell_display - 15
  • woocommerce_output_related_products - 20

因此,为了在这 3 个之前打印,您需要使用较小的优先级。 F.e。 0 或 1 或 2 或 9。但不是 11。

如果连那个都不起作用,您将需要调试代码并打印 woocommerce_after_single_product_summary 的所有默认+自定义挂钩。

要查看给定操作有哪些挂钩,您可以使用此代码(在模板的页脚区域 f.e):

 global $wp_filter;
 var_dump($wp_filter["woocommerce_after_single_product_summary"]);