Forked from andrewlimaza/pmpro-payment-plan-select-plan-query-param.php
Last active
June 28, 2024 13:49
-
-
Save JarrydLong/ad3f2fd3d1c1cc41a1c7c533a1df3d8a to your computer and use it in GitHub Desktop.
Select Paid Memberships Pro Payment Plan via query parameter
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 | |
/** | |
* Add &pmpropp_chosen_plan=<<plan_id>> in the URL to preselect the payment plan option. | |
* Add this code to your site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmpro_payment_plan_select_url() { | |
// Only load this on the checkout page. | |
if ( function_exists('pmpro_is_checkout') && !pmpro_is_checkout() ) { | |
return; | |
} | |
?> | |
<script> | |
jQuery( document ).ready(function() { | |
const urlParams = new URLSearchParams(window.location.search); | |
const payment_plan_query = urlParams.get('pmpropp_chosen_plan'); | |
const payment_plan_level = urlParams.get('pmpro_level'); | |
jQuery( "#pmpropp_chosen_plan_choice_L-"+payment_plan_level+"-P-"+payment_plan_query ).click(); | |
}); | |
</script> | |
<?php | |
} | |
add_action( 'wp_footer', 'my_pmpro_payment_plan_select_url' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment