This snippet increases the Fear Of Missing Out (FOMO) and urgency factor by showing a countdown timer on the product loop.
Specifically, the timer counts down to the sale end price. If there is no sale end price, the countdown timer will not show.
The “sale to price” is set in the product settings under the “General” tab and saved in the database in the “wp_postmeta” table with the meta key “_sale_price_dates_to”.
By showing a countdown, the customer knows that the sale will end, an encourages them to purchase now rather than wait and potentially miss out on the sales price.
/**
* Snippet Name: WooCommerce Show Sale Ending Countdown Timer On Loop
* Snippet Author: ecommercehints.com with props to www.w3schools.com for the JS countdown
*/
add_action( 'woocommerce_after_shop_loop_item_title', 'ecommercehints_show_countdown_timer_on_loop', 15 );
function ecommercehints_show_countdown_timer_on_loop() {
global $product;
$sales_price_to = date( "M j, Y", get_post_meta( $product->id, '_sale_price_dates_to', true )); // Get the sales price 'to' date
if ( $product->is_on_sale() && $sales_price_to != "" ) {
echo 'Sales ends in:
';
}
};
2 Responses
1. Doesn’t show anything after “Sales ends in”. I thought it might be a theme issue for me, so I tried on Storefront theme. Same result. Doesn’t show the actual timer.
2. Would be really great to get code snippet to show the same timer on single product page too.
Hey Manish,
I’ve just tried again my end and it seems ok. Although I did just update the JS part of the snippet. Could you try again please and let me know? Keep in mind this snippet is for the product archive template not the single product template – it will be a case of using the same code but a different hook…this is a steer in the right direction (WooCommerce Product Page Countdown Timer). If you’d like me to implement on your site, drop me a message 😀 https://ecommercehints.com/hire-me