0

我是 PHP 的初学者,但我对 Web 开发有基本的了解,

我有以下代码content-single-product.php

        <?php
        /**
         * Hook: woocommerce_single_product_summary.
         *
         * @hooked woocommerce_template_single_title - 5
         * @hooked woocommerce_template_single_rating - 10
         * @hooked woocommerce_template_single_price - 10
         * @hooked woocommerce_template_single_excerpt - 20
         * @hooked woocommerce_template_single_add_to_cart - 30
         * @hooked woocommerce_template_single_meta - 40
         * @hooked woocommerce_template_single_sharing - 50
         * @hooked WC_Structured_Data::generate_product_data() - 60
         */

        do_action( 'woocommerce_single_product_summary' );
        ?>

当我尝试在单个产品页面中向 Hook 添加新操作时

我将此部分自定义为如下

        <?php
        /**
         * Hook: woocommerce_single_product_summary.
         *
         * @hooked woocommerce_template_single_title - 5
         * @hooked woocommerce_template_single_rating - 10
         * @hooked woocommerce_template_single_price - 10
         * @hooked woocommerce_template_single_excerpt - 20
         * @hooked woocommerce_template_single_add_to_cart - 30
         * @hooked woocommerce_template_single_meta - 40
         * @hooked woocommerce_template_single_sharing - 50
         * @hooked WC_Structured_Data::generate_product_data() - 60
         */
         function carzyFunction(){
                echo'<h1>crazy statement</h1>';
            }
            add_action( 'woocommerce_single_product_summary', 'carzyFunction', 15 );

        do_action( 'woocommerce_single_product_summary' );
        ?>

我无法理解的是,虽然分配了carzyFunction()15 的优先级,但它出现在单个产品摘要部分的末尾,

为什么它没有出现在价格部分和产品描述部分之间

疯狂的功能输出出现在单品总结的最后

4

1 回答 1

0
add_filter( 'woocommerce_get_price_html', 'njengah_text_after_price' );
function njengah_text_after_price($price){
    $text_to_add_after_price  = echo'<h1>crazy statement</h1>';;
          
    return $price .'<br>'.  $text_to_add_after_price ;
}
于 2021-01-11T18:46:54.913 回答