Popup when closing tab if any product is in cart

WebTrend

New member
Feb 2, 2021
15
2
3
Hello,

How to make popup in WooCommerce, when client want to close tab. But only then when something is in his cart ?
I mean that type of popup or if is it possible - elementor popup.

1615903350600.png
 
  • Like
Reactions: khalilbnzz

justcamehere

Member
Nov 26, 2020
73
42
18
25
Brasil
I didn't see you tipped Elementor. I'm sorry.
You can use the "Popup builder".

When you finish editing your pop up, the elementor will show some options. There you can config to show " when client want to close tab "
 

frizzel

Well-known member
Trusted Uploader
Jun 13, 2019
485
253
63
Wherever my imagination takes me
@justcamehere But that does always trigger the pop-up on exit intent whether there are items in the cart or not. That's not what OP asked for.

Unfortunately, Elementor has made it much more difficult to manually trigger a pop-up if the conditions are not within their pre-defined triggers and advanced rules. But, a little coding gets you there.

I tried to add my code via the normal procedure of embedding code here, but it seems Babiato doesn't allow that anymore or maybe because the code is a combination of PHP and Javasacript?

I'll try again, first the PHP part:
PHP:
function not_empty_cart_popup_function(){
    global $woocommerce;
    $items = $woocommerce->cart->get_cart();
    if( count($items) > 0 || !empty($items) ) { ?>
        // the JavaScript part comes here
         <?php
    }
    return;
}
add_action( 'wp_footer', 'not_empty_cart_popup_function', 10, 5);

And the JavaScript is this:

JavaScript:
            var mouseX = 0;
            var mouseY = 0;
            var popupCounter = 0;

            document.addEventListener("mousemove", function(e) {
                mouseX = e.clientX;
                mouseY = e.clientY;
            });

            jQuery(document).mouseleave(function () {
                if (mouseY < 50) {
                    if (popupCounter < 1) {
                        elementorFrontend.documentsManager.documents[11964].showModal();
                    }
                    popupCounter ++;
                }
            });

NOTES:
1) In the settings of your pop-up you set it to display on the entire site, but DON'T select any triggers or advanced rules.
2) The number between brackets (documents[11964].showModal)is the ID of your popup.
3) Surround the JavaScript with the usual opening and closing tags. Apparently those tags are not allowed in the code section.
 
Last edited:

frizzel

Well-known member
Trusted Uploader
Jun 13, 2019
485
253
63
Wherever my imagination takes me
Just to clarify, I put the full code here, only omitting the opening and closing tags for javascript but indicating where they should come.

PHP:
function not_empty_cart_popup_function(){
    global $woocommerce;
    $items = $woocommerce->cart->get_cart();
    if( count($items) > 0 || !empty($items) ) { ?>
    // Put the opening tag for javascript here       
            var mouseX = 0;
            var mouseY = 0;
            var popupCounter = 0;

            document.addEventListener("mousemove", function(e) {
                mouseX = e.clientX;
                mouseY = e.clientY;
            });

            jQuery(document).mouseleave(function () {
                if (mouseY < 50) {
                    if (popupCounter < 1) {
                        elementorFrontend.documentsManager.documents[11964].showModal();
                    }
                    popupCounter ++;
                }
            });
    // Put the closing tag for javascript here   
         <?php
    }
    return;
 }
add_action( 'wp_footer', 'not_empty_cart_popup_function', 10, 5);
 

WebTrend

New member
Feb 2, 2021
15
2
3
I didn't have time to check that, have so much other work. But I will chceck that in few days.
 

frizzel

Well-known member
Trusted Uploader
Jun 13, 2019
485
253
63
Wherever my imagination takes me
Can you share the code as a file?
So, you're too lazy to take the code I shared above and turn it into what is in the screenshot?

I generally don't like people demanding everything readily presented on a plate without any effort whatsoever themselves. To me it's in the same league as people asking questions for which the answer is easily found via Google.

To answer your question:
NO
 
  • Haha
Reactions: Saint Gabriel

Saint Gabriel

Well-known member
Jan 3, 2020
2,998
3,049
113
So, you're too lazy to take the code I shared above and turn it into what is in the screenshot?

I generally don't like people demanding everything readily presented on a plate without any effort whatsoever themselves. To me it's in the same league as people asking questions for which the answer is easily found via Google.

To answer your question:
NO
Pull yourself together mate, not interested in the code, I have no requirements for the feature he requested.

Was just thinking it'd be easier for the person who requested it and others that way.

BTW, Thank You.
 

ngepetlo

Member
Nov 26, 2020
36
15
8
So, you're too lazy to take the code I shared above and turn it into what is in the screenshot?

I generally don't like people demanding everything readily presented on a plate without any effort whatsoever themselves. To me it's in the same league as people asking questions for which the answer is easily found via Google.

To answer your question:
NO
then don't share your code or don't help other ppl if you're too lazy to give it, i never saw people help other people on stackoverflow with just showing screenshot of code, even you just copy it from other website : code from here
 

Saint Gabriel

Well-known member
Jan 3, 2020
2,998
3,049
113
then don't share your code or don't help other ppl if you're too lazy to give it, i never saw people help other people on stackoverflow with just showing screenshot of code, even you just copy it from other website : code from here
Oh wow. Just as I thought. Thanks for this output Bro.

Wonder how he'll just share a picture and expect a newbie or person needing help to write it on their own. If they knew how to go about it, they wouldn't ask for help.

That's why I asked him to share as a file and he started wailing and crying on how lazy he his.

facetWP-minion-king.gif
 
  • Angry
Reactions: frizzel

About us

  • Our community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day to make sure our community is one of the best.

Quick Navigation

User Menu