woocommerce stock notification priority

元气小坏坏 提交于 2019-12-04 06:10:14

问题


I am trying to arrange the order of the product summary such that price comes after stock notification which comes after short description. I am aware of the priorities as defined in content-single-product.php

/**
         * woocommerce_single_product_summary hook.
         *
         * @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' );

However, I do not see where stock is hooked in. I cannot find it in the documentation or the code. If I knew the hook and priority for the stock template, I could solve my problem. I have tried

remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_stock', 30 );

with no results. Can anyone help? Thanks.


回答1:


I finally figured it out. Stock status is hardcoded into the templates, so you must first remove it from simple.php and variation.php in your child theme. (And grouped.php too, but I don't use grouped products, so I didn't need to update that template.)

Delete these lines from variation.php

    <div class="woocommerce-variation-availability">
    {{{ data.variation.availability_html }}}
</div>

and this line from simple.php (line 28)

echo wc_get_stock_html( $product );

Then in your functions.php add the following code changing the priority to where ever you want the stock status to show up.

add_action( 'woocommerce_single_product_summary', 'mh_output_stock_status', 21 );

function mh_output_stock_status ( ) {
    global $product;

    echo wc_get_stock_html( $product );

}

I really wish stock was hooked in like the rest of the summary. It would be a lot more straight forward.

I hope this helps someone else.



来源:https://stackoverflow.com/questions/44664561/woocommerce-stock-notification-priority

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!