Skip to content

Instantly share code, notes, and snippets.

@ipokkel
Last active August 1, 2022 07:34
Show Gist options
  • Save ipokkel/9aa3b052a517a4a97d6f1fdebb88d41d to your computer and use it in GitHub Desktop.
Save ipokkel/9aa3b052a517a4a97d6f1fdebb88d41d to your computer and use it in GitHub Desktop.
PMPro - Change Text Example on Checkout Page by LEVEL
<?php // Do Not Copy This Line
/**
* This recipe will help you change text on the checkout paid by level
* 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/
*/
// paste content from below this line
function pmproc_change_my_text( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'Membership Checkout':
$translated_text = __( 'Application', 'pmpro' );
break;
case 'Membership Level':
$translated_text = __( 'Application', 'pmpro' );
break;
case 'Do you have a discount code?':
$translated_text = __( 'Do you have a membership code?', 'pmpro' );
break;
case 'Click here to enter your discount code':
$translated_text = __( 'Click here to enter your membership code', 'pmpro' );
break;
case 'You have selected the <strong>%s</strong> membership level.':
$translated_text = __( '<strong>%s</strong> has been selected.', 'pmpro' );
break;
case 'The price for membership is <strong>%s</strong> now':
$translated_text = __( ' you can leave this blank ', 'pmpro' );
break;
}
return $translated_text;
}
function do_gettext_for_pmpro_checkout() {
global $pmpro_level;
if ( '1' === $pmpro_level->id ) {
add_filter( 'gettext', 'pmproc_change_my_text', 20, 3 );
}
}
add_action( 'pmpro_checkout_preheader', 'do_gettext_for_pmpro_checkout' );
/**
* This function will change the Page Title on the Checkout page for 1 level
*/
function my_checkout_page_title( $page_title, $page_id ) {
/* Settings - set your level ID and page title here */
$level_id = '1';
$level_page_title = 'Application';
/* END */
global $pmpro_pages, $pmpro_level;
// Let's check if we are on the checkout page and what level the checkout is for
if ( $page_id == $pmpro_pages['checkout'] && ( ( isset( $_REQUEST['level'] ) && $_REQUEST['level'] == $level_id ) || $level_id === $pmpro_level->id ) ) {
// Let's change the page title
$page_title = $level_page_title;
}
return $page_title;
}
add_filter( 'the_title', 'my_checkout_page_title', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment