Modify the generated HTML with filters

Reference of the output filters of affiliate-toolkit: change the HTML of product boxes, lists, text links and search forms before it is displayed.

affiliate-toolkit passes the finished HTML of every product box, list and search form through a filter before it is output. With these filters you can change the HTML without touching the templates – for example to show a fallback text when a list is empty, wrap boxes in your own markup or add attributes to links.

Add the code to a small site-specific plugin or the functions.php of a child theme. To change the layout itself, a template is usually the better choice (see What are templates and how do I create them?).

Lists: atkp_modify_output_list

Runs for every list output ([atkp_list], [atkp], list blocks and widgets). The example shows a text when the list contains no products.

add_filter( 'atkp_modify_output_list', 'my_atkp_output_list', 10, 3 );

function my_atkp_output_list( $output, $products, $template ) {
    if ( empty( $products ) ) {
        return '<p class="my-empty-list">No products available at the moment.</p>';
    }
    return $output;
}

Products: atkp_modify_output_product

Runs for every single product output – product boxes, single fields and text links of [atkp_product].

add_filter( 'atkp_modify_output_product', 'my_atkp_output_product', 10, 3 );

function my_atkp_output_product( $output, $product, $template ) {
    // wrap every box in the "wide" template
    if ( $template === 'wide' ) {
        $output = '<div class="my-review-box">' . $output . '</div>';
    }
    return $output;
}

Search form and live list

The Frontend Search & Filter module provides two more filters for its search form and its live list.

add_filter( 'atkp_modify_output_searchform', function ( $output, $template ) {
    return $output;
}, 10, 2 );

add_filter( 'atkp_modify_output_livelist', function ( $output, $shop_ids, $template ) {
    return $output;
}, 10, 3 );

Parameters

FilterParametersDescription
atkp_modify_output_list$output, $products, $templateGenerated HTML, array of the atkp_product objects of the list, template ID or name.
atkp_modify_output_product$output, $product, $templateGenerated HTML, the main product (atkp_product), template ID or name.
atkp_modify_output_product_link$link, $templatehelper, $product, $tracking_idLink attributes, the atkp_template_helper, the product and the tracking ID passed in the shortcode.
atkp_modify_output_searchform$output, $templateGenerated HTML of the search form and its template.
atkp_modify_output_livelist$output, $shop_ids, $templateGenerated HTML of the live list, the searched shop IDs and the template.

Every filter must return the (modified) first parameter. If you return an empty string, nothing is output.