当Woocommerce 3.4.5中的产品缺货时,触发购物车中的弹出窗口

时间:2018-11-06 00:56:13

标签: wordpress woocommerce

基本上,该网站用于销售体育课程,并且只能将一门课程添加到购物车中。客户将课程添加到购物车(每当客户将课程添加到购物车时,便会清空购物车),并在这样做时自动将其重定向到购物车。所有这些都很好。

我允许缺货,因此如果缺货,仍可以将产品添加到购物车,但是我现在需要的是单击继续结帐按钮时>,它会触发一个弹出窗口,通知该产品缺货,并阻止客户继续前进。

这是我的做法,但我想听听您的意见。

JS

if($('.product-cart-title .backorder_notification').length){
  $('.checkout-button').attr("href", "#openModal");
} else {
  return;
}

CSS

.modalDialog {
    position: fixed;
    font-family: Arial, Helvetica, sans-serif;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(198, 195, 195, 0.55);
    z-index: 99999;
    opacity:0;
    -webkit-transition: opacity 400ms ease-in;
    -moz-transition: opacity 400ms ease-in;
    transition: opacity 400ms ease-in;
    pointer-events: none;
}
.modalDialog:target {
    opacity:1;
    pointer-events: auto;
}
.modalDialog > div {
    width: 400px;
    position: relative;
    margin: 10% auto;
    padding: 5px 20px 13px 20px;
    background: #fff;
    -webkit-box-shadow: 1px 1px 10px 0px rgba(0,0,0,0.5);
-moz-box-shadow: 1px 1px 10px 0px rgba(0,0,0,0.5);
box-shadow: 1px 1px 10px 0px rgba(0,0,0,0.5);
  -webkit-transition: opacity 400ms ease-in;
-moz-transition: opacity 400ms ease-in;
transition: opacity 400ms ease-in;
}
.closemodal {
    background: #fff;
    color: #811937;
    line-height: 25px;
    position: absolute;
    right: 0;
    text-align: center;
    top: 0;
    width: 24px;
    text-decoration: none;
    font-weight: bold;
}

HTML

<div id="openModal" class="modalDialog">
    <div>
        <a href="#close" title="Close" class="closemodal">X</a>
        <h2>Sorry!</h2>
        <p>The item is currently out of stock.</p>
    </div>
</div>

0 个答案:

没有答案
相关问题