WooCommerce Subscriptions: Confirmation for Cancellation with Feedback via. Contact Form

Date: 
18. May 2022
Author: 
mbs
Category: 

Is this JavaScript confirmation not good enough for you?

Well. Here is another way of doing it, with a nice feedback function from a Contact Form.

The customer can't cancel the subscription, without they finish submit feedback.

You will need Popup maker plugin for this. Or you can make popup function you own.

Add this code snippet to your favorite code operator, and change 'popup1 popmake-2133' according to your settings

// add_shortcode("cancel_subscription_wpform","handsomebeardedguy_after_my_account2");

function handsomebeardedguy_after_my_account() {

echo '<script> 

	jQuery(document).ready(function($) {
				$("td.subscription-actions a.cancel, table.shop_table.subscription_details a.cancel").after(\'<button class="popup1 popmake-2133" style="display:none">popup</button>\');
		  $(\'form.wpforms-form\').on(\'wpformsAjaxSubmitSuccess\', (event) => {
window.location.replace($(".popup1").prev().attr("href"));

  })
		
	$("td.subscription-actions a.cancel, table.shop_table.subscription_details a.cancel").on("click", function(e) { 
	
    e.preventDefault();
	$(".popup1").click();
})
})
</script>';

}

function andsomebeardedguy_after_my_account_suspend() {
echo '<script> 

	jQuery(document).ready(function($) {
				$("td.subscription-actions a.suspend, table.shop_table.subscription_details a.suspend").after(\'<button class="popup2 popmake-2133" style="display:none">popup</button>\');
		  $(\'form.wpforms-form\').on(\'wpformsAjaxSubmitSuccess\', (event) => {
window.location.replace($(".popup2").prev().attr("href"));

  })
		
	$("td.subscription-actions a.suspend, table.shop_table.subscription_details a.suspend").on("click", function(e) { 
    e.preventDefault();
	$(".popup2").click();
})
})
</script>';
}

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


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

Leave a Reply

Your email address will not be published. Required fields are marked *

© Copyright 2007-2024
mbsTECH.dk

Build with
and 
Oxygenbuilder
I'm using 
Ahoy