Forked from ipokkel/change-text-for-addon-package-checkout.php
Created
April 4, 2025 08:14
-
-
Save dwanjuki/e90d17dc53097be8ded46407ba1ae531 to your computer and use it in GitHub Desktop.
Change the text for the addon package checkout page to only show the post title and exclude the level name.
This file contains hidden or 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 | |
/** | |
* Change the text for the addon package checkout page. | |
* | |
* 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/ | |
*/ | |
// Swap the pmproap_pmpro_checkout_level filter with our custom one. | |
function init_swap_pmproap_pmpro_checkout_level() { | |
if ( ! function_exists( 'pmproap_pmpro_checkout_level' ) || ! function_exists( 'my_pmproap_pmpro_checkout_level' ) ) { | |
return; | |
} else { | |
remove_filter( 'pmpro_checkout_level', 'pmproap_pmpro_checkout_level' ); | |
add_filter( 'pmpro_checkout_level', 'my_pmproap_pmpro_checkout_level' ); | |
} | |
} | |
add_action( 'init', 'init_swap_pmproap_pmpro_checkout_level' ); | |
// Tweak the checkout page when ap is passed in. | |
function my_pmproap_pmpro_checkout_level( $level ) { | |
global $current_user; | |
if ( ! function_exists( 'pmproap_pmpro_checkout_level' ) || ! function_exists( 'my_pmproap_pmpro_checkout_level' ) ) { | |
return $level; | |
} | |
if ( ! isset( $level->id ) ) { | |
return $level; | |
} | |
// are we purchasing a post? | |
if ( isset( $_REQUEST['ap'] ) && ! empty( $_REQUEST['ap'] ) ) { | |
$ap = intval( $_REQUEST['ap'] ); | |
$ap_post = get_post( $ap ); | |
$pmproap_price = get_post_meta( $ap, '_pmproap_price', true ); | |
if ( ! empty( $pmproap_price ) ) { | |
if ( pmpro_hasMembershipLevel( $level->id ) ) { | |
// already have the membership, so price is just the ap price | |
$level->initial_payment = $pmproap_price; | |
// zero the rest out | |
$level->billing_amount = 0; | |
$level->cycle_number = 0; | |
$level->trial_amount = 0; | |
$level->trial_limit = 0; | |
// unset expiration period and number | |
$level->expiration_period = null; | |
$level->expiration_number = null; | |
} else { | |
// add the ap price to the membership | |
$level->initial_payment = $level->initial_payment + $pmproap_price; | |
} | |
// update the name | |
$level->name = $ap_post->post_title; | |
} else { | |
// woah, they passed a post id that isn't locked down | |
} | |
} | |
return $level; | |
} | |
add_filter( 'pmpro_checkout_level', 'my_pmproap_pmpro_checkout_level' ); | |
// Change the text for the addon package checkout page. | |
function my_pmpro_change_text_for_addon_package_checkout( $translated_text, $text, $domain ) { | |
if ( ! function_exists( 'pmproap_pmpro_checkout_level' ) || ! function_exists( 'my_pmproap_pmpro_checkout_level' ) ) { | |
return $translated_text; | |
} | |
if ( ! empty( $_REQUEST['ap'] ) || ( ! empty( $_REQUEST['level'] ) || ! empty( $_REQUEST['pmpro_level'] ) ) ) { | |
if ( 'paid-memberships-pro' === $domain && 'You have selected the %s membership level.' === $text ) { | |
$translated_text = __( 'You have selected to purchase access to the post: %s', 'paid-memberships-pro' ); | |
} | |
} | |
return $translated_text; | |
} | |
add_filter( 'gettext', 'my_pmpro_change_text_for_addon_package_checkout', 20, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment