1. Home
  2. Docs
  3. Cresta Checkout for WooCo...
  4. Compatibility and help
  5. For developers

For developers

How to adapt Cresta Checkout with code: custom CSS, hooks and filters, and blocks of your own. Internal names start with cresta_bc_, whatever the plugin is called.

Custom CSS

Every style of the plugin starts with #cbc-app, the wrapper of the three pages. Start your selectors the same way and they’ll win over the plugin’s. Each block is wrapped in an element with the classes cbc-block cbc-block--{type} and a data-cbc-id attribute, for example cbc-block--trust_badges.

#cbc-app .cbc-block--trust_badges {
			border-top: 1px solid #e5e7eb;
			padding-top: 16px;
		}

With PRO, paste your CSS in Settings → Advanced → Custom CSS. It loads only on the pages of the plugin.

Without PRO, add it from a small plugin or a code snippet. Stylesheets of themes are left out of these pages, so add the CSS to the plugin’s own stylesheet:

add_action( 'wp_enqueue_scripts', function () {
			wp_add_inline_style( 'cresta-bc-frontend', '#cbc-app .cbc-block--trust_badges { padding-top: 16px; }' );
		}, 40 ); // After the plugin, which loads its styles at priority 30.

Turn the design off for some buyers

Cresta_BC_Frontend::current_page() returns cart, checkout, thankyou or an empty string, and the filter cresta_bc_current_page can change the answer. Return an empty string to give a page back to WooCommerce:

// Wholesale customers keep the WooCommerce checkout.
		add_filter( 'cresta_bc_current_page', function ( $page ) {
			if ( 'checkout' === $page && in_array( 'wholesale_customer', (array) wp_get_current_user()->roles, true ) ) {
				return '';
			}
			return $page;
		} );

Filters

FilterArgumentsWhat it changes
cresta_bc_current_page$pageThe page handled by the plugin, see above.
cresta_bc_layout$layout, $pageThe layout printed on the storefront. The builder always edits the stored one.
cresta_bc_options$optionsThe values of the Settings panel, as read on the storefront.
cresta_bc_block_visible$visible, $instance, $pageWhether a block is printed. Display conditions use it.
cresta_bc_block_classes$classes, $instanceThe classes of a block wrapper.
cresta_bc_block_refreshes$refreshes, $instanceWhether a block is printed again after each update of the cart.
cresta_bc_block_fields$fields, $blockThe settings of a block. PRO adds the display conditions here.
cresta_bc_app_classes$classes, $pageThe classes of the #cbc-app wrapper.
cresta_bc_keep_theme_assets$handlesStyle and script handles of the theme to keep on these pages.
cresta_bc_isolated_style_paths$pathsThe URL paths whose stylesheets are left out: the themes folder and the uploads folder.
cresta_bc_templates$templatesThe templates of the builder, keyed by page.
cresta_bc_skins$skinsThe skins, keyed by id.
cresta_bc_token_fields$fieldsThe design settings of the Style panel.
cresta_bc_option_fields$fieldsThe fields of the Settings panel.
cresta_bc_font_stacks$stacksThe fonts offered in the Style panel.
cresta_bc_frontend_data$dataThe data passed to the storefront script.
cresta_bc_builder_data$dataThe data passed to the builder.
cresta_bc_cart_response$payload, $op, $pageThe answer of the plugin’s cart requests.
cresta_bc_delivery_wait_gateways$gatewaysPRO. Payment methods that ship only once paid, for the delivery estimate. Default array( 'bacs', 'cheque' ).

For example, to keep the stylesheet of a payment plugin that is enqueued from your theme folder:

add_filter( 'cresta_bc_keep_theme_assets', function ( $handles ) {
			$handles[] = 'my-gateway-style';
			return $handles;
		} );

Actions

ActionArgumentsWhen it fires
cresta_bc_loadednoneOnce every class of the free plugin is available. Register your blocks here: PRO starts from it too.
cresta_bc_saved$requestAfter the builder has saved, with the REST request.
cresta_bc_cart_action$op, $pageFor a cart request the plugin doesn’t know, so that your blocks can handle their own.

A block of your own

A block is a class that extends Cresta_BC_Block, registered on cresta_bc_loaded. It shows up in the builder like the others, with its settings in the side panel.

add_action( 'cresta_bc_loaded', function () {
		
			class My_Shop_Notice_Block extends Cresta_BC_Block {
		
				public $type = 'my_shop_notice';
		
				public function title() {
					return __( 'Shop notice', 'my-shop' );
				}
		
				public function description() {
					return __( 'A short message for your buyers.', 'my-shop' );
				}
		
				public function pages() {
					return array( 'cart', 'checkout' );
				}
		
				public function fields() {
					return array(
						'text' => array(
							'type'    => 'text',
							'label'   => __( 'Text', 'my-shop' ),
							'default' => __( 'Orders placed today ship tomorrow.', 'my-shop' ),
						),
					);
				}
		
				public function render( $settings, $page ) {
					echo '<p class="my-shop-notice">' . esc_html( $settings['text'] ) . '</p>';
				}
			}
		
			Cresta_BC_Blocks::register( new My_Shop_Notice_Block() );
		} );

Only title() and render() are required. The other methods have defaults you can override:

MethodDefaultPurpose
description()emptyThe short text under the name in the builder.
icon()layersAn icon name of Cresta_BC_Icons.
pages()cart, checkoutPages the block can go on: cart, checkout, thankyou.
category()conversionGroup in the library: essential, conversion or content.
zones()all fourZones it can be dropped in: header, main, sidebar, footer.
unique()falseWhether it can be used only once per page.
required( $page )falseRequired blocks can’t be removed.
shared()falseThe builder copies its settings to the other pages it’s on.
refreshes()falsePrinted again after each update of the cart, for blocks that depend on it.
fields()noneIts settings, see below.
preview( $settings, $page )calls render()What the builder shows. Override it when the block reads the cart, which is empty in the builder.

Each setting in fields() has a type, a label and a default, and optionally a help text. The types are text, textarea, html, url, number, range, toggle, select, color, image, product, term and list. Some keys only apply to some types:

  • options for a select, as value => label;
  • min, max and unit for numbers and ranges;
  • fields and add for a list, the settings of each item and the text of the button that adds one;
  • show_if shows the setting only when others have some values, for example array( 'amount_type' => array( 'fixed' ) );
  • money set to true marks an amount in the shop currency, converted for multi-currency shops;
  • translate set to false keeps a text out of String Translation.

Settings are cleaned according to their type before they’re saved, and render() gets them merged over the defaults. Escape what you print, as in the example.

Where the data lives

DataStored in
LayoutsOptions cresta_bc_layout_cart, cresta_bc_layout_checkout, cresta_bc_layout_thankyou
Settings panel and designOptions cresta_bc_options and cresta_bc_design
Order bump lineOrder item meta _cresta_bc_bump, the id of the block
Reward bar giftOrder item meta _cresta_bc_reward, the step it comes from
Reward bar discountA coupon line with the code cresta-reward, made in memory
Message of a feeFee item meta _cresta_bc_note and _cresta_bc_note_label
Next order couponOrder meta _cresta_bc_next_coupon with the code, coupon meta _cresta_bc_from_order with the order id

To see a page without the plugin while you debug, add ?cbc=off to its address while logged in as a shop manager.