Created
November 1, 2022 09:59
-
-
Save verygoodplugins/fa96e8e61e7e5185b2ed8a76230995c8 to your computer and use it in GitHub Desktop.
Modifies the Easy Digital Downloads cancellation link to point to a custom "Confirm cancellation" page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Modify the EDD cancel URL to point custom cancellation page. | |
* | |
* @param string $url The cancel URL. | |
* @param EDD_Subscription $subscription The subscription. | |
*/ | |
function wpf_edd_subscription_cancel_url( $url, $subscription ) { | |
if ( is_admin() ) { | |
return $url; | |
} | |
$args = array( | |
'sub_id' => $subscription->id, | |
); | |
return add_query_arg( $args, get_site_url( null, '/account/cancel-subscription/' ) ); | |
} | |
add_filter( 'edd_subscription_cancel_url', 'wpf_edd_subscription_cancel_url', 10, 2 ); | |
/** | |
* Cancel subscription shortcode. Put this on the custom cancellation page. | |
*/ | |
function wpf_cancel_subscription_link() { | |
$args = array( | |
'edd_action' => 'cancel_subscription', | |
'sub_id' => absint( $_GET['sub_id'] ), | |
); | |
$url = wp_nonce_url( add_query_arg( $args, get_site_url( null, '/account/' ) ), 'edd-recurring-cancel' ); | |
return '<a href="' . esc_url_raw( $url ) . '">No thanks, cancel my subscription anyway »</a>'; | |
} | |
add_shortcode( 'wpf_cancel_subscription_link', 'wpf_cancel_subscription_link' ); | |
/** | |
* Shortcode for EDD subscription cancelled confirmation. | |
*/ | |
function wpf_edd_messages() { | |
if ( isset( $_GET['edd-message'] ) && 'cancelled' === $_GET['edd-message'] ) { | |
$content = '<div class="elementor-element elementor-element-5d6fa8b elementor-widget elementor-widget-alert" data-id="5d6fa8b" data-element_type="widget" data-widget_type="alert.default"><div class="elementor-widget-container"><div class="elementor-alert elementor-alert-success" role="alert"> <span class="elementor-alert-title">'; | |
$content .= 'Your subscription was successfully cancelled.'; | |
$content .= '</span></div></div></div>'; | |
} | |
} | |
add_shortcode( 'wpf_edd_messages', 'wpf_edd_messages' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment