Plugin Directory

Changeset 3115281


Ignore:
Timestamp:
07/10/2024 06:11:30 AM (21 months ago)
Author:
morganhvidt
Message:

version 4.0.0

Location:
checkout-countdown-for-woocommerce
Files:
27 added
10 edited

Legend:

Unmodified
Added
Removed
  • checkout-countdown-for-woocommerce/trunk/assets/checkout-countdown.css

    r2167353 r3115281  
    1 /* Checkout Countdown bar CSS */
    21.checkout-countdown-wrapper.checkout-countdown-bar {
    32    text-align: center;
     
    65    z-index: 9999;
    76}
    8 .ccfwoo-is-hidden {
     7.checkout-countdown-is-hidden {
    98    display: none;
    109}
    11 /* Loading Dots */
    12 @-webkit-keyframes ccfwoo-dot-keyframes {
     10@-webkit-keyframes checkout-countdown-loading-dot-keyframes {
    1311    0% {
    1412        opacity: 0.4;
     
    2725    }
    2826}
    29 @keyframes ccfwoo-dot-keyframes {
     27@keyframes checkout-countdown-loading-dot-keyframes {
    3028    0% {
    3129        opacity: 0.4;
     
    4442    }
    4543}
    46 .ccfwoo-loading-dots {
     44.checkout-countdown-loading {
    4745    width: 100%;
    4846}
    49 .ccfwoo-loading-dots--dot {
    50     -webkit-animation: ccfwoo-dot-keyframes 1.5s infinite ease-in-out;
    51     animation: ccfwoo-dot-keyframes 1.5s infinite ease-in-out;
     47.checkout-countdown-loading-dot {
     48    -webkit-animation: checkout-countdown-loading-dot-keyframes 1.5s infinite ease-in-out;
     49    animation: checkout-countdown-loading-dot-keyframes 1.5s infinite ease-in-out;
    5250    background-color: rgb(209, 209, 209);
    5351    border-radius: 10px;
     
    5654    width: 5px;
    5755}
    58 .ccfwoo-loading-dots--dot:nth-child(2) {
     56.checkout-countdown-loading-dot:nth-child(2) {
    5957    -webkit-animation-delay: 0.5s;
    6058    animation-delay: 0.5s;
    6159}
    62 .ccfwoo-loading-dots--dot:nth-child(3) {
     60.checkout-countdown-loading-dot:nth-child(3) {
    6361    -webkit-animation-delay: 1s;
    6462    animation-delay: 1s;
  • checkout-countdown-for-woocommerce/trunk/assets/checkout-countdown.js

    r3065377 r3115281  
    77 */
    88
    9 // eslint-disable-next-line
    109var ccfwooController = {
    1110    counting: false,
    12     cartItems: ccfwooLocal.cart_count,
    13     cart: 0,
    1411    interval: false,
    1512    htmlElements: false,
     13    forceStop: false, // Used to override the criteria.
    1614    config: ccfwooLocal, // localized data.
    1715    setElements(classNames) {
     
    5048                ccfwooFinishedCountingHTML(contentElement);
    5149            }
    52             if (textType === "banner") {
     50            if (
     51                textType === "banner" &&
     52                !elements[i]?.classList.contains("checkout-countdown-notice")
     53            ) {
    5354                ccfwooBannerHTML(contentElement);
    5455            }
     
    6061        return this.counting;
    6162    },
    62     hasCart() {
    63         return this.cartItems >= 1 ? true : false;
    64     },
    65     getCartItems() {
    66         return this.cartItems;
    67     },
    68     setCartItems(value) {
    69         this.cartItems = value;
     63    hasCartCriteria() {
     64        var cartFragment = document.querySelector(".ccfwoo-cart-fragment");
     65
     66        if (cartFragment && !this.forceStop) {
     67            var hasValidCart =
     68                cartFragment.getAttribute("data-has-cart-criteria") &&
     69                cartFragment.getAttribute("data-has-cart-criteria") == true;
     70
     71            return hasValidCart;
     72        }
     73
     74        return false;
    7075    },
    7176    setIsCounting(value) {
     
    7479        } else {
    7580            ccfwooController.classes("add", "checkout-countdown-is-counting");
    76             ccfwooController.classes("remove", "ccfwoo-is-hidden");
     81            ccfwooController.classes("remove", "checkout-countdown-is-hidden");
     82            ccfwooController.classes("remove", "checkout-countdown-is-expired");
    7783        }
    7884
     
    8995    startInterval() {
    9096        // we are only counting if there's a cart.
    91         if (this.hasCart()) {
     97        if (this.hasCartCriteria()) {
    9298            this.setIsCounting(true);
    9399        } else {
     
    154160
    155161/**
    156  * Init Checkout Countdown - Pure JS version of Document Ready.
     162 * Init Checkout Countdown.
    157163 */
    158164document.addEventListener("DOMContentLoaded", function (event) {
    159165    // eslint-disable-line
    160     ccfwooController.setElements(); // Set the HTML Elements.
    161 
    162     // Combat Caching plugins by setting the cart items from cookies.
    163     const cookie = ccfwooGetCookie("woocommerce_items_in_cart");
    164 
    165     const cookieCart = cookie && cookie >= 1 ? 1 : 0;
    166     ccfwooController.setCartItems(cookieCart);
     166    ccfwooController.setElements(); // Get instances of Checkout Countdown in the DOM.
     167    // Register new event, ccfwooHasLoaded.
     168    ccfwooController.triggerEvent("document", "ccfwooLoaded", true);
    167169
    168170    ccfwooCounter(); // Run without delay once.
     
    184186});
    185187
    186 /*
     188/**
    187189 * Handles the countdown as an interval.
    188190 */
    189191function ccfwooCounter() {
    190192    // Stop early if no cart available and display the banner.
    191     if (!ccfwooController.hasCart()) {
     193    if (!ccfwooController.hasCartCriteria()) {
    192194        ccfwooController.setHtml("banner");
    193195        ccfwooController.classes("remove", "checkout-countdown-is-counting");
     
    215217                return;
    216218            }
     219            // Expired text.
     220            ccfwooController.classes("add", "checkout-countdown-is-expired");
     221            ccfwooController.setHtml("expired");
     222
    217223            ccfwooController.triggerEvent("document", "ccfwooFinishedCounting", true);
    218             // Expired text.
    219             ccfwooController.setHtml("expired");
    220224        }, 1000);
    221225        // Wait 5 seconds and display default text.
     
    268272 */
    269273function ccfwooBannerHTML(element) {
    270     // Exit if no element.
    271274    if (!element) {
    272275        return;
    273276    }
    274 
    275277    // Banner message if selected.
    276278    if (
     
    364366    return formattedDifference;
    365367}
    366 /**
    367  * Get any cookie from the browsers. e.g woocommerce_items_in_cart.
    368  */
    369 function ccfwooGetCookie(name) {
    370     const match = document.cookie.match(new RegExp("(^| )" + name + "=([^;]+)"));
    371     if (match) return match[2];
    372 }
    373368
    374369/**
  • checkout-countdown-for-woocommerce/trunk/assets/checkout-countdown.min.css

    r2167353 r3115281  
    1 .checkout-countdown-wrapper.checkout-countdown-bar{text-align:center;padding:15px 0;width:100%;z-index:9999}.ccfwoo-is-hidden{display:none}@-webkit-keyframes ccfwoo-dot-keyframes{0%{opacity:.4;-webkit-transform:scale(1,1);transform:scale(1,1)}50%{opacity:1;-webkit-transform:scale(1.2,1.2);transform:scale(1.2,1.2)}100%{opacity:.4;-webkit-transform:scale(1,1);transform:scale(1,1)}}@keyframes ccfwoo-dot-keyframes{0%{opacity:.4;-webkit-transform:scale(1,1);transform:scale(1,1)}50%{opacity:1;-webkit-transform:scale(1.2,1.2);transform:scale(1.2,1.2)}100%{opacity:.4;-webkit-transform:scale(1,1);transform:scale(1,1)}}.ccfwoo-loading-dots{width:100%}.ccfwoo-loading-dots--dot{-webkit-animation:ccfwoo-dot-keyframes 1.5s infinite ease-in-out;animation:ccfwoo-dot-keyframes 1.5s infinite ease-in-out;background-color:#d1d1d1;border-radius:10px;display:inline-block;height:5px;width:5px}.ccfwoo-loading-dots--dot:nth-child(2){-webkit-animation-delay:.5s;animation-delay:.5s}.ccfwoo-loading-dots--dot:nth-child(3){-webkit-animation-delay:1s;animation-delay:1s}
     1.checkout-countdown-wrapper.checkout-countdown-bar{text-align:center;padding:15px 0;width:100%;z-index:9999}.checkout-countdown-is-hidden{display:none}@-webkit-keyframes checkout-countdown-loading-dot-keyframes{0%{opacity:.4;-webkit-transform:scale(1,1);transform:scale(1,1)}50%{opacity:1;-webkit-transform:scale(1.2,1.2);transform:scale(1.2,1.2)}100%{opacity:.4;-webkit-transform:scale(1,1);transform:scale(1,1)}}@keyframes checkout-countdown-loading-dot-keyframes{0%{opacity:.4;-webkit-transform:scale(1,1);transform:scale(1,1)}50%{opacity:1;-webkit-transform:scale(1.2,1.2);transform:scale(1.2,1.2)}100%{opacity:.4;-webkit-transform:scale(1,1);transform:scale(1,1)}}.checkout-countdown-loading{width:100%}.checkout-countdown-loading-dot{-webkit-animation:checkout-countdown-loading-dot-keyframes 1.5s infinite ease-in-out;animation:checkout-countdown-loading-dot-keyframes 1.5s infinite ease-in-out;background-color:#d1d1d1;border-radius:10px;display:inline-block;height:5px;width:5px}.checkout-countdown-loading-dot:nth-child(2){-webkit-animation-delay:.5s;animation-delay:.5s}.checkout-countdown-loading-dot:nth-child(3){-webkit-animation-delay:1s;animation-delay:1s}
  • checkout-countdown-for-woocommerce/trunk/assets/checkout-countdown.min.js

    r2732232 r3115281  
    1 var ccfwooController={counting:!1,cartItems:ccfwooLocal.cart_count,cart:0,interval:!1,htmlElements:!1,config:ccfwooLocal,setElements(o){const e=o||"checkout-countdown-wrapper",t=document.getElementsByClassName(e);return this.htmlElements=t,t},getElements(){return this.htmlElements},setHtml(o,e,t){if(t=t||!1,!(e=e||this.htmlElements)||!o)return!1;let n;for(n=0;n<e.length;n++){const c=e[n].firstElementChild;"loading"===o&&ccfwooLoadingHTML(c),"counting"===o&&ccfwooUpdateCountingHTML(c,t),"expired"===o&&ccfwooFinishedCountingHTML(c),"banner"===o&&ccfwooBannerHTML(c)}return!0},isCounting(){return this.counting},hasCart(){return this.cartItems>=1},getCartItems(){return this.cartItems},setCartItems(o){this.cartItems=o},setIsCounting(o){!1===o?ccfwooController.classes("remove","checkout-countdown-is-counting"):(ccfwooController.classes("add","checkout-countdown-is-counting"),ccfwooController.classes("remove","ccfwoo-is-hidden")),this.counting=o},stopInterval(o){!0===o&&localStorage.removeItem("ccfwoo_end_date"),this.setIsCounting(!1),clearInterval(this.interval)},startInterval(){this.hasCart()?this.setIsCounting(!0):this.setIsCounting(!1),this.interval=setInterval(ccfwooCounter,1e3)},restartInterval(){this.stopInterval(!0),this.setHtml("loading"),this.startInterval()},setNewDate(o){const e=o||60*ccfwooLocal.ccfwoo_minutes,t=new Date;return t.setSeconds(t.getSeconds()+e),localStorage.setItem("ccfwoo_end_date",t),t},triggerEvent(o,e){if(e=new Event(e,{bubbles:!0}),"document"===o&&document.dispatchEvent(e),"window"===o&&window.dispatchEvent(e),"body"===o){document.getElementsByTagName("BODY")[0].dispatchEvent(e)}},classes(o,e,t){const n=this.htmlElements;if(!n)return!1;let c;for(c=0;c<n.length;c++)"add"===o&&n[c].classList.add(e),"remove"===o&&n[c].classList.remove(e),"replace"===o&&t&&(n[c].classList.remove(e),n[c].classList.add(t))}};function ccfwooCounter(){if(!ccfwooController.hasCart())return ccfwooController.setHtml("banner"),ccfwooController.classes("remove","checkout-countdown-is-counting"),void ccfwooController.stopInterval(!0);const o=ccfwooGetDurationRange(),e=ccfwooFormatDuration(o.start,o.end);!0===e.isPast?(ccfwooController.setHtml("loading"),ccfwooController.stopInterval(!0),ccfwooController.triggerEvent("document","ccfwooReachedZero",!0),setTimeout((function(){ccfwooController.isCounting()||(ccfwooController.triggerEvent("document","ccfwooFinishedCounting",!0),ccfwooController.setHtml("expired"))}),1e3),setTimeout((function(){ccfwooController.isCounting()||ccfwooController.setHtml("banner")}),1e3*parseInt(ccfwooLocal.expired_message_seconds))):ccfwooController.setHtml("counting",!1,e)}function ccfwooUpdateCountingHTML(o,e){if(!o)return;let t=ccfwooLocal.countdown_text.replace("{minutes}",e.minutes);t=t.replace("{seconds}",e.seconds),t=t.replace("{hours}",e.hours),t=t.replace("{days}",e.days),o.innerHTML=t}function ccfwooLoadingHTML(o){o&&(o.innerHTML=ccfwooLocal.loading_html)}function ccfwooBannerHTML(o){o&&"on"===ccfwooLocal.enable_banner_message&&ccfwooLocal.banner_message_text&&(o.innerHTML=ccfwooLocal.banner_message_text)}function ccfwooFinishedCountingHTML(o){o&&(o.innerHTML=ccfwooLocal.expired_text)}function ccfwooGetDurationRange(){const o=new Date;let e=!!localStorage.getItem("ccfwoo_end_date")&&localStorage.getItem("ccfwoo_end_date");e=e?new Date(e):ccfwooController.setNewDate();return{start:o,end:e}}function ccfwooFormatDuration(o,e){const t=new Date(e)-new Date(o),n=Number.isInteger(t),c=Math.floor(t/1e3/60/60/24/7),r=Math.floor(t/1e3/60/60/24-7*c),s=Math.floor(t/1e3/60/60-7*c*24-24*r),a=Math.floor(t/1e3/60-7*c*24*60-24*r*60-60*s),l=Math.floor(t/1e3-7*c*24*60*60-24*r*60*60-60*s*60-60*a),i=t/1e3<=0;return{milliseconds:Math.floor(t-7*c*24*60*60*1e3-24*r*60*60*1e3-60*s*60*1e3-60*a*1e3-1e3*l),seconds:ccfwooLeadingZero(l),minutes:ccfwooLeadingZero(a),hours:s,days:r,weekdays:c,totalSeconds:t/1e3,isPast:i,ValidDates:n}}function ccfwooGetCookie(o){const e=document.cookie.match(new RegExp("(^| )"+o+"=([^;]+)"));if(e)return e[2]}function ccfwooLeadingZero(o){if("on"===ccfwooLocal.leading_zero){const e=2;for(o=o.toString();o.length<e;)o="0"+o;return o}return o}document.addEventListener("DOMContentLoaded",(function(o){ccfwooController.setElements();const e=ccfwooGetCookie("woocommerce_items_in_cart"),t=e&&e>=1?1:0;ccfwooController.setCartItems(t),ccfwooCounter(),ccfwooController.startInterval(),ccfwooController.isCounting()&&ccfwooController.classes("add","checkout-countdown-is-counting")})),document.addEventListener("ccfwooFinishedCounting",(function(o){ccfwooController.classes("remove","checkout-countdown-is-counting")}));
     1var ccfwooController={counting:!1,interval:!1,htmlElements:!1,forceStop:!1,config:ccfwooLocal,setElements(o){const e=o||"checkout-countdown-wrapper",t=document.getElementsByClassName(e);return this.htmlElements=t,t},getElements(){return this.htmlElements},setHtml(o,e,t){if(t=t||!1,!(e=e||this.htmlElements)||!o)return!1;let n;for(n=0;n<e.length;n++){const c=e[n].firstElementChild;"loading"===o&&ccfwooLoadingHTML(c),"counting"===o&&ccfwooUpdateCountingHTML(c,t),"expired"===o&&ccfwooFinishedCountingHTML(c),"banner"!==o||e[n]?.classList.contains("checkout-countdown-notice")||ccfwooBannerHTML(c)}return!0},isCounting(){return this.counting},hasCartCriteria(){var o=document.querySelector(".ccfwoo-cart-fragment");return!(!o||this.forceStop)&&(o.getAttribute("data-has-cart-criteria")&&1==o.getAttribute("data-has-cart-criteria"))},setIsCounting(o){!1===o?ccfwooController.classes("remove","checkout-countdown-is-counting"):(ccfwooController.classes("add","checkout-countdown-is-counting"),ccfwooController.classes("remove","checkout-countdown-is-hidden"),ccfwooController.classes("remove","checkout-countdown-is-expired")),this.counting=o},stopInterval(o){!0===o&&localStorage.removeItem("ccfwoo_end_date"),this.setIsCounting(!1),clearInterval(this.interval)},startInterval(){this.hasCartCriteria()?this.setIsCounting(!0):this.setIsCounting(!1),this.interval=setInterval(ccfwooCounter,1e3)},restartInterval(){this.stopInterval(!0),this.setHtml("loading"),this.startInterval()},setNewDate(o){const e=o||60*ccfwooLocal.ccfwoo_minutes,t=new Date;return t.setSeconds(t.getSeconds()+e),localStorage.setItem("ccfwoo_end_date",t),t},triggerEvent(o,e){if(e=new Event(e,{bubbles:!0}),"document"===o&&document.dispatchEvent(e),"window"===o&&window.dispatchEvent(e),"body"===o){document.getElementsByTagName("BODY")[0].dispatchEvent(e)}},classes(o,e,t){const n=this.htmlElements;if(!n)return!1;let c;for(c=0;c<n.length;c++)"add"===o&&n[c].classList.add(e),"remove"===o&&n[c].classList.remove(e),"replace"===o&&t&&(n[c].classList.remove(e),n[c].classList.add(t))}};function ccfwooCounter(){if(!ccfwooController.hasCartCriteria())return ccfwooController.setHtml("banner"),ccfwooController.classes("remove","checkout-countdown-is-counting"),void ccfwooController.stopInterval(!0);const o=ccfwooGetDurationRange(),e=ccfwooFormatDuration(o.start,o.end);!0===e.isPast?(ccfwooController.setHtml("loading"),ccfwooController.stopInterval(!0),ccfwooController.triggerEvent("document","ccfwooReachedZero",!0),setTimeout((function(){ccfwooController.isCounting()||(ccfwooController.classes("add","checkout-countdown-is-expired"),ccfwooController.setHtml("expired"),ccfwooController.triggerEvent("document","ccfwooFinishedCounting",!0))}),1e3),setTimeout((function(){ccfwooController.isCounting()||ccfwooController.setHtml("banner")}),1e3*parseInt(ccfwooLocal.expired_message_seconds))):ccfwooController.setHtml("counting",!1,e)}function ccfwooUpdateCountingHTML(o,e){if(!o)return;let t=ccfwooLocal.countdown_text.replace("{minutes}",e.minutes);t=t.replace("{seconds}",e.seconds),t=t.replace("{hours}",e.hours),t=t.replace("{days}",e.days),o.innerHTML=t}function ccfwooLoadingHTML(o){o&&(o.innerHTML=ccfwooLocal.loading_html)}function ccfwooBannerHTML(o){o&&"on"===ccfwooLocal.enable_banner_message&&ccfwooLocal.banner_message_text&&(o.innerHTML=ccfwooLocal.banner_message_text)}function ccfwooFinishedCountingHTML(o){o&&(o.innerHTML=ccfwooLocal.expired_text)}function ccfwooGetDurationRange(){const o=new Date;let e=!!localStorage.getItem("ccfwoo_end_date")&&localStorage.getItem("ccfwoo_end_date");e=e?new Date(e):ccfwooController.setNewDate();return{start:o,end:e}}function ccfwooFormatDuration(o,e){const t=new Date(e)-new Date(o),n=Number.isInteger(t),c=Math.floor(t/1e3/60/60/24/7),r=Math.floor(t/1e3/60/60/24-7*c),s=Math.floor(t/1e3/60/60-7*c*24-24*r),a=Math.floor(t/1e3/60-7*c*24*60-24*r*60-60*s),l=Math.floor(t/1e3-7*c*24*60*60-24*r*60*60-60*s*60-60*a),i=t/1e3<=0;return{milliseconds:Math.floor(t-7*c*24*60*60*1e3-24*r*60*60*1e3-60*s*60*1e3-60*a*1e3-1e3*l),seconds:ccfwooLeadingZero(l),minutes:ccfwooLeadingZero(a),hours:s,days:r,weekdays:c,totalSeconds:t/1e3,isPast:i,ValidDates:n}}function ccfwooLeadingZero(o){if("on"===ccfwooLocal.leading_zero){const e=2;for(o=o.toString();o.length<e;)o="0"+o;return o}return o}document.addEventListener("DOMContentLoaded",(function(o){ccfwooController.setElements(),ccfwooController.triggerEvent("document","ccfwooLoaded",!0),ccfwooCounter(),ccfwooController.startInterval(),ccfwooController.isCounting()&&ccfwooController.classes("add","checkout-countdown-is-counting")})),document.addEventListener("ccfwooFinishedCounting",(function(o){ccfwooController.classes("remove","checkout-countdown-is-counting")}));
  • checkout-countdown-for-woocommerce/trunk/checkout-countdown-for-woocommerce.php

    r3065377 r3115281  
    33 * Plugin Name:       Checkout Countdown for WooCommerce
    44 * Description:       A flexible WooCommerce cart/checkout countdown to help improve cart conversion.
    5  * Version:           3.2.3
     5 * Version:           4.0.0
    66 * Author:            Puri.io
    77 * Author URI:        https://puri.io/
     
    1212 * Requires at least: 5.0
    1313 * WC requires at least: 5.0
    14  * WC tested up to: 8.8
     14 * WC tested up to: 9.0
    1515 */
    1616
     
    9696        $this->constants = array(
    9797            'name' => 'Checkout Countdown for WooCommerce',
    98             'version' => '3.2.3',
     98            'version' => '4.0.0',
    9999            'prefix' => 'ccfwoo',
    100100            'admin_page' => 'checkout-countdown',
     
    140140        }
    141141
     142        if ( ! class_exists( 'woocommerce' ) ) {
     143            return;
     144        }
     145
    142146
    143147        // Require core files.
     
    146150        if ( $enable_countdown === 'on' ) {
    147151            require_once plugin_dir_path( __FILE__ ) . 'functions/functions.php';
     152            require_once plugin_dir_path( __FILE__ ) . 'functions/cart-fragments.php';
    148153            require_once plugin_dir_path( __FILE__ ) . 'functions/enqueue.php';
    149154            require_once plugin_dir_path( __FILE__ ) . 'functions/shortcode.php';
  • checkout-countdown-for-woocommerce/trunk/functions/enqueue.php

    r3065377 r3115281  
    66function ccfwoo_core_enqueue_scripts() {
    77
    8     wp_enqueue_style( 'ccfwoo-style', plugin_dir_url( __FILE__ ) . '../assets/checkout-countdown.min.css', array(), '3.2.3' );
     8    wp_enqueue_style( 'ccfwoo-style', plugin_dir_url( __FILE__ ) . '../assets/checkout-countdown.min.css', array(), '4.0.0' );
    99
    1010    if ( ccfwoo_get_option( 'bar_position', false, 'top' ) === 'top' ) {
    1111        $position = 'position: relative;';
    1212    } else {
    13         $position  = 'position: fixed;';
     13        $position = 'position: fixed;';
    1414        $position .= 'bottom: 0;';
    1515    }
     
    2626    );
    2727
    28      wp_add_inline_style( 'ccfwoo-style', $inline_css );
     28    wp_add_inline_style( 'ccfwoo-style', $inline_css );
    2929
    3030    // Load Javascript and Access settings as variables.
    31     wp_enqueue_script( 'ccfwoo-countdown', plugin_dir_url( __FILE__ ) . '../assets/checkout-countdown.min.js', array(), '3.2.3', true );
     31    wp_enqueue_script( 'ccfwoo-countdown', plugin_dir_url( __FILE__ ) . '../assets/checkout-countdown.min.js', array(), '4.0.0', true );
    3232
    3333    $countdown_text = sprintf(
     
    5050
    5151    $data = array(
    52         'ccfwoo_minutes'              => ccfwoo_get_option( 'countdown_time' ),
    53         'top_banner_font_color'       => ccfwoo_get_option( 'top_banner_font_color' ),
     52        'ccfwoo_minutes' => ccfwoo_get_option( 'countdown_time' ),
     53        'top_banner_font_color' => ccfwoo_get_option( 'top_banner_font_color' ),
    5454        'top_banner_background_color' => ccfwoo_get_option( 'top_banner_background_color' ),
    55         'countdown_text'              => $countdown_text,
    56         'expired_text'                => $expired_text,
    57         'banner_message_text'         => $banner_message_text,
    58         'enable_banner_message'       => ccfwoo_get_option( 'enable_banner_message' ),
    59         'leading_zero'                => ccfwoo_get_option( 'leading_zero', false, false ),
    60         'cart_count'                  => ccfwoo_get_cart_content(), // Check the number of products in cart.
    61         'countdown_locations'         => is_array( ccfwoo_get_option( 'countdown_locations' ) ) ? ccfwoo_get_option( 'countdown_locations' ) : array(),
    62         'loading_html'                => ccfwoo_loading_html(),
    63         'expired_message_seconds'     => apply_filters( 'ccfwoo_expired_message_seconds', 6 ),
     55        'countdown_text' => $countdown_text,
     56        'expired_text' => $expired_text,
     57        'banner_message_text' => $banner_message_text,
     58        'enable_banner_message' => ccfwoo_get_option( 'enable_banner_message' ),
     59        'leading_zero' => ccfwoo_get_option( 'leading_zero', false, false ),
     60        'countdown_locations' => is_array( ccfwoo_get_option( 'countdown_locations' ) ) ? ccfwoo_get_option( 'countdown_locations' ) : array(),
     61        'loading_html' => ccfwoo_loading_html(),
     62        'expired_message_seconds' => apply_filters( 'ccfwoo_expired_message_seconds', 6 ),
     63        'cart_criteria' => ccfwoo_has_cart_criteria(),
    6464    );
    6565
  • checkout-countdown-for-woocommerce/trunk/functions/functions.php

    r3065377 r3115281  
    66
    77/**
     8 * Checks if the cart has specific criteria.
     9 *
     10 * @return bool The result of the check.
     11 */
     12function ccfwoo_has_cart_criteria() {
     13
     14    $cart_has_items = WC()->cart && WC()->cart->is_empty() === false;
     15
     16    return apply_filters( 'ccfwoo_cart_criteria', $cart_has_items );
     17}
     18
     19/**
    820 * Remove all settings on uninstall
    921 */
     
    1426}
    1527register_uninstall_hook( __FILE__, 'ccfwoo_uninstall' );
    16 
    17 /**
    18  * Get the number of products in cart.
    19  */
    20 function ccfwoo_get_cart_content() {
    21 
    22     if ( ! is_object( WC() ) ) {
    23         return 0;
    24     }
    25 
    26     if ( ! is_object( WC()->cart ) ) {
    27         return 0;
    28     }
    29 
    30     if ( empty( WC()->cart->get_cart_contents_count() ) ) {
    31         $content_count = 0;
    32     } else {
    33         $content_count = WC()->cart->get_cart_contents_count();
    34     }
    35 
    36     return $content_count;
    37 }
    3828
    3929/**
     
    5343                <li>Redirect after countdown has finished.</li>
    5444                <li>Restart/loop the countdown.</li>
    55                 <li>Recalucate the cart totals with every loop.</li>
     45                <li>Recalculate the cart totals with every loop.</li>
    5646                <li>Start the timer without reloading the page when adding a product to cart (AJAX).</li>
    5747                <li>and much more!</li>
     
    6454}
    6555
    66  add_filter( 'ccfwoo_above_settings_sidebars', 'ccfwoo_upgrade_to_pro_sidebar', 10 );
    67 
    68 
    69  /**
    70   * Small upgrade notice at the bottom of general settings.
    71   */
     56add_filter( 'ccfwoo_above_settings_sidebars', 'ccfwoo_upgrade_to_pro_sidebar', 10 );
     57
     58
     59/**
     60 * Small upgrade notice at the bottom of general settings.
     61 */
    7262function ccfwoo_upgrade_to_pro_settings_bottom() {
    7363    echo '<div style="display:inline-block;width:100%; float:right; background-color:#ffffff;">';
     
    8676function ccfwoo_settings_preview() {
    8777
    88     $ccfwoo_bg   = ccfwoo_get_option( 'top_banner_background_color' ) ? ccfwoo_get_option( 'top_banner_background_color' ) : '#000000';
     78    $ccfwoo_bg = ccfwoo_get_option( 'top_banner_background_color' ) ? ccfwoo_get_option( 'top_banner_background_color' ) : '#000000';
    8979    $ccfwoo_font = ccfwoo_get_option( 'top_banner_font_color' ) ? ccfwoo_get_option( 'top_banner_font_color' ) : '#ffffff';
    9080
     
    133123function ccfwoo_convert_options_for_banana() {
    134124
    135     $new_options  = get_option( 'ccfwoo_general_section', 'none' );
     125    $new_options = get_option( 'ccfwoo_general_section', 'none' );
    136126    $check_enable = get_option( 'ccfwoo_enable_countdown', 'none' );
    137127
     
    141131    }
    142132
    143      // New settings already exists - return
     133    // New settings already exists - return
    144134    if ( is_array( $new_options ) ) {
    145135
     
    153143            }
    154144            if ( $new_options['display_type'] === 'woo-notice' ) {
    155                 $new_location['cart-notice']     = 'cart-notice';
     145                $new_location['cart-notice'] = 'cart-notice';
    156146                $new_location['checkout-notice'] = 'checkout-notice';
    157147            }
     
    184174    $temp['display_type'] = $display_type;
    185175
    186     $before_text    = ! empty( get_option( 'ccfwoo_before_countdown' ) ) ? get_option( 'ccfwoo_before_countdown' ) : '';
     176    $before_text = ! empty( get_option( 'ccfwoo_before_countdown' ) ) ? get_option( 'ccfwoo_before_countdown' ) : '';
    187177    $inbetween_text = ! empty( get_option( 'ccfwoo_inbetween_countdown' ) ) ? get_option( 'ccfwoo_inbetween_countdown' ) : '';
    188     $after_text     = ! empty( get_option( 'ccfwoo_after_countdown' ) ) ? get_option( 'ccfwoo_after_countdown' ) : '';
     178    $after_text = ! empty( get_option( 'ccfwoo_after_countdown' ) ) ? get_option( 'ccfwoo_after_countdown' ) : '';
    189179
    190180    if ( ! empty( $before_text ) || ! empty( $before_text ) || ! empty( $before_text ) ) {
  • checkout-countdown-for-woocommerce/trunk/functions/shortcode.php

    r2953672 r3115281  
    8080 */
    8181function ccfwoo_loading_html() {
    82     $loading_dots = '<div class="ccfwoo-loading-dots">
    83     <div class="ccfwoo-loading-dots--dot"></div>
    84     <div class="ccfwoo-loading-dots--dot"></div>
    85     <div class="ccfwoo-loading-dots--dot"></div>
     82    $loading_dots = '<div class="checkout-countdown-loading">
     83    <div class="checkout-countdown-loading-dot"></div>
     84    <div class="checkout-countdown-loading-dot"></div>
     85    <div class="checkout-countdown-loading-dot"></div>
    8686    </div>';
    8787
     
    9696
    9797    $loading_dots = ccfwoo_loading_html();
     98    $has_cart_criteria = ccfwoo_has_cart_criteria();
    9899
    99     if ( $type === 'notice' ) {
     100    $classes = array( 'checkout-countdown-wrapper' );
    100101
    101         $notice_html = '<div class="checkout-countdown-wrapper checkout-countdown-notice" id="cc-countdown-wrap">
    102     <div class="checkout-countdown-content" id="cc-countdown-timer">';
    103         $notice_html .= $loading_dots;
    104         $notice_html .= '</div></div>';
    105         // error, notice or success.
    106         return wc_print_notice( $notice_html, 'error' );
     102    if ( ccfwoo_get_option( 'enable_banner_message' ) !== 'on' && ! $has_cart_criteria ) {
     103        $classes[] = 'checkout-countdown-is-hidden';
    107104    }
    108105
    109     $add_classes = '';
    110     $add_id = '';
    111 
    112     if ( $type === 'shortcode' ) {
    113         $add_classes .= 'checkout-countdown-shortcode cc-shortcode cc-countdown ';
    114         $add_id = 'cc-countdown-timer';
     106    switch ( $type ) {
     107        case 'shortcode':
     108            $classes[] = 'checkout-countdown-shortcode';
     109            break;
     110        case 'bar':
     111            $classes[] = 'checkout-countdown-bar';
     112            break;
     113        case 'notice':
     114            $classes[] = 'checkout-countdown-notice';
     115            break;
    115116    }
    116117
    117     if ( $type === 'bar' ) {
    118         $add_classes .= 'checkout-countdown-bar ';
    119     }
    120 
    121     $add_classes .= ccfwoo_get_option( 'enable_banner_message' ) !== 'on' && ccfwoo_get_cart_content() === 0 ? 'ccfwoo-is-hidden' : '';
    122 
    123     $html = '<div class="checkout-countdown-wrapper ' . $add_classes . '" id="' . $add_id . '">';
     118    $html = '<div class="' . implode( ' ', $classes ) . '">';
    124119    $html .= '<div class="checkout-countdown-content">';
    125120    $html .= $loading_dots;
     
    127122    $html .= '</div>';
    128123
     124    /**
     125     * Notices should be printed as WC notices - they won't display the optional welcome message.
     126     */
     127    if ( $type === 'notice' ) {
     128        if ( ! $has_cart_criteria ) {
     129            return '';
     130        }
     131
     132        return wc_print_notice( $html, 'error' );
     133    }
     134
    129135    return $html;
    130136}
  • checkout-countdown-for-woocommerce/trunk/languages/checkout-countdown-for-woocommerce.pot

    r3065377 r3115281  
    99"Language-Team: Puri.io\n"
    1010"Last-Translator: Puri.io\n"
    11 "POT-Creation-Date: 2024-04-05 10:37+0000\n"
     11"POT-Creation-Date: 2024-07-10 06:01+0000\n"
    1212"X-Poedit-Basepath: ..\n"
    1313"X-Poedit-KeywordsList: __;_e;_ex:1,2c;_n:1,2;_n_noop:1,2;_nx:1,2,4c;_nx_noop:1,2,3c;_x:1,2c;esc_attr__;esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c\n"
  • checkout-countdown-for-woocommerce/trunk/readme.txt

    r3065377 r3115281  
    77Donate link: https://www.paypal.me/morganhvidt/
    88Requires at least: 5.0
    9 Tested up to: 6.5
     9Tested up to: 6.6
    1010Requires PHP: 7.4
    1111Stable tag: trunk
     
    139139== Changelog ==
    140140
     141= 4.0.0 =
     142
     143V4 is major update which includes breaking changes to previous css customization.
     144
     145* Update: Change to more reliable cart detection using cart fragments instead of cookies. This allows customizations server side such as triggering the countdown for specific products or categories.
     146* Fixed: a case where banner text would be inserted in the WC notices.
     147* Ready & tested for WordPress 6.6
     148* Ready & tested for WooCommerce 9.0
     149* Breaking Changes: Standardized the CSS classes - read the [https://puri.io/docs/checkout-countdown-for-woocommerce/troubleshoot/migration-guide-v4/](Migration Guide for v4) for more information.
     150
    141151= 3.2.3 =
    142152
Note: See TracChangeset for help on using the changeset viewer.