How do I add a “Order for Pickup” button to my popup window allowing to proceed to checkout?

旧时模样 提交于 2019-12-12 03:37:44

问题


<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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!