AbstractFlow implements FlowInterface and provides all the boilerplate so you can focus on your flow’s unique logic. Extend it and implement the three abstract methods.
Extending AbstractFlow
Methods you MUST override
render_custom_content(): void
Outputs the HTML for the product page. Called by render_flow_wrapper(), which wraps the output in <div class="utb-product-flow-container id-{flow_id}">.
prepare_cart_metadata(array $post_data): array
Builds the metadata array saved to the WooCommerce cart item and order. See FlowInterface::prepare_cart_metadata() for full documentation.
validate_cart_data(array $post_data)
Validates the add-to-cart form submission. Return true on success or an error string on failure. See FlowInterface::validate_cart_data() for full documentation.
Methods you CAN override
enqueue_assets(): void
Called on wp_enqueue_scripts. The base implementation checks is_product() and applies_to_product() and returns early if neither applies. Override to enqueue flow-specific JavaScript and CSS.
get_shortcodes(): array
Returns shortcodes to register. Defaults to an empty array in the base class (the interface requires it; AbstractFlow does not provide a default). Override to register shortcodes.
get_ajax_endpoints(): array
Returns AJAX endpoints to register. Both wp_ajax_{action} and wp_ajax_nopriv_{action} are registered for each entry, so all endpoints are accessible to logged-in and guest users. Override to add endpoints.
Hooks registered by init()
Calling AbstractFlow::init() (which happens automatically via FlowRegistry) registers these WordPress/WooCommerce hooks:
| Hook | Method | Priority | Args |
|---|---|---|---|
wp | maybe_setup_landing | 50 | — |
woocommerce_add_to_cart_validation | validate_add_to_cart | 10 | 3 |
woocommerce_add_cart_item_data | add_cart_item_data_filter | 10 | 3 |
woocommerce_before_calculate_totals | apply_dynamic_pricing | 20 | 1 |
woocommerce_checkout_create_order_line_item | save_order_item_meta | 10 | 4 |
wp_enqueue_scripts | enqueue_assets | — | — |
add_shortcode() and AJAX endpoints with add_action() during init() based on what your overridden get_shortcodes() and get_ajax_endpoints() return.
Product landing cleanup
Whenapplies_to_product() returns true for the current product, setup_product_landing() removes the following WooCommerce elements to make room for the flow’s custom UI:
Removed from woocommerce_before_main_content:
woocommerce_breadcrumb(priority 20)
woocommerce_sidebar:
woocommerce_get_sidebar(priority 10)
woocommerce_single_product_summary:
woocommerce_template_single_title(priority 5)woocommerce_template_single_rating(priority 10)woocommerce_template_single_price(priority 10)woocommerce_template_single_excerpt(priority 20)woocommerce_template_single_add_to_cart(priority 30)woocommerce_template_single_meta(priority 40)woocommerce_template_single_sharing(priority 50)
woocommerce_after_single_product_summary:
woocommerce_output_product_data_tabs(priority 10)woocommerce_upsell_display(priority 15)woocommerce_output_related_products(priority 20)
woocommerce_single_product_summary at priority 30 and applies inline CSS to hide any price markup that the theme may still render.
Utility methods
Nonce helpers
"{flow_id}_{action}".
create_nonce(). Returns true if valid.
AJAX response helpers
wp_send_json_success() and terminates.
wp_send_json_error() with the given HTTP status code and terminates. The $data parameter is merged into the response body alongside the message key.
Sanitization helpers
wp_unslash() then sanitize_text_field() on $value.
wp_unslash() then sanitize_email() on $value.
$value to int.