GCBGutenberg
Control Blocks
v1.3.3
Buy

Pricing table

Up to four plans side by side, each with a price, a list of features, a button and a featured switch. Every file shown in full.

A pricing table: a heading, an intro and up to four plans side by side. Each plan is a block of its own, with a name, a price, a period, a list of features, a button and a switch that marks it as the featured plan. It is two block folders: the table and the plan.

Download example A zip of two block folders for your theme. Needs GCB 1.3.1 or later, and nothing else.

The whole block

Create blocks/pricing-table/ and blocks/pricing-plan/ in your theme. They register as gcb/pricing-table and gcb/pricing-plan.

The table: pricing-table

block.json is WordPress's standard block metadata. There are no attributes in it and no render key: GCB makes the attributes from the fields and finds render.php by itself.

blocks/pricing-table/block.json
{	"apiVersion": 3,	"name": "gcb/pricing-table",	"title": "Pricing table",	"description": "Up to four plans side by side. Each plan is a card your client fills in on the page.",	"category": "design",	"icon": "money-alt",	"supports": { "html": false, "align": [ "wide", "full" ] },	"style": "file:./style.css"}

block.fields.json holds the table's own two fields. Nothing in it mentions the plans.

blocks/pricing-table/block.fields.json
{	"controls": [		{ "id": "c_heading", "type": "text", "label": "Heading", "attributeKey": "heading", "default": "Plans and pricing",			"validation": { "maxLength": 60 } },		{ "id": "c_intro", "type": "textarea", "label": "Intro", "attributeKey": "intro", "default": "Pick the plan that fits. You can change it at any time.",			"validation": { "maxLength": 200 } }	]}

render.php is the template, for the editor and the page alike. It reads the values from $attributes. An element with data-gcb-field="<attributeKey>" and data-gcb-field-type="<type>" is edited where it sits on the page. A field with no marker appears in the block's sidebar.

The template marks where the plans go with a <Repeater>. That one marker holds every rule about them: which block a plan is, the label on the Add button, how many a new table starts with, and the fewest and most there can be. max="4" is the limit of four plans. editLayout="grid" tells the editor to show the plans where your CSS puts them.

blocks/pricing-table/render.php
<?php/** * Pricing table: a heading, an intro and up to four plans. * * Each plan is a block of its own (gcb/pricing-plan). The <Repeater> marker says where the plans go, which block * a plan is, and how few and how many there can be. WordPress won't save a page outside those limits. * * @var array $attributes The block's field values. */ $heading = (string) ( $attributes['heading'] ?? '' );$intro   = (string) ( $attributes['intro'] ?? '' );?><section <?php echo get_block_wrapper_attributes( array( 'class' => 'pricing-table' ) ); ?>>	<?php if ( '' !== $heading ) : ?>		<h2 class="pricing-table__heading" data-gcb-field="heading" data-gcb-field-type="text"><?php echo esc_html( $heading ); ?></h2>	<?php endif; ?>	<?php if ( '' !== $intro ) : ?>		<p class="pricing-table__intro" data-gcb-field="intro" data-gcb-field-type="textarea"><?php echo esc_html( $intro ); ?></p>	<?php endif; ?>	<div class="pricing-table__plans">		<Repeater			allowedBlocks='["gcb/pricing-plan"]'			addButtonLabel="Add plan"			min="1"			max="4"			defaultChildren="3"			editLayout="grid"		/>	</div></section>

style.css styles the table and the plans, so the plan needs no stylesheet of its own.

blocks/pricing-table/style.css
.pricing-table__heading { margin: 0 0 8px; text-align: center; }.pricing-table__intro { margin: 0 auto 32px; max-width: 52ch; text-align: center; opacity: .75; }.pricing-table__plans { display: grid; gap: 24px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); align-items: stretch; }.pricing-plan { position: relative; display: flex; flex-direction: column; height: 100%; box-sizing: border-box; padding: 28px 24px; border: 1px solid color-mix(in srgb, currentColor 18%, transparent); border-radius: 14px; }.pricing-plan.is-featured { border-color: #1d1b18; background: #f3efe8; color: #1d1b18; box-shadow: 0 0 0 1px #1d1b18; }.pricing-plan__badge { position: absolute; top: -13px; left: 24px; margin: 0; padding: 4px 12px; border-radius: 999px; background: #1d1b18; color: #fff; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }.pricing-plan__name { margin: 0 0 12px; font-size: 1.15em; }.pricing-plan__cost { margin: 0 0 20px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; }.pricing-plan__price { font-size: clamp(34px, 3.4vw, 44px); line-height: 1; font-weight: 700; }.pricing-plan__period { opacity: .7; }.pricing-plan__features { list-style: none; margin: 0 0 28px; padding: 0; display: grid; gap: 10px; }.pricing-plan__features li { position: relative; padding-left: 26px; line-height: 1.45; }.pricing-plan__features li::before { content: ""; position: absolute; left: 4px; top: .3em; width: 10px; height: 5px; border-left: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); opacity: .7; }.pricing-plan__button { margin-top: auto; padding: 13px 24px; border: 1px solid currentColor; border-radius: 999px; color: inherit; text-align: center; text-decoration: none; }.pricing-plan.is-featured .pricing-plan__button { border-color: #1d1b18; background: #1d1b18; color: #fff; }.pricing-plan__button:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }

The plan: pricing-plan

parent in its block.json means a plan is only offered inside a Pricing table block.

blocks/pricing-plan/block.json
{	"apiVersion": 3,	"name": "gcb/pricing-plan",	"title": "Plan",	"description": "One plan on the Pricing table block: a name, a price, a list of features and a button.",	"category": "design",	"icon": "tag",	"parent": [ "gcb/pricing-table" ],	"supports": { "html": false }}

The name and the price are required. The price is a text field, not a number, so it can hold "$29", "Free" or "Ask us". The features are a repeater field with a max of 10: rows of one text field each. Featured is a toggle, which stores true or false. The badge has conditionalLogic, so its field only shows while Featured is on.

blocks/pricing-plan/block.fields.json
{	"controls": [		{ "id": "p_words", "type": "group", "label": "Words" },		{ "id": "p_button", "type": "group", "label": "Button" },		{ "id": "p_featured", "type": "group", "label": "Featured" }, 		{ "id": "c_name", "type": "text", "label": "Name", "attributeKey": "name", "default": "Plan name", "parentPanelId": "p_words",			"validation": { "required": true, "maxLength": 40 } },		{ "id": "c_price", "type": "text", "label": "Price", "attributeKey": "price", "default": "$29", "parentPanelId": "p_words",			"validation": { "required": true, "maxLength": 16 } },		{ "id": "c_period", "type": "text", "label": "Period", "attributeKey": "period", "default": "per month", "parentPanelId": "p_words",			"validation": { "maxLength": 30 } },		{ "id": "c_features", "type": "repeater", "label": "Features", "attributeKey": "features", "parentPanelId": "p_words",			"addButtonLabel": "Add feature", "collapsedTitle": "text", "max": 10,			"fields": [				{ "id": "text", "type": "text", "label": "Feature", "attributeKey": "text" }			],			"default": [				{ "_id": "f1", "text": "The first thing they get" },				{ "_id": "f2", "text": "The second thing they get" },				{ "_id": "f3", "text": "The third thing they get" }			] }, 		{ "id": "c_button", "type": "url", "label": "Button", "attributeKey": "button", "parentPanelId": "p_button",			"default": { "url": "/contact", "text": "Choose plan", "opensInNewTab": false } }, 		{ "id": "c_featured", "type": "toggle", "label": "Featured plan", "attributeKey": "featured", "default": false, "parentPanelId": "p_featured" },		{ "id": "c_badge", "type": "text", "label": "Badge", "attributeKey": "badge", "default": "Most popular", "parentPanelId": "p_featured",			"validation": { "maxLength": 24 },			"conditionalLogic": { "enabled": true, "rules": [ { "field": "featured", "operator": "==", "value": true } ] } }	]}

In the template, each feature is marked with its row (data-gcb-row) and its sub-field (data-gcb-subfield), which is how a row of a repeater field is typed on the page. Featured has no marker: it adds the is-featured class and prints the badge.

blocks/pricing-plan/render.php
<?php/** * Plan: one card on the Pricing table block. * * The name, the price, the period, each feature and the button's label are typed on the page. The features are * rows of a repeater field, ten at most. Featured is a switch in the sidebar: it adds the is-featured class and * shows the badge. * * @var array $attributes The block's field values. */ // A field that stores an object (a link) can arrive as an object or an array.$as_array = static function ( $value ) {	return is_object( $value ) ? json_decode( wp_json_encode( $value ), true ) : (array) $value;}; $button   = $as_array( $attributes['button'] ?? array() );$features = (array) ( $attributes['features'] ?? array() );$featured = ! empty( $attributes['featured'] );$badge    = (string) ( $attributes['badge'] ?? '' );$period   = (string) ( $attributes['period'] ?? '' );?><article <?php echo get_block_wrapper_attributes( array( 'class' => 'pricing-plan' . ( $featured ? ' is-featured' : '' ) ) ); ?>>	<?php if ( $featured && '' !== $badge ) : ?>		<p class="pricing-plan__badge" data-gcb-field="badge" data-gcb-field-type="text"><?php echo esc_html( $badge ); ?></p>	<?php endif; ?>	<h3 class="pricing-plan__name" data-gcb-field="name" data-gcb-field-type="text"><?php echo esc_html( $attributes['name'] ?? '' ); ?></h3>	<p class="pricing-plan__cost">		<span class="pricing-plan__price" data-gcb-field="price" data-gcb-field-type="text"><?php echo esc_html( $attributes['price'] ?? '' ); ?></span>		<?php if ( '' !== $period ) : ?>			<span class="pricing-plan__period" data-gcb-field="period" data-gcb-field-type="text"><?php echo esc_html( $period ); ?></span>		<?php endif; ?>	</p>	<?php if ( $features ) : ?>		<ul class="pricing-plan__features" role="list">			<?php			foreach ( $features as $i => $row ) :				$row    = (array) $row;				$row_id = (string) ( $row['_id'] ?? $i );				?>				<li data-gcb-field="features" data-gcb-row="<?php echo esc_attr( $row_id ); ?>" data-gcb-subfield="text" data-gcb-field-type="text"><?php echo esc_html( $row['text'] ?? '' ); ?></li>			<?php endforeach; ?>		</ul>	<?php endif; ?>	<?php if ( ! empty( $button['text'] ) ) : ?>		<a class="pricing-plan__button" data-gcb-field="button" data-gcb-field-type="url" href="<?php echo esc_url( $button['url'] ?? '#' ); ?>"<?php echo ! empty( $button['opensInNewTab'] ) ? ' target="_blank" rel="noopener noreferrer"' : ''; ?>><?php echo esc_html( $button['text'] ); ?></a>	<?php endif; ?></article>

That is all of it. There is no edit.js, no npm and no build step: save the files, reload the editor, and the block is in the inserter.

What your client does

  • Presses Add plan for another plan, up to four.
  • Clicks a name, a price, a period or a feature and types.
  • Adds, removes and reorders features in the sidebar.
  • Changes the button's label and address.
  • Turns on Featured plan in the sidebar for the plan to draw the eye to, and changes its badge.

They can't add a fifth plan, WordPress won't save a table with no plans, and it won't save a plan with no name or no price.

Use it

  1. Unzip the download.
  2. Copy pricing-table/ and pricing-plan/ into your theme's blocks/ folder.
  3. Reload the block editor. Pricing table is in the inserter.

That's all of it. You don't register the block: there's no register_block_type() call and nothing to add to functions.php. GCB registers every folder in your theme's blocks/ folder by itself.

More examples: all examples, or download them together as the GCB Kit. To build one from nothing, see how to build a block.

Build anything in the block editor

Every licence includes all features and a year of updates and support.

Buy GCB from $8.25 a month See pricing