Skip to content

Instantly share code, notes, and snippets.

@vovafeldman
Last active June 8, 2023 15:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vovafeldman/2bc86bed60f488e0e1f1b3d5f790f7e7 to your computer and use it in GitHub Desktop.
Save vovafeldman/2bc86bed60f488e0e1f1b3d5f790f7e7 to your computer and use it in GitHub Desktop.
Freemius Buy Button Code for a Multi-Plans Table
<script src="https://checkout.freemius.com/checkout.min.js"></script>
<select id="starter-licenses">
<option value="1" selected="selected">Single Site License</option>
<option value="5">5-Site License</option>
<option value="25">25-Site License</option>
<option value="unlimited">Unlimited Sites License</option>
</select>
<button id="starter-purchase">Buy Starter</button>
<select id="pro-licenses">
<option value="1" selected="selected">Single Site License</option>
<option value="5">5-Site License</option>
<option value="25">25-Site License</option>
<option value="unlimited">Unlimited Sites License</option>
</select>
<button id="pro-purchase">Buy Professional</button>
<select id="bus-licenses">
<option value="1" selected="selected">Single Site License</option>
<option value="5">5-Site License</option>
<option value="25">25-Site License</option>
<option value="unlimited">Unlimited Sites License</option>
</select>
<button id="bus-purchase">Buy Professional</button>
<script type="text/javascript">
(function(){
var freemiusHandler = FS.Checkout.configure({
name : '<pluginTitle>',
plugin_id: '<pluginID>',
public_key: '<publicKey>'
});
var plans = {
starter: '<starterPlanID>',
pro: '<proPlanID>',
bus: '<busPlanID>'
};
var addBuyHandler = function (plan, planID){
$('#' + plan + '-purchase').on('click', function (e) {
freemiusHandler.open({
plan_id : planID,
licenses: $('#' + plan + '-licenses').val(),
// You can consume the response for after purchase logic.
success : function (response) {
// alert(response.user.email);
}
});
e.preventDefault();
});
};
for (var plan in plans) {
if (!plans.hasOwnProperty(plan))
continue;
addBuyHandler(plan, plans[plan]);
}
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment