Skip to content

Instantly share code, notes, and snippets.

@ideadude
Created September 30, 2022 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ideadude/534a6d3f8de389a6c08b1a412ecaa05d to your computer and use it in GitHub Desktop.
Save ideadude/534a6d3f8de389a6c08b1a412ecaa05d to your computer and use it in GitHub Desktop.
Some example code of how to create a PMPro membership level.
<?php
/**
* Some example code of how to create a PMPro membership level.
* Uses the PMPro_Membership_Level class and save() method.
*/
// Copy a level.
$level = new PMPro_Membership_Level( 1 ); // Pass the ID of the level to copy.
$level->id = $level->ID = null; // Clear out the ID, triggers insert on save.
$level->name = 'NewName'; // Update any property you want.
$level->save(); // Save.
$level_id = $level->id; // The id AND ID properties are updated on save.
// Create a level from scratch.
$level = new PMPro_Membership_Level();
$level->name = 'Fan';
$level->initial_payment = '10.00';
$level->description = 'New description.';
$level->recurring = 'yes';
$level->billing_amount = '10.00';
$level->cycle_number = 1;
$level->cycle_period = 'Month';
$level->save();
$level_id = $level->id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment