【问题标题】:Add a spinner to Add to Basket and Place Order buttons in WooCommerce在 WooCommerce 中添加微调器以添加到购物篮和下订单按钮
【发布时间】:2019-11-09 22:01:05
【问题描述】:

我正在对产品使用上传选项,并希望在最终结帐页面的“添加到购物车”按钮和“下订单”按钮上都显示一个微调器。 下面的代码是一个微调器,但我不确定要使用哪个类或如何触发它(PHP 或 jQuery)

这是示例主题:

https://demo.themeisle.com/hestia/product/mens-classic-regular-fit-jean/

/* 
* Custom AJAX spinner on WooCommerce checkout 
* The class used to load the overlay is .blockUI .blockOverlay
* The class used to load the spinner is .woocommerce .loader:before
*
*/
.woocommerce .blockUI.blockOverlay:before,.woocommerce .loader:before {
  height: 3em;
  width: 3em;
  position: absolute;
  top: 50%;
  left: 50%;
  margin-left: -.5em;
  margin-top: -.5em;
  display: block;
  content: "";
  -webkit-animation: none;
  -moz-animation: none;
  animation: none;
  background: url('https://loading.io/spinners/spin/lg.ajax-spinner-gif.gif') center center;
  background-size: cover;
  line-height: 1;
  text-align: center;
  font-size: 2em;
}

这是按钮的 HTML 代码

/* Checkout Button */
<button type="submit" class="button alt" name="woocommerce_checkout_place_order" id="place_order" value="Place order" data-value="Place order">Place order</button>

/* Add to basket Button */
<button type="submit" name="add-to-cart" value="15" class="single_add_to_cart_button button alt">Add to basket</button>

或者甚至使用 Font Awesome,而不是托管的 gif?小问题是它需要在实际添加到购物车时触发,而不是在单击时触发,并且可能未填写选项。

【问题讨论】:

  • 您是通过&lt;form&gt;标签提交此表单,还是通过AJAX等功能提交?

标签: php jquery html css woocommerce


【解决方案1】:

最好的解决方案是使用Promise 在正确的时刻停止微调器。由于我对 WooCommerce 不是很有经验,也许以下解决方案可以帮助您:

$('.button').on('click', () => {
$('.loading').show();
setTimeout(() => {
	$('.loading').hide();
}, 1000); // Stop the spinner after 1 second
})
.loading {
  height: 3em;
  width: 3em;
  position: absolute;
  top: 50%;
  left: 50%;
  margin-left: -.5em;
  margin-top: -.5em;
  display: none;
  content: "";
  -webkit-animation: none;
  -moz-animation: none;
  animation: none;
  background: url('https://loading.io/spinners/spin/lg.ajax-spinner-gif.gif') center center;
  background-size: cover;
  line-height: 1;
  text-align: center;
  font-size: 2em;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
/* Checkout Button */
<button type="submit" class="button alt test" name="woocommerce_checkout_place_order" id="place_order" value="Place order" data-value="Place order">Place order</button>

/* Add to basket Button */
<button type="submit" name="add-to-cart" value="15" class="single_add_to_cart_button button alt">Add to basket</button>

<div class="loading"></div>

【讨论】:

  • 可能需要一个PHP解决方案。就像您按添加到购物篮并且某些字段尚未被选择一样,即使它没有提交,它也会显示微调器。请参阅此处的示例demo.themeisle.com/hestia/product/…
猜你喜欢
  • 1970-01-01
  • 2020-04-14
  • 1970-01-01
  • 2018-10-30
  • 1970-01-01
  • 1970-01-01
  • 2015-01-03
  • 2018-05-08
相关资源
最近更新 更多