[英]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:根据您的软件和您想要做什么,有两种方法:
Hide the div with CSS/JS (like change the display
property).使用 CSS/JS 隐藏 div(例如更改display
属性)。
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.