• Resolved Chris Gagner

    (@chrisgagner)


    When someone clicks on the X in the top right corner, it will make the popup disappear. However, on the next page load, it appears again unless the user check the don’t show box.

    I noticed when previewing some of the YITH themes that the popup will appear only once during a browser session, and not on each pageload. How can this be accomplished?

    http://wordpress.org/plugins/yith-newsletter-popup/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Chris Gagner

    (@chrisgagner)

    I made 2 tweaks to the code to accomplish what I needed. It might not be the cleanest solution, but it works for now.

    In class.yith-newsletter-popup-frontend.php, I added the following bold code:

    /**
    * Constructor
    *
    * @return YITH_Newsletter_Popup_Frontend
    * @since 1.0.0
    */
    public function __construct( $version ) {
    $this->version = $version;
    global $yith_newsletter_popup_base;
    $yith_newsletter_popup_base = “yith-newsletter-popup-” . basename( get_template_directory() ) . “-hide-popup-” . get_option(‘yith_newsletter_popup_cookie_var’);
    if (
    ( ! yith_newsletter_popup_is_enabled())
    ||(isset($_COOKIE[$yith_newsletter_popup_base]))
    ||(isset($_COOKIE[‘visited’]))
    // ||(wp_is_mobile())
    ) return $this;
    add_action( ‘wp_enqueue_scripts’, array( $this, ‘newsletter_popup_in_place_inserter_master’), 99 );
    add_action(‘wp_head’, array( $this, ‘newsletter_popup_style_to_the_head’));
    add_action(‘init’, array( $this, ‘add_google_fonts’));
    add_action(‘wp_footer’, array( $this, ‘newsletter_popup_in_place_inserter’), 999);
    return $this;
    }

    This checks to see if a cookie named “visited” exists. If it does, then it hides the popup.

    In yith-newsletter-popup.php, I added the bold code:

    <?php
    /**
    * Newsletter Popup page
    *
    * @author Your Inspiration Themes
    * @package YITH Newsletter Popup
    * @version 1.0.0
    */
    ;?>
    <!– yith-newsletter-popup –>
    <?php
    setcookie(‘visited’, true, time() + 3600 * 2); // Save a cookie for 2 hours
    $yith_use_woocommerce = yit_is_woocommerce_active()
    && get_option(‘yith_newsletter_popup_woocommerce_integration’) == ‘1’
    && get_option(‘yith_newsletter_popup_woocommerce_product_id’);

    if ( $yith_use_woocommerce ){

    When the popup displays, it will set a cookie named visited. In this case I set it to 2 hours, but you can change it to whatever you need.

    Now the popup will only display once every 2 hours, instead of on each pageview.

    If there’s a better way to accomplish this, please let me know.

    Hi Chris, Tried your suggestion but it didn’t work for me. Does this fix still work for you?

    Thanks,

    Mark

    martinavive

    (@martinavive)

    Hi

    I would like to not have the pop up appear on every page also, the above did not work for me either how do i resolve please?

    Interested in the answer to this as well. How do we contact the developer?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Popup on every pageload’ is closed to new replies.