jquery - 在 woo-commerce wordpress 中添加到购物车操作之前应用 jQuery
问题描述
在用户继续添加到购物车之前,我需要一个确认弹出窗口。如果用户在确认框中单击是,则应将产品添加到购物车并重定向到购物车页面,就像在正常流程中发生的那样,在 woo commerce wordpress 中。我在woocommerce/templates/single-product/add-to-cart/simple.php
.
当单击“是”按钮时,它会重定向到页面并且不将产品添加到购物车。以下是我的相同代码:
var cat_name = document.getElementById('cat_name').value;
if(cat_name != ''){
var el = document.getElementById('add_to_cart_submit');
el.addEventListener('submit', function(e){
e.preventDefault();
$("#dialog-confirm").dialog({
resizable: false,
modal: true,
title: "Terms and Conditions",
height: "auto",
width: 400,
open: function(event, ui) {
$('.ui-widget-overlay').bind('click', function()
{
$("#dialog-confirm").dialog('close');
}); },
create: function (e, ui) {
var pane = $(this).dialog("widget").find(".ui-dialog-buttonpane")
$("<label class='confirm-check' ><input type='checkbox'/> I acknowledge I have read and accepted the above statements</label><p id='insideStyle' style='display:none;color:red; margin: 0; font-size: 14px;'>Required*</p>").prependTo(pane)
},
buttons: {
"Yes": function () {
if($('.confirm-check input').is(":checked")){
$(this).dialog('close');
$("#add_to_cart_submit").submit();
}else{
$("#insideStyle").show();
}
},
"No": function () {
$(this).dialog('close');
}
}
});
}, false);
}
解决方案
推荐阅读
- html - 修复了即使 z-index=10000 也出现在 img 后面的导航栏
- python - Django 测试失败,posts.models.Post.DoesNotExist:后匹配查询不存在
- java - Eclipse 中缺少 Project Facets
- php - 在 Woocommerce 中根据产品类别添加自定义结帐字段
- python - Removing NaN rows from a three dimensional array
- excel - 如何在用户窗体对象指示器名称(VBA)中有一个变量
- java - 无效的 bean 定义:无法解析占位符
- if-statement - 非常简单的 if/else 语句似乎在倒退
- scala - 火花作业给出路径已经存在错误,即使使用 df.overwrite
- appium - 如何使用 uiautomator 与嵌入在 android.webkit.WebView 中的元素进行交互