Home Forums WoodMart support forum Popup cookies

Popup cookies

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #717022

    metuza
    Participant

    Hello,

    I am using the popup module for a popup in cart and checkout where customers have to enter their zip-code before they can access these pages. This because a zip code will automatically calculate shipping cost and make the checkout easier.

    But i have noticed that expiry time for the cookie is set longer than woocommerce set cart sessions so if a user is to shop again the day after then no popup appear.

    I have tried to remove cookie based on if a zip-code is filled in or not using below code, but with no luck, i guess it gets overwritten?

    function remove_popup_cookie() {
        if ( is_cart() || is_checkout() ) {
           if ( isset( $_COOKIE['woodmart_popup-18535_1'] ) && empty( WC()->customer->get_shipping_postcode() ) ) {
             unset( $_COOKIE['woodmart_popup-18535_1'] );
             setcookie( 'woodmart_popup-18535_1', '', time() - 3600, COOKIEPATH, COOKIE_DOMAIN );
           }
        }
    }
    //add_action( 'init', 'remove_popup_cookie' );

    Anyone having an idea for how i can force the popup to show up if no zip-code is registered, OR eventually not use cookie but hide the popup if zip-code is registered?

    Brgds
    Rune

    • This topic was modified 2 months, 1 week ago by metuza.
    #717036

    Artem Temos
    Keymaster
    Xtemos team

    Hello,

    If you want the popup cookie to expire when the WooCommerce session expires (default 2 days), add this filter:

    // Modify cookie expiration for popup-related cookies
    add_filter( 'woodmart_cookie_expires', 'custom_popup_cookie_expires' );
    function custom_popup_cookie_expires( $days ) {
        // Match WooCommerce session expiration (48 hours = 2 days)
        return 2;
    }

    Kind Regards

    #717127

    metuza
    Participant

    Nice 🙂 Thanks a lot ..

    Brgds
    Rune

    #717159

    Artem Temos
    Keymaster
    Xtemos team

    You are always welcome. Feel free to contact us if you have any further questions.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Popup cookies’ is closed to new replies.