显示woocommerce缺货产品变体的自定义div块 [英] Display a custom div block for woocommerce out of stock product variations

查看:61
本文介绍了显示woocommerce缺货产品变体的自定义div块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Woocommerce中,我试图使自定义div容器在可变产品的变体缺货但可以延期交货时可见.

In Woocommerce, I'm trying to make a custom div container visible when a variation of variable product is out of stock, but available on backorder.

因此默认情况下它是隐藏的.但是,当客户选择了一个缺货但可以延期交货的变体时,它将显示我编写的div块.

So by default it's hidden. But when a customer selects a variation that's out of stock, but available on backorder, it will show the div blocks I've written.

我已将此div块放置在产品的简短说明中,因为这是我希望在缺货时可以看到它的地方.或者至少,我希望将其放在产品简短说明下方的变体形式上方.

I've placed this div block inside the short description of the product, since that is the place where I want to have it visible when it is out of stock. Or at least, I want to have it above the variations form, under the product short description.

由于我对php和woocommerce钩子几乎一无所知,所以我想知道是否有人知道该怎么做.

Since I have little to no knowledge on php and woocommerce hooks, I was wondering if someone knows how to do this.

这是我正在谈论的div容器代码.

This is the div container code I'm talking about.

<div class="mto-cont">
<div class="col-xs-6 made-to-order"><a href="#">Made to Order</a></div>
<div class="col-xs-6">Production time: <span style="color: #000;">2 - 4 weeks</span></div>

推荐答案

已更新-当缺货的产品变体形式以下时,将添加自定义html显示:

Updated - The following will add a custom html display when a product variation is on backorders:

add_filter( 'woocommerce_available_variation', 'custom_outofstock_variation_addition', 10, 3 );
function custom_outofstock_variation_addition( $data, $product, $variation ) {
    if( $variation->is_on_backorder() ){
        $data['availability_html'] .= '<div class="mto-cont">
        <div class="col-xs-6 made-to-order"><a href="#">Made to Order</a></div>
        <div class="col-xs-6">Production time: <span style="color: #000;">2 - 4 weeks</span></div>
        </div>';
    }
    return $data;
}

代码进入您的活动子主题(或活动主题)的function.php文件中.经过测试,可以正常工作.

Code goes in function.php file of your active child theme (or active theme). Tested and works.

这篇关于显示woocommerce缺货产品变体的自定义div块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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