Created
February 26, 2024 07:51
-
-
Save ipokkel/e60bbb300e64076c5f4e28e95a838fff to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* Save the user's membership level name and the order date as comma separated values to the user meta. | |
* | |
* 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_pmpro_save_level_and_checkout_date_to_user_meta( $user_id, $morder ) { | |
$user = get_userdata( $user_id ); // user object | |
$level = pmpro_getLevel( $morder->membership_id ); // membership level object | |
// Exammple: Save the user's membership level name and the order date as comma separated values to the user meta§ | |
$membership_level_name = $level->name; | |
$order_date = date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ); | |
$meta_key = 'membership_level_and_order_date'; | |
$meta_value = $membership_level_name . ',' . $order_date; | |
update_user_meta( $user_id, $meta_key, $meta_value ); | |
} | |
add_action( 'pmpro_after_checkout', 'my_pmpro_save_level_and_checkout_date_to_user_meta', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment