The UK subscription rules require a block of key information right above the pay button on every checkout that sells an auto-renewing subscription. MemberPress has no setting for this block. This document gives a code snippet that adds it, and explains how to install and adjust the snippet.
The block is one part of the setup that the guide to MemberPress and the UK subscription contract rules describes. That guide also explains what the rules require.
What the Block Shows
The snippet builds a “Before you subscribe” box for each recurring membership. It takes every value from the membership’s own settings, so the box changes when the membership changes. The box shows:
- that the subscription renews automatically, the price, and how often it’s charged;
- the monthly equivalent, for plans not billed monthly;
- the total number of payments, for plans with a fixed number of payments;
- for trials, the trial length and price, and the date and amount of the first full charge;
- the minimum total, how to cancel, and that there’s no minimum term or notice period;
- when reminders go out;
- any terms for changing the price;
- the cooling-off rights: 14 days after signing up, and 14 days after a trial ends or after each yearly renewal, where those apply;
- the accepted payment methods.
One-time memberships get no box, because they don’t renew.
Where the Block Appears
The snippet places the box on both MemberPress checkouts:
- Registration pages: directly above the button, on the classic, single-page and ReadyLaunch registration forms. The snippet uses the
mepr_checkout_before_submithook; - Cart checkout: on the Payment step, above the Terms of Service checkbox and the Pay button, with one box for each membership in the cart. The snippet uses the
mepr_cart_checkout_payment_fieldshook.
Installing the Snippet
The snippet can run as a WPCode snippet or as a must-use plugin. Install it in one place only.
To add the snippet with the free WPCode plugin, as the guide to adding custom code snippets in WPCode describes:
- Navigate to Dashboard > Code Snippets > Add Snippet.
- Hover over Add Your Custom Code (New Snippet), and click Use Snippet.
- Add a title, for example, “UK Subscription Key Information”.
- In the Code Type dropdown, choose PHP Snippet.
- Paste the snippet below into the Code Preview field. WPCode removes the opening
<?phpline when it saves, so paste the code as it is. - Change the settings at the top of the code, as the next section describes.
- Leave Insert Method on Auto Insert, and set Location to Run Everywhere.
- Switch the snippet from Inactive to Active, and click Save Snippet.
- Open a membership’s registration page, or the cart checkout’s Payment step, and check that the box shows above the button.
To use a must-use plugin instead, save the snippet as a file named uk-subscription-key-info.php in the site’s wp-content/mu-plugins/ folder. Create the folder if it doesn’t exist. WordPress runs must-use plugins without activation.
<?php
/**
* Plugin Name: MemberPress UK Subscription Key Information
* Description: Shows the UK subscription "key pre-contract information" block right above the pay button
* on MemberPress checkouts (classic, single-page, ReadyLaunch and cart). Edit the settings below.
* Version: 1.0.0
*
* Install: save as wp-content/mu-plugins/uk-subscription-key-info.php (or paste into a code-snippets plugin).
* Only recurring memberships get the block; one-time memberships are left alone.
*/
if (!defined('ABSPATH')) {
exit;
}
/**
* Site settings. Change these to match your site and terms.
*/
function uk_key_info_settings()
{
return [
// Where members cancel (usually your MemberPress Account page, Subscriptions tab).
'cancel_url' => MeprOptions::fetch()->account_page_url('action=subscriptions'),
// Page holding your full pre-contract information / terms.
'terms_url' => home_url('/terms/'),
// When reminders go out. Must match the reminders you set up in MemberPress > Reminders.
'reminders_monthly' => '5 to 3 days before each renewal',
'reminders_yearly' => '30 to 28 days and 14 to 12 days before each renewal',
'reminders_trial' => '7 to 5 days before your trial ends',
// Price-change terms. Use '' if you never change prices for existing members.
'price_change' => 'We may change the price with at least 30 days\' notice. You can cancel before the new price applies.',
// Payment methods you accept.
'payment_methods' => 'Visa, Mastercard, American Express and PayPal',
// Optional: only show to buyers in these countries (ISO codes, e.g. ['GB']). Empty = show to everyone.
// Note: the country is only known on the cart checkout's billing step; the classic form always shows it.
'only_countries' => [],
];
}
/**
* Build the block for one membership. Returns '' for one-time memberships.
*
* @param MeprProduct $product The membership.
* @return string HTML.
*/
function uk_key_info_html_for_product($product)
{
if (!($product instanceof MeprProduct) || empty($product->ID) || $product->is_one_time_payment()) {
return '';
}
$s = uk_key_info_settings();
$price = (float) $product->price;
$period = max(1, (int) $product->period);
$period_type = (string) $product->period_type; // weeks | months | years.
$money = function ($amount) {
return MeprAppHelper::format_currency((float) $amount, true, false);
};
// How often, in words.
$every = $period === 1
? rtrim($period_type, 's')
: $period . ' ' . $period_type;
// Monthly equivalent (only required when not billed monthly).
$monthly = null;
if ($period_type === 'weeks') {
$monthly = $price * 52 / 12 / $period;
} elseif ($period_type === 'years') {
$monthly = $price / (12 * $period);
} elseif ($period_type === 'months' && $period > 1) {
$monthly = $price / $period;
}
$has_trial = !empty($product->trial) && (int) $product->trial_days > 0;
$first = $has_trial ? (float) $product->trial_amount : $price;
$is_long = ($period_type === 'years') || ($period_type === 'months' && $period >= 12) || ($period_type === 'weeks' && $period >= 52);
$items = [];
// 1, 4, 5: keeps charging, how much, how often, monthly equivalent.
$line = sprintf(
'This is a subscription. It renews automatically and you\'ll be charged %1$s every %2$s',
esc_html($money($price)),
esc_html($every)
);
if ($monthly !== null) {
$line .= sprintf(' (equal to %s a month)', esc_html($money($monthly)));
}
$line .= ' until you cancel.';
if (!empty($product->limit_cycles) && (int) $product->limit_cycles_num > 0) {
$line .= sprintf(' It stops after %d payments in total.', (int) $product->limit_cycles_num);
}
$items[] = $line;
// 3: trial / intro price.
if ($has_trial) {
$converts = wp_date(get_option('date_format'), strtotime('+' . (int) $product->trial_days . ' days'));
$items[] = sprintf(
'Your first %1$d days %2$s. Unless you cancel before %3$s, you\'ll be charged %4$s on that date.',
(int) $product->trial_days,
$first > 0 ? 'cost ' . esc_html($money($first)) : 'are free',
esc_html($converts),
esc_html($money($price))
);
}
// 2, 6, 8, 9: minimum term, minimum total, how to cancel, notice.
$items[] = sprintf(
'Minimum you\'ll pay: %1$s%3$s. There\'s no minimum term and no notice period. Cancel any time online from <a href="%2$s">your account</a>.',
esc_html($money($first)),
esc_url($s['cancel_url']),
$has_trial ? ' if you cancel during the trial' : ''
);
// 10: reminder timing.
$reminders = $is_long ? $s['reminders_yearly'] : $s['reminders_monthly'];
if ($has_trial) {
$reminders = $s['reminders_trial'] . ', then ' . $reminders;
}
$items[] = 'We\'ll email you a reminder ' . esc_html($reminders) . '.';
// 7: price changes.
if ($s['price_change'] !== '') {
$items[] = esc_html($s['price_change']);
}
// 11: cooling-off summary.
$renewal_window = [];
if ($has_trial) {
$renewal_window[] = 'after your trial ends';
}
if ($is_long) {
$renewal_window[] = 'after each yearly renewal';
}
$cooling = 'You can cancel within 14 days of signing up';
if ($renewal_window) {
$cooling .= ', and within 14 days ' . implode(' and ', $renewal_window);
}
$cooling .= sprintf(
', and pay only for what you\'ve used. Full details are in our <a href="%s">terms</a>.',
esc_url($s['terms_url'])
);
$items[] = $cooling;
// Payment methods (required to be visible on the page).
$items[] = 'We accept ' . esc_html($s['payment_methods']) . '.';
$html = '<div class="uk-key-info" style="border:2px solid currentColor;border-radius:6px;padding:12px 16px;margin:16px 0;">';
$html .= '<strong>' . esc_html(sprintf('Before you subscribe to %s', get_the_title($product->ID))) . '</strong>';
$html .= '<ul style="margin:8px 0 0 18px;padding:0;">';
foreach ($items as $item) {
$html .= '<li>' . wp_kses_post($item) . '</li>';
}
$html .= '</ul></div>';
return $html;
}
/**
* Is the buyer in a country we show the block to?
*
* @param string $country ISO country code, '' if unknown.
* @return boolean
*/
function uk_key_info_country_ok($country)
{
$only = uk_key_info_settings()['only_countries'];
if (empty($only) || $country === '') {
return true; // Unknown country: show it, to be safe.
}
return in_array(strtoupper($country), $only, true);
}
// Classic, single-page and ReadyLaunch registration forms: right above the submit button.
add_action('mepr_checkout_before_submit', function ($product_id) {
if (!uk_key_info_country_ok('')) {
return;
}
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped while building.
echo uk_key_info_html_for_product(new MeprProduct((int) $product_id));
});
// Cart checkout (payment step): just above the Terms checkbox and the Pay button.
add_action('mepr_cart_checkout_payment_fields', function ($step_data) {
if (!class_exists('MeprCartSessionService')) {
return;
}
$session = MeprCartSessionService::current_session();
if (!$session) {
return;
}
$country = '';
if (class_exists('MeprCartCheckoutService')) {
$data = MeprCartCheckoutService::get_checkout_data($session);
$country = isset($data['billing']['country']) ? (string) $data['billing']['country'] : '';
}
if (!uk_key_info_country_ok($country)) {
return;
}
foreach (array_keys(MeprCartSessionService::get_items($session)) as $product_id) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped while building.
echo uk_key_info_html_for_product(new MeprProduct((int) $product_id));
}
});
Adjusting the Settings
The settings sit at the top of the snippet, in the uk_key_info_settings() function. Find each setting by its name. Change only the value after its =>, and keep the quotes and the comma at the end of the line.
| Setting | What it controls | How to change it |
|---|---|---|
cancel_url | The “your account” link in the box | Leave it as it is. It opens the Account page’s Subscriptions tab, where members cancel without giving a reason. |
terms_url | The “terms” link in the cooling-off line | Replace /terms/ with the path of the page that holds the full pre-contract information, for example, home_url('/subscription-terms/'). |
reminders_monthly | The reminder timing shown for plans billed more often than yearly | Enter the window the site’s reminders promise, for example, '5 to 3 days before each renewal'. |
reminders_yearly | The reminder timing shown for plans billed every 12 months or more | Enter both windows, for example, '30 to 28 days and 14 to 12 days before each renewal'. |
reminders_trial | The reminder timing shown before a trial ends | Enter the trial reminder’s window, for example, '7 to 5 days before your trial ends'. |
price_change | The price-change terms | Enter the site’s terms, or '' if prices never change for existing members. Keep the backslash before an apostrophe, as in days\' notice. |
payment_methods | The accepted payment methods | List the methods the checkout accepts, for example, 'Visa, Mastercard and PayPal'. |
only_countries | Which buyers see the box | Leave [] to show the box to everyone. Enter ['GB'] to show it to UK buyers only. Registration pages always show the box, because the buyer’s country isn’t known there. |
The box also states “There’s no minimum term and no notice period.” That sentence is fixed text in the snippet, not a setting. Search the snippet for it. If a membership has a minimum term, or members must give notice to cancel, change the sentence to state the term or the notice.
Matching the Reminder Wording
The box must promise the same reminder timing that the site’s reminders deliver. The snippet uses reminders_yearly for plans billed every 12 months or more, and reminders_monthly for every shorter plan, including 6- to 11-month plans.
The main guide recommends a reminder 14 days before each renewal for 6- to 11-month plans, while the default monthly wording promises “5 to 3 days before each renewal”. One wording can’t describe both timings. Build the reminders for 6- to 11-month plans with the same timing as the monthly ones, or change reminders_monthly so it’s true for both. The guide to creating a reminder covers the reminder settings.
Limits
- it shows the regular price, and ignores any coupon the buyer applies;
- it shows the price as entered on the membership, so if prices are entered without tax, the box doesn’t add tax;
- the cart checkout’s button reads “Pay” with the order total, and the snippet can’t change that wording;
- 6- to 11-month plans get the monthly reminder wording, as the previous section describes.
Summary
With the snippet installed and its settings adjusted, every recurring membership shows its key information right above the pay button. The box appears on registration pages and on the cart checkout’s Payment step. The guide to MemberPress and the UK subscription contract rules covers the rest of the setup.