Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ipokkel/c42c5a8a092e18556e64bb59976d5b8b to your computer and use it in GitHub Desktop.
Save ipokkel/c42c5a8a092e18556e64bb59976d5b8b to your computer and use it in GitHub Desktop.
Removes payment plans from a membership level checkout if a discount code is applied.
<?php
/**
* This recipe removes payment plans from the PMPro checkout page if a
* discount code is applied.
*
* 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 remove_payment_plans_when_discount_code_applied( $discount_code, $discount_code_id, $level_id, $code_level ) {
// Is payment plans active?
if ( ! function_exists( 'pmpropp_get_plan' ) ) {
return;
}
// If a valid discount code is applied, remove payment plans.
if ( ! empty( $code_level ) ) {
echo 'jQuery("#pmpropp_select_payment_plan").remove();';
}
}
add_action( 'pmpro_applydiscountcode_return_js', 'remove_payment_plans_when_discount_code_applied', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment