Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dparker1005/f048542f620038d91bc96f9baa4d9cc5 to your computer and use it in GitHub Desktop.
Save dparker1005/f048542f620038d91bc96f9baa4d9cc5 to your computer and use it in GitHub Desktop.
Add username to PayPal order description. Equivalent for Authorize.net also included, but commented out.
<?php
// Copy from below here...
/**
* Add username to PayPal order description.
* Equivalent for Authorize.net also included, but commented out.
*/
function my_pmpro_custom_level_description_add_username( $description, $level_name, $order, $site_name ) {
//Initialize $username
$username = '';
// Get username for current user
if ( array_key_exists( 'username', $_REQUEST ) ) {
// First checkout.
$username = $_REQUEST['username'];
} elseif ( array_key_exists( 'pmpro_signup_username', $_SESSION ) ) {
// Returning from PayPal during thier first checkout.
$username = $_SESSION['pmpro_signup_username'];
} else {
// Existing user.
$user = wp_get_current_user();
if ( ! empty( $user ) && isset( $user->user_login ) ) {
$username = $user->user_login;
}
}
// Check that we've found a username
if ( empty( $username ) ) {
// We should never get here.
echo "Couldn't get a username.";
wp_die();
}
// Format description.
$description = $username . ': ' . $description;
return substr( $description, 0, 127);
}
add_filter( 'pmpro_paypal_level_description', 'my_pmpro_custom_level_description_add_username', 10, 4 );
// add_filter( 'pmpro_authorizenet_level_description', 'my_pmpro_custom_level_description_add_username', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment