Top 7 Programming Questions and their Answers about Countdown Timer and Flash Sales in PrestaShop

In the present age of competition, successful are those merchants who adapts the latest trends in their shops. These trends a basically a way to facilitate the customers more than your competitors. This is way to capture the user minds in such a way that they remember your shop due to some prominence or facilitation available on your store. One such facilitation or prominence is counter down timer and flash sales.  

According to this idea, merchants allow some of their products in sale at low prices. They create a special page on their store where they display only those products that are on sale. There will a countdown timer available at that page that show that when this offer start and when this will end and all will be shown using a running timer. Similarly, there will be timer also on product page. Admin can make more than one flash sales offers in this way. To make it more successful, admin can show flash sales banner on home and other pages.  

Although, this feature is not available by default in PrestaShop but anyone with knowledge of coding can use javascript queries in product.tpl to do this. Those who are not expert, don’t worry because you can use free or paid countdown timers modules and get this functionality done on your store.

Here our purpose is not to promote a module or service but here we want to provide solution to some of the problems related to countdown and flash sales feature within PrestaShop stores. So given here top 5 problems and their solution related to it;

Question No. 1: Hello, I want to show on product pages that how much time is left from shipping the product to the customers? Please send me the code and also tell me that where to insert it. Currently, I am using PrestaShop v1.6.1.7

Answer: You can insert the following code in the product.tpl and that will work for you.

<scripttype="text/javascript">

$(document).ready(function(){

    setInterval(function(){

        var now =newDate();

        var day = now.getDay();

        var end;

    

        if(day >=1&& day <=5){

            end =newDate(now.getYear(), now.getMonth(), day,18,0,0,0);    

        }else{

            end =newDate(now.getYear(), now.getMonth(), day,15,0,0,0);

        }

        

        var timeleft = end.getTime()- now.getTime();

        var diff =newDate(timeleft);

        

    

        $("#timeleft").html("Order now and we ship your order in: "+ diff.getHours()+"h "+ diff.getMinutes()+"Min "+ diff.getSeconds()+"Sec");

        

    },1000);

});

</script>

 

<divid="timeleft">Order now and we ship your order in:</div>

Question No. 2: Hi, I have two PrestaShop stores and I want to show countdown timer in the following way;

  • On one store show a countdown timer for a single product. This timer will show below the add to cart button on product page.
  • On the other store, I want to show this timer for multiple products.

Please let me know that where and how to paste the code?

Answer: You can place the following code in product.tpl file for single product timer;

{if $product->id == XXX}you countdown timer code here{/if}

Here xxx is the product ID.

For placing timer on multiple product page, use the following code;

{if $product->id == XXX OR $product->id == XX OR $product->id == X}you countdown timer code here{/if}

Question No.3: Hi, I am creating a countdown timer module that will show a timer on left column of store. I have written the code for timer and now want to place it in product.tpl. I am placing it but it is unsuccessful. Please help me on this.

Answer: Go to the left column hook of product.tpl file and add the variables for smarty array.

In old ps:

global $smarty;

$smarty->assign('myVariable', $myvariable);

new ps:

$this->smarty->assign('myVariable', $myvariable);

Your product.tpl file will look like this after defining smarty variables.

public function hookLeftColumn($params)
{

$x = time();
$tre = mktime(14);
if ($x < $tre) {
$y = strtotime('today 14:00:00');
}
else {
$y = strtotime('tomorrow 14:00:00');
}
$result = floor(($y - $x) / 60);
$s = $result * 60;
$ms = $s * 1000;

 

global $smarty;
$smarty->assign('myVariable', $result);
return $this->display(__FILE__, 'welcome.tpl');
}

Question No. 4: Hi, I want to show a countdown timer module on my product pages with the situation like this;

My delivery time for shop is 1Pm daily. So when there is time left from 1PM, a countdown timer will show there. Similarly, if orders are placed after 1PM, a timer will show considering the delivery time of next day 1PM.

Answer: You can create a simple jquery module that is set to your local time of 1PM. Then display the counter for it and show the text accordingly. Another solution is to use PHP to check the time of delivery and show timer in this way. If you are a developer, you can do it by self. In the other case, you can contact the PrestaShop custom module developer to get this task done.

Question No. 5: Hi, I am using a countdown timer on my PrestaShop store. The problem is that timer is only showing when CACHE is OFF. In on state, timer will not work. How can I make the timer working in both conditions?

Answer: This problem may be due to the reason that old product.tpl is still available in cache. So it does not allow the new one to take effect. Now the solution is to clear the cache and turn on the force compile. Run the code and when it is working. Turn on the cache and turn off the force compile.

Question No. 6: Hi, I have installed a new count down timer module on my PrestaShop store. For its correct working, I have to place the code in the hook {hook h=’productListDiscountCountdown’ product=$product}. I don’t know where to place this code?

Answer: You need to go to product.tpl file and paste this code after any closing tag like "</div>". Use the <div> of that location where you want to display the timer.

Question No. 7: Hi, I want to show promotion dates on my product page e.g. start and end dates.

Answer: Go to the product.tpl file and paste this code there;

to display special price expiry date:

{$product->specificPrice['to']}

start date:

{$product->specificPrice['from']}

Note: These questions are answered by top community developers and do not reflect FMEModules.