Skip to content

Instantly share code, notes, and snippets.

@ipokkel
Created February 13, 2023 04:10
Show Gist options
  • Save ipokkel/3ceffae7e7788302563db15914db99ef to your computer and use it in GitHub Desktop.
Save ipokkel/3ceffae7e7788302563db15914db99ef to your computer and use it in GitHub Desktop.
Redirect membr back to Addon Package purchased after checkout.
<?php
/**
* Redirect member back to Addon Packages page after checkout.
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_addon_package_confirmation_url( $url, $user_id, $level ) {
// Let's only do this if Addon Packages is active and a package id is passed.
if ( function_exists( 'pmproap_hasAccess' ) && isset( $_REQUEST['ap'] ) && ! empty( $_REQUEST['ap'] ) ) {
$ap = get_post( $_REQUEST['ap'] );
if ( $ap ) {
$url = get_permalink( $ap->ID );
}
}
return $url;
}
add_filter( 'pmpro_confirmation_url', 'my_pmpro_addon_package_confirmation_url', 10, 3 );
@ipokkel
Copy link
Author

ipokkel commented Nov 25, 2024

This recipe works for on-site payment gateways and additional code may be required if you are using off-site payment gateways, e.g. Stripe Checkout, PayFast, Paystack, or CCBill.

If you are using an off-site gateway please also add the following recipe
https://gist.github.com/andrewlimaza/eddc8ba56dd89aee6b32dd85391271d8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment