简体   繁体   English

显示用于 woocommerce 缺货产品变体的自定义 div 块

[英]Display a custom div block for woocommerce out of stock product variations

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.在 Woocommerce 中,当可变产品的变体缺货时,我试图使自定义 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.我已将此 div 块放在产品的简短描述中,因为这是我希望在缺货时可以看到它的地方。 Or at least, I want to have it above the variations form, under the product short description.或者至少,我想把它放在变体表格之上,在产品简短描述之下。

Since I have little to no knowledge on php and woocommerce hooks, I was wondering if someone knows how to do this.由于我对 php 和 woocommerce 钩子几乎一无所知,我想知道是否有人知道如何做到这一点。

This is the div container code I'm talking about.这是我正在谈论的 div 容器代码。

<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>

Updated - The following will add a custom html display when a product variation is on backorders:更新- 当产品变体处于缺货状态时,以下将添加自定义 html 显示:

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;
}

Code goes in function.php file of your active child theme (or active theme).代码位于活动子主题(或活动主题)的 function.php 文件中。 Tested and works.测试和工作。

在此处输入图片说明

Depending on your software and what you want to do, there are 2 ways:根据您的软件和您想要做什么,有两种方法:

  1. Hide the div with CSS/JS (like change the display property).使用 CSS/JS 隐藏 div(例如更改display属性)。

  2. Since youre are talking about a PHP framework, you can just not display the DIVs under certain conditions.既然你在谈论一个 PHP 框架,你就不能在某些条件下显示 DIV。

I hope you were not asking for how to solve your problem in a detailed way in one of those both ways, since there are billions of billions of explanations and tutorials out there because hiding a html-element under certain conditions is one of the most basic stuff you can learn on the world wide web by just using google for 2 seconds ;)我希望你不是在问如何以这两种方式之一详细解决你的问题,因为那里有数十亿的解释和教程,因为在某些条件下隐藏 html 元素是最基本的之一只需使用谷歌 2 秒就可以在万维网上学到的东西;)

If you have a detailed question because you what you have coded does not work for some reason, then provide the code and describe what you have tried to do and what is not working.如果您有一个详细的问题,因为您所编码的内容由于某种原因不起作用,请提供代码并描述您尝试执行的操作以及无效的操作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 基于 Woocommerce 产品变体库存数据复选框选项的自定义显示 - Custom display based on Woocommerce product variations stock data checkbox option 通过 WooCommerce 中的自定义库存数量减少来灰显“缺货”产品变化 - Greying out “out-of-stock” product variations with custom stock quantity reduction in WooCommerce 显示在 WooCommerce 可变产品上售罄,当所有变体都缺货时 - Display sold out on WooCommerce variable product when all variations are out of stock woocommerce-显示库存变化 - woocommerce - display variations in stock 如果所有变体都缺货,则从目录中隐藏 WooCommerce 可变产品 - Hide WooCommerce variable product from catalog if all variations are out of stock 显示 现货 WooCommerce 单品简短描述 - Display In stock available variations in WooCommerce single product short description 检查 WooCommerce 产品(简单或变体)是否有库存并将标签显示为短代码 - Check if WooCommerce product (simple or variations) are in stock and display label as shortcode 在 WooCommerce 产品变体中显示 ACF 自定义字段 - Display ACF custom field in WooCommerce product variations 如果 WooCommerce 中的所有变体都缺货,则显示已售罄的灰色按钮 - Display a Sold out greyed button if all variations are out of stock in WooCommerce 对于没有托管库存的 WooCommerce 变体显示“有货”通知 - Display “In Stock” notice for WooCommerce variations with no Managed Stock
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM