woocommerce 库存通知优先级 [英] woocommerce stock notification priority

查看:32
本文介绍了woocommerce 库存通知优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试安排产品摘要的顺序,以便价格在库存通知之后出现,在简短描述之后出现.我知道 content-single-product.php 中定义的优先级

/*** 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');

但是,我没有看到股票在哪里挂钩.我在文档或代码中找不到它.如果我知道股票模板的钩子和优先级,我就可以解决我的问题.我试过了

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

没有结果.任何人都可以帮忙吗?谢谢.

解决方案

我终于想通了.库存状态被硬编码到模板中,因此您必须首先将其从子主题中的 simple.php 和variation.php 中删除.(还有 grouped.php,但我不使用分组产品,所以我不需要更新那个模板.)

从variation.php中删除这些行

 

{{{ data.variation.availability_html }}}

还有来自 simple.php 的这一行(第 28 行)

echo wc_get_stock_html( $product );

然后在您的functions.php中添加以下代码,将优先级更改为您希望库存状态显示的位置.

add_action('woocommerce_single_product_summary', 'mh_output_stock_status', 21);函数 mh_output_stock_status ( ) {全球$产品;回声 wc_get_stock_html( $product );}

我真的希望股票能像总结的其余部分一样被吸引.这会更直接.

我希望这对其他人有帮助.

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.

解决方案

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.

这篇关于woocommerce 库存通知优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆