问题
<script>
jQuery(function() {
var $ = jQuery;
$(document).on('touchstart mouseover', 'a#wsite-com-minicart-checkout-button', function(e) {
var totalCount = $( "span#wsite-nav-cart-num" ).text();
var totalNeeded = 12;
if (totalCount < totalNeeded) {
var totalItems = totalNeeded - totalCount;
$("a#wsite-com-minicart-checkout-button").click(function(event){
event.stopImmediatePropagation();
alert('Orders under ' + totalNeeded + ' packages are only available for pickup. Click "Order for Pickup" to proceed to checkout. If not, click "OK" and add ' + totalItems + ' more packages for us to ship your order.');
return false;
});
}
});
});
</script>
Here's the link to view online: http://poloniafoods.weebly.com/store/p10/kozackie
Select any city, click "add to cart" then click "checkout" to see the popup window.
If a button isn't possible maybe I can use a checkbox?
回答1:
I have altered the text in the confirm popup, sightly, but this is what you are looking for:
<script>
jQuery(function() {
var $ = jQuery;
$(document).on('touchstart mouseover', 'a#wsite-com-minicart-checkout-button', function(e) {
var totalCount = $( "span#wsite-nav-cart-num" ).text();
var totalNeeded = 12;
if (totalCount < totalNeeded) {
var totalItems = totalNeeded - totalCount;
$("a#wsite-com-minicart-checkout-button").click(function(event){
event.stopImmediatePropagation();
var PickupOnly = confirm('Orders under ' + totalNeeded + ' packages are only available for local pickup. If this order is for local pickup only, click "Ok" to proceed to checkout. If not, click "Cancel" and add ' + totalItems + ' more packages for us to ship your order.');
if (PickupOnly !== true) {
return false;
}
});
}
});
});
</script>
Basically if PickupOnly is NOT true, they will stay on the page. If PickupOnly is true, then it will let them proceed to the checkout.
回答2:
Confirm returns true or false. So instead of alert do
Var Result = Confirm("your string here");
If (result === true) {
// user wants to proceed write code to handle
} else {
// user clicked cancel handle that
}
来源:https://stackoverflow.com/questions/39070215/how-do-i-add-a-order-for-pickup-button-to-my-popup-window-allowing-to-proceed