keithpickeringkmg
Forum Replies Created
-
Forum: Plugins
In reply to: [WooCommerce Cart Stock Reducer] Show timers on individual cart itemsThanks for the plugin by the way, it’s super useful and I was lucky to find it! Seems crazy this functionality isn’t built into WC to begin with, I could see the default setup (not decreasing quantity until an order is complete) causing a lot of headaches in high-demand stores.
Forum: Plugins
In reply to: [WooCommerce Cart Stock Reducer] Show timers on individual cart itemsOkay, I did this in a slightly hacky way that involves overriding the cart.php template, but I was doing that already so it worked out for me.
Luckily the expiry time is stored in the data for each cart item (thanks!) so I added this to the foreach loop in cart.php where I wanted the timers to appear:
<div class="cart-item-countdown" data-time="<?php echo $cart_item['csr_expire_time'] - time(); ?>"> <?php _e('Reserved for', 'kincaid'); ?> <span></span> </div>
The current epoch time is subtracted from the csr_expire_time, which is exactly what the plugin already does for the timer up top, so there’s no discrepancy.
Then you just need some javascript to run on the cart page:
jQuery('.cart-item-countdown').each(function() { var $this = jQuery(this), time = parseInt($this.data('time')), soon = false; $this.find('span').countdown({ until: time, format: 'dhmS', layout: '{mnn}{sep}{snn}', onTick: function(periods) { if (periods[5] <= 1 && !soon) { $this.addClass('cart-item-countdown--soon'); soon = true; } } }); });
I’m adding a class to turn the countdown red when the timer has less than 2 minutes left, but that’s totally optional. Hopefully this can help someone else out.
EDIT: Oh, also, that 2 minute check probably won’t work right if your expiration time is 1 hour or higher. Ours is only 5 minutes (extremely limited-edition prints, so people need to checkout or get out) so simply checking for the minute value works.
- This reply was modified 6 years, 11 months ago by keithpickeringkmg.
Forum: Plugins
In reply to: [WooCommerce Cart Stock Reducer] Show timers on individual cart itemsI need to get this done for work, so I can definitely make a pull request once I have it working.
Where do you think you’d start with this? Do you maybe have a general idea of how it should be done?
@jonboss Thanks so much for the quick reply! Please do let me know if you get this working.
@jonboss Did you get this figured out? We need the EXACT same functionality.