我需要能够隐藏的地方订单按钮在Magento结帐,如果时间x达到

I need to be able to hide the place order button in Magento checkout if time x is reached

本文关键字:结帐 Magento 如果 达到 时间 按钮 方订单 隐藏      更新时间:2023-09-26

如果在结帐阶段达到最后期限,我需要能够隐藏"下订单"按钮。在这个商店里,顾客为他们的订单选择路线,然后他们从路线上取货。

当客户选择路线时,设置了截止时间的cookie,我需要在结帐过程中将该cookie与当前实时时间进行比较,以确保客户不能向已关闭的路线下订单。

我有时间比较在PHP工作,但它只得到当前的时间在页面加载,所以如果有人花太多的时间在结帐可能是一个问题。我尝试过ajax脚本,并将它们放在button.phtml内,但由于某种原因,它们似乎不起作用。我确定这是与magento的主题/文件结构有关的东西,我没有得到

这是我目前的解决方案。它非常简单,但我现在的问题是,我无法弄清楚如何从服务器获得当前时间,因为javascript是客户端,它使用用户的时钟设置。做这么一件简单的事,难得出奇。我想我很快就能弄明白。

此代码位于button.phtml

<script>
  document.getElementById('deadline_reached').style.visibility = 'hidden';  
  function validateDeadline() {
   <?php 
    date_default_timezone_set('Europe/Helsinki');
    $deadlineTimeHuman=$_COOKIE["deadlineDate"];
    $deadlineTimeUnixTimestamp = strtotime($deadlineTimeHuman);
     ?>
  // Current date 
  var timeNowCompare = Math.round(new Date().getTime() / 1000) //Current date is changed to unix timestamp without milliseconds os it matches with php's timestamp format.
  //Cookie's deadline time which has been changed to timestamp is loaded into variable.
  var deadlineDate = "<?php echo $deadlineTimeUnixTimestamp ?>";
  if (timeNowCompare < deadlineDate) // What happens when we are in schedule.
  { 
  alert("Now < Deadline Order can be placed 'n"+"n:"+ timeNowCompare +"'nd:"+deadlineDate); // This is for debugging
  }
  else if (timeNowCompare > deadlineDate) // What happens when current time is higher than deadline.
  { 
  alert("Now > Deadline Order cant be placed 'n"+"n:"+ timeNowCompare +"'nd:"+deadlineDate); // This is for debugging
  document.getElementById('place_order_btn').style.visibility = 'hidden';  
  document.getElementById('deadline_reached').style.visibility = 'visible'; 
  }     
}  
window.setInterval(function(){
  validateDeadline();
 }, 10000);
</script>