Skip to content

Instantly share code, notes, and snippets.

@wpt00ls
Last active March 16, 2023 03:59
Show Gist options
  • Save wpt00ls/db7047162c12a72fb47028c37a486a38 to your computer and use it in GitHub Desktop.
Save wpt00ls/db7047162c12a72fb47028c37a486a38 to your computer and use it in GitHub Desktop.
WordPress hooks for "Freemius Toolkit" plugin
<?php
/**
* Text at the start of the pricing table.
* Mainly used for multi-plan pricing tables
*/
add_filter(
'pricing_table_features_start',
function (
// generated list item content
$response,
// plan = array containing plan information
$plan,
// array containing features
$features,
// group type = the grouping of pricing table. 'duration', 'license', 'plan'
$group_type,
// group name = example 'lifetime', 'monthly', '1', 'unlimited'
$group_name
) {
if (($group_type == 'plan') &&
($group_name == 'platinum') &&
($plan['id'] == 8357)) {
// for multi plan pricing table
$response = sprintf('<li><strong>%s</strong></li>', 'All features from Gold');
}
return $response;
},
10,
5
);
/**
* Filter for html output generated for each feature item
*/
add_filter(
'pricing_table_feature_item',
function (
// generated list item content
$response,
// array containing feature information
$feature,
// plan = array containing plan information
$plan,
// group type = the grouping of pricing table. 'duration' or 'license'
$group_type,
// group name = example 'lifetime', 'monthly', '1', 'unlimited'
$group_name
) {
$response = sprintf(
'<li>%s%s%s</li>',
$feature['value'] ? '<strong>' . $feature['value'] . '</strong> ' : '',
$feature['title'],
$feature['description'] ? '<span class="tooltip-box">?<span class="tooltip-text">' . $feature['description'] . '</span></span>' : ''
);
return $response;
},
10,
5
);
/**
* Hook to add html after the pricing information for each pricing table column
*/
add_filter(
'single_plan_pricing_table_after_price',
function (
// the generated html
$response,
// plan = array containing plan information
$plan,
// group type = the grouping of pricing table. 'duration' or 'license'
$group_type,
// group name = example 'lifetime', 'monthly', '1', 'unlimited'
$group_name
) {
if ($plan['id'] == 8356) {
$description = '';
if ($group_type == 'duration') {
switch ($group_name) {
case 'lifetime':
$description = 'Lifetime plan is great for large agencies';
break;
case 'annual':
$description = 'Annual plan is great for small agencies';
break;
case 'monthly':
$description = 'Monthly plan is great for pay as-you-go!';
break;
default:
// code...
break;
}
}
if ($group_type == 'license') {
switch ($group_name) {
case 'unlimited':
$description = 'Unlimited-site license is great for large agencies';
break;
case '5':
$description = '5-site license is great for small agencies';
break;
case '1':
$description = '1-site license is for single website owners';
break;
default:
// code...
break;
}
}
return sprintf('<p class="plan-description">%s</p>', $description);
}
return $response;
},
10,
4
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment