Skip to main content

Modifying Block and Front-End HTML

You can modify the HTML output of any SureCart block using WordPress’s render_block filter combined with the HTML Tag Processor—a safe, performant way to manipulate HTML without regex or string replacement.

Finding a Block’s Name

To target a specific block, you need its name. SureCart blocks use the surecart/ namespace (e.g., surecart/product-title). Here are ways to find a block’s name:

Browser Inspector

Inspect the block on the frontend. The wrapper element’s class follows the pattern wp-block-{namespace}-{block-name}. For example, wp-block-surecart-product-title means the block name is surecart/product-title.

Code editor

In the block editor, switch to the Code Editor view (⇧⌘⌥M or via Options menu). Block names appear in HTML comments like <!-- wp:surecart/product-title -->.

PHP

Use get_dynamic_block_names() to list all registered dynamic blocks:
Common SureCart blocks include surecart/product-title, surecart/product-price, surecart/buy-button, surecart/product-image, surecart/product-description, and surecart/product-collection.

Using render_block

The render_block filter runs after a block is rendered, giving you access to the final HTML output. You can target specific blocks by checking $block['blockName'].

Block-Specific Shorthand

For cleaner code, use the render_block_{$this->name} filter which only fires for a specific block type—no conditional check needed:

Using the HTML Tag Processor

The WP_HTML_Tag_Processor class provides a safe way to traverse and modify HTML. It’s the recommended approach over regex or string manipulation.

Block Examples

Add Custom Data Attributes to Buy Buttons

Wrap Product Prices with Custom Markup

Add Low Stock Warning Badge

Append a warning badge next to the product title when stock is low. This uses SureCart’s built-in .sc-tag component classes for consistent styling.
SureCart’s .sc-tag component supports variants like --warning, --success, --danger, --info, and --primary, plus sizes --small, --medium, --large, and a --pill modifier for rounded corners.
The HTML Tag Processor is available in WordPress 6.2+. For older versions, consider using DOMDocument or carefully crafted string replacements.

Block Pattern Filters

surecart/blocks/pattern_categories

Filter the available block pattern categories.

surecart/blocks/patterns

Filter the registered block patterns.

surecart_block_output

Filter the rendered output of SureCart blocks.

Page Builder Filters

sc_elementor_templates

Filter available Elementor templates.

Shortcode Filters

surecart/shortcode/render

Filter the rendered shortcode output.
Filter Parameters

Review Filters

surecart/review_count/enabled

Control whether review counts are displayed.

surecart/review_form/enabled

Control whether the review form is displayed.

surecart/review_average/enabled

Control whether average rating is displayed.

surecart/review_stars/enabled

Control whether star ratings are displayed.

sc_anonymous_reviewer_name

Filter the display name for anonymous reviewers.

Require Purchase for Reviews

Template Actions

These actions allow you to inject content into SureCart templates and pages.

surecart_buy_page_body_open

Fired at the start of the buy page body. Use this to add announcements, banners, or tracking scripts.

surecart_template_dashboard_body_open

Fired at the start of the customer dashboard template body.

surecart_template_blank_body_open

Fired at the start of the blank template body.

Page & Post Actions

surecart/post_created

Fired when SureCart seeds pages (checkout page, shop page, dashboard page, checkout forms) during installation.
Action Parameters

Use Cases

Add Tracking Pixels

Custom Dashboard Header

Media

Customize video and image display.

Admin

Customize admin menus and toolbars.