Developer Usage

JavaScript Events

Checkout Countdown will trigger JavaScript events depending on the status of the countdown timer.

  • ccfwooReachedZero – Triggers when the countdown is zero but may not be finished. At this point the countdown could loop if you have enabled the looping feature in Checkout Countdown Pro.
  • ccfwooFinishedCounting – The countdown has completely finished and the “countdown expired” message will be displayed at this event.

/*
* Event when the countdown has reached zero but may not be finished. Might Loop.
*/
document.addEventListener('ccfwooReachedZero', function (event) {
// Do something in JS.
});


/*
* Event when the countdown has finished counting.
*/
document.addEventListener('ccfwooFinishedCounting', function (event) {
    // Do something in JS.
});

Code language: JavaScript (javascript)

/*
* Event when the countdown has reached zero on the checkout page, trigger a reload.
*/
document.addEventListener('ccfwooReachedZero', function (event) {
// Check if the current page is /checkout/
if (window.location.pathname === '/checkout/') {
    // Refresh the page
    window.location.reload();
}
});Code language: JavaScript (javascript)

Exclude Specific Products from the Countdown

If you need the countdown to trigger for specific products, or product categories, then you can use the filter ccfwoo_cart_product_criteria.

In the below example you’ll see the product ID 33 will be excluded from the countdown criteria, as well as any products belonging to the “t-shirts” category.

TIP: Since the excluded products aren’t being handled by Checkout Countdown Pro. They will remain the customers cart when the countdown has finished.

/**
 * Exclude specific products from cart criteria.
 *
 * @param boolean $should_trigger_countdown if the product should trigger the countdown. Default is true.
 * @param int $product_id The ID of the product.
 * @param array $cart_item The cart item data.
 * @return boolean Whether to handle the product.
 */
function custom_ccfwoo_exclude_specific_products( $should_trigger_countdown, $product_id, $cart_item ) {
    // Array of product IDs to exclude
    $excluded_product_ids = [33, 45, 67, 89]; // Add more product IDs as needed

    // Check if the product ID is in the excluded array
    if (in_array($product_id, $excluded_product_ids)) {
        return false;
    }
	// Check if the product is in the 't-shirts' category.
	if ( has_term( 't-shirts', 'product_cat', $product_id ) ) {
		return false;
	}

	// If none of the conditions are met, return the original value.
	return $should_trigger_countdown;
}

// Hook the new function to the 'ccfwoo_cart_product_criteria' filter.
add_filter( 'ccfwoo_cart_product_criteria', 'custom_ccfwoo_exclude_specific_products', 15, 3 );Code language: PHP (php)
Was this page helpful?