gpt4 book ai didi

php - 在 Woocommerce 中启动和停止 Ajax Overlay 微调器

转载 作者:行者123 更新时间:2023-12-01 01:21:23 24 4
gpt4 key购买 nike

我开发了自定义支付网关,它将通过ajax延迟处理支付。我想展示目前在 woocommerce 中使用的相同微调器。

这是我的 jQuery 代码的摘录:

function callAjax(){
jQuery.ajax({
type : "POST",
url: '<?php echo site_url().'/?wc-api=custom_ function'; ?>',
data: response,
//data: {action:'gateway'},
dataType : "json",
cache: false,
success: function(response) {
//alert("Your vote could not be added");
//alert(response);
flag = true;
// window.location = response.redirect;
//console.log(response);
return false;
}
});
}

setTimeout(
function(){ callAjax();
}, 3000);

所以我想做这个:

please check with the image

如何在结帐页面中启动和停止 ajax Woocommerce 叠加旋转器?

最佳答案

Woocommerce 使用 jQuery BlockUI Plugin在某些 jQuery 事件和特定页面上使用动画微调器制作阻塞叠加。

下面是结帐页面上的示例,页面加载后,它将在 2 秒延迟后激活 woocommerce 旋转器,并在 3 秒后停止它们:

add_action('wp_footer', 'spinners_example_on_checkout_jquery_script');
function spinners_example_on_checkout_jquery_script() {
if ( is_checkout() && ! is_wc_endpoint_url() ) :
?>
<script type="text/javascript">
jQuery( function($){
// Targeting checkout checkout payment and Review order table like Woocommerce does.
var a = '.woocommerce-checkout-payment, .woocommerce-checkout-review-order-table';

// Starting spinners with a delay of 2 seconds
setTimeout(function() {
// Starting spinners
$(a).block({
message: null,
overlayCSS: {
background: "#fff",
opacity: .6
}
});

console.log('start');

// Stop spinners after 3 seconds
setTimeout(function() {
// Stop spinners
$(a).unblock();

console.log('stop');
}, 5000);
}, 2000);
});
</script>
<?php
endif;
}

代码位于事件子主题(或事件主题)的 function.php 文件中。经过测试并有效。

jQuery BlockUI Plugin官方文档。

关于php - 在 Woocommerce 中启动和停止 Ajax Overlay 微调器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54536575/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com