Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save greathmaster/ec938005b5e616470e77 to your computer and use it in GitHub Desktop.
Save greathmaster/ec938005b5e616470e77 to your computer and use it in GitHub Desktop.
Update Category Membership Level Restrictions for Foreign Languages In PMPro
/**
*
* @param int $save_id
* Updates equivalent membership category in other languages when saving levels.
* Not suitable for large number of languages.
*/
function update_level_categories_for_all_languages($save_id)
{
$level_cat_ids = pmpro_getMembershipCategories($save_id);
$updated_level_cat_ids = $level_cat_ids;
$all_languages = icl_get_languages();
foreach($level_cat_ids as $key => $cc)
{
foreach ($all_languages as $lang => $row)
{
$term_id = icl_object_id($cc, 'category',false, $lang);
if($term_id && !in_array($term_id, $updated_level_cat_ids))
{
$updated_level_cat_ids[] = $term_id;
}
}
}
pmpro_updateMembershipCategories( $save_id, $updated_level_cat_ids );
}
add_action("pmpro_save_membership_level", "update_level_categories_for_all_languages", 10);
@jublack2000
Copy link

Hi there, does this code get inserted to the functions.php file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment