Skip to content

Developer Docs

Hooks & Filters Reference

Hooks & filters reference for Smart Add-Ons — all PHP actions and filters are prefixed with saue_.

Action hooks

Hook name Arguments Description
saue_register_field_types $registry: FieldTypeRegistry Fired during plugin boot. Register a custom field type class with the registry.
saue_addon_group_saved $group_id: int Fired after an addon group is created or updated via the REST API. Receives the group ID only.
saue_addon_field_deleted $field_id: int Fired after a field row is deleted from an addon group.
saue_before_render_product_addons $product_id: int Fired immediately before the storefront renders the addon groups for a product page. Use to inject custom markup or enqueue assets.
saue_integrations_loaded none Fired after all built-in integrations (WPML, Subscriptions, Bookings) have been registered. Use to register your own integration.
saue_bookings_before_product_addons $product_id: int Registered only when WooCommerce Bookings is active. Re-fires saue_before_render_product_addons under this name for any product that has addons — not only bookable products. Use it to add your own booking-specific logic; the plugin does not include any.

Filter hooks

Filter name Arguments Return type Description
saue_addon_groups_for_product $groups: array, $product_id: int array Modify, add, or remove the addon groups shown for a specific product. Return the modified $groups array.
saue_addon_field_html $html: string, $field: array string Customize the rendered HTML for a single addon field on the storefront. Return modified HTML string.
saue_translate_string $string: string, $context: string, $name: string string Called for every user-facing addon group, field, and option string. When WPML is active, the plugin already passes these through wpml_translate_single_string. Unregistered dynamic strings still return untranslated — see the WPML guide.
saue_locate_template $path: string, $template: string string Override any plugin template file. Return an absolute file path to your custom template.
saue_subscriptions_addon_groups $groups: array, $product_id: int array Filter the addon groups shown for WooCommerce Subscription products specifically.
saue_price_preview_result $result: array, $selections: array array Modify the calculated price preview result before it is returned to the storefront. $result contains total, addons_total, breakdown.
saue_order_item_meta_label $label: string, $field: array string Change the label used for addon field values in the order item meta display.
saue_upload_allowed_mime_types $types: array, $field_id: int array Modify allowed MIME types for a file upload field. Return an array of MIME type strings.

Examples

Register a custom field type

/**
 * Register a custom "Color Swatch" field type.
 * MyColorSwatchFieldType must implement:
 * SmartAddOnsContractsFieldTypeInterface
 */
add_action( 'saue_register_field_types', function( $registry ) {
    $registry->register( 'color_swatch', new MyColorSwatchFieldType() );
} );

Add a group to a product programmatically

/**
 * Inject an extra addon group for product ID 42
 * during storefront rendering.
 */
add_filter( 'saue_addon_groups_for_product', function( $groups, $product_id ) {
    if ( $product_id === 42 ) {
        $groups[] = [
            'id'     => 99,
            'label'  => 'VIP Packaging',
            'fields' => [],
        ];
    }
    return $groups;
}, 10, 2 );

Override a template file

/**
 * Load a custom version of the addon group template
 * from the active theme's /saue/ folder.
 */
add_filter( 'saue_locate_template', function( $path, $template ) {
    $theme_file = get_stylesheet_directory() . '/saue/' . $template;
    if ( file_exists( $theme_file ) ) {
        return $theme_file;
    }
    return $path;
}, 10, 2 );

Restrict allowed MIME types for file uploads

/**
 * Allow only PNG and JPG uploads for field ID 5.
 */
add_filter( 'saue_upload_allowed_mime_types', function( $types, $field_id ) {
    if ( $field_id === 5 ) {
        return [ 'image/png', 'image/jpeg' ];
    }
    return $types;
}, 10, 2 );

Register addon strings with WPML

When WPML is active, Smart Add-Ons already attaches to saue_translate_string and calls wpml_translate_single_string — you do not add that filter yourself. Dynamic addon labels still need to be registered with WPML String Translation before they actually translate. Hook saue_addon_group_saved (it receives the group ID only) and call icl_register_string() using the same context and name values as the plugin. Full walkthrough: WPML support.

/**
 * Register a group's translatable strings with WPML after save.
 * Context/name pairs must match StringTranslator. The plugin does
 * not call icl_register_string() itself — see the WPML guide.
 */
add_action( 'saue_addon_group_saved', function( $group_id ) {
    if ( ! function_exists( 'icl_register_string' ) ) {
        return;
    }

    // Load the saved group, then register each string:

    // icl_register_string( 'saue_group', 'name_' . $group_id, $group['name'] );

    // icl_register_string( 'saue_field', 'label_' . $field_id, $field['label'] );

    // icl_register_string( 'saue_field_option', 'option_' . $field_id . '_' . $value, $option['label'] );

} );

Implementing FieldTypeInterface

A custom field type must implement SmartAddOnsContractsFieldTypeInterface. The interface requires:

interface FieldTypeInterface {
    // Machine name: 'color_swatch'

    public function get_type(): string;

    // Human label shown in the admin UI

    public function get_label(): string;

    // Schema for the admin field editor (JSON Schema)

    public function get_schema(): array;

    // Validate a submitted value; throw ValidationException on failure

    public function validate( $value, array $field ): void;

    // Sanitize the value before storing

    public function sanitize( $value, array $field );

    // Render the storefront HTML for this field

    public function render( array $field, $value ): string;
}