Skip to content
Advertisement

Countdown timer until product sale ends on WooCommerce single product page

My goal with this, as I am learning, is to add a countdown timer after the add to cart form on the product page that counts down the time left until the sale is over.

I’m using “How TO – JavaScript Countdown Timer” from the w3schools website and I wrote code for getting the _sale_price_dates_to using $sale_date = get_post_meta( $product->get_id(), '_sale_price_dates_to', true );

My problem is this: nothing shows on the product page. No notice, no errors and nothing in the error log. I believe that this is the problem, but I’m not sure: var countDownDate = <?php $sale_date; ?>

The code so far:

JavaScript

Advertisement

Answer

Multiply by 1000 because Date() requires miliseconds

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement