I'm trying to have a popup appear when a customer suspends their account (WooCommerce subscriptions)

193 Views Asked by At

The the only action I got to somewhat work was this one, but this shows the popup when the "suspend/hold" button is on the page, not when it's pressed. I want the popup to appear when it's pressed, I've tried the ones mentioned in the documentation, like 'woocommerce_subscription_status_on-hold' and a ton of others, I don't know if I'm using the wrong action or something else in my code is wrong. Here is the snippet, thank you so much for your time.

    add_action('wcs_can_user_put_subscription_on_hold','suspend_survey_popup');

    function suspend_survey_popup () {
    echo '<html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>My typeform</title> <style>*{margin:0;padding:0;} html,body,#wrapper{width:100%;height:100%;} iframe{border-radius:0 !important;}</style> </head> <body> <div id="wrapper" data-tf-widget="D4JE8Xxp" data-tf-inline-on-mobile data-tf-medium="snippet" ></div> <script src="//embed.typeform.com/next/embed.js"></script> </body> </html>';
    }
1

There are 1 best solutions below

0
On

Bind a jQuery click event to the suspend button click event.

add_action('woocommerce_after_my_account', 'myaccount_on_suspend_subsciption');
add_action('woocommerce_subscription_details_after_subscription_table', 'myaccount_on_suspend_subsciption');

function myaccount_on_suspend_subsciption() {
            ?>
    <script>
        jQuery(document).ready(function($) {
            $("td.subscription-actions a.suspend, table.shop_table.subscription_details a.suspend").on("click", function(e) {
                var confirmCancel = confirm("Are you sure you want to suspend this subscription?");
                if (!confirmCancel) {
                    e.preventDefault()
                }
            })
        })
    </script>
    <?php

}