Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kimwhite/44b08335dd655fe772b26dd20386426e to your computer and use it in GitHub Desktop.
Save kimwhite/44b08335dd655fe772b26dd20386426e to your computer and use it in GitHub Desktop.
This recipe changes the level selection text and hides the level cost text if level is a donations only level. $pmpro-donations
<?php
/**
* This recipe changes the level selection text and hides the
* level cost text if level is a donations only level.
* KIM - uplated to include changing the wording of "Membership Level" on the checkout page. line 56
* EDIT line 31 with the ID's of your donation only level(s).
*
* This recipe assumes PMPro Donations is set up and configured.
* @link https://www.paidmembershipspro.com/add-ons/donations-add-on/
*
* 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_pmprodon_change_text_for_discount_only_level() {
// Bail if necessary
if ( ! function_exists( 'pmprodon_is_donations_only' ) ) {
return false;
}
global $pmpro_level, $pmpro_pages;
//if ( pmpro_is_checkout() || is_page( $pmpro_pages['checkout'] ) /* || is_page( $pmpro_pages['confirmation'] ) */ ) {
// Change text if a donations only level
//if ( pmprodon_is_donations_only( $pmpro_level->id ) ) {
// Change your membership level ID here.
if ( is_page( $pmpro_pages['checkout'] ) && isset( $_REQUEST['level'] ) && ($_REQUEST['level'] == '6' || $_REQUEST['level'] == '9' )) {
add_filter( 'gettext', 'gettext_translate_donations', 10, 3 );
add_filter( 'pmpro_level_cost_text', 'free_level_change_pmpro_level_cost_text', 10, 2 );
}
}
add_action( 'pmpro_checkout_preheader', 'my_pmprodon_change_text_for_discount_only_level' );
/**
* Change the level text
*/
function gettext_translate_donations( $translated, $text, $domain ) {
switch ( $domain ) {
case 'paid-memberships-pro':
switch ( $text ) {
case 'Membership Level':
$translated = 'Donation Level';
break;
case 'You have selected the <strong>%s</strong> membership level.':
// Your custom text string or translation here.
$translated = 'Thank you for choosing to donate to the <strong>%s</strong>';
break;
}
break;
}
return $translated;
}
/**
* Remove or change the level cost for free levels.
*/
function free_level_change_pmpro_level_cost_text( $text, $level ) {
if ( pmpro_isLevelFree( $level ) ) {
return ''; // leave blank or enter custom level cost text here.
} else {
return $text;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment