In addition to styles, the plugin uses various templates for filter output.
Styles are used to add certain classes and make small changes to the position of elements. At the same time templates are used to define the general structure of elements.
The templates for filters can be found in the directory templates\filters:
- checkbox.php – template for checkboxes, filters by color and filters by image
- datepicker.php – template for selecting a range of dates
- new_slider.php – template for new sliders
- select.php – template for a drop-down list
- slider.php – template for old sliders
Templates for other elements are in the directory templates\elements:
- button.php – template for filter application and filter reset buttons
- selected_filters.php – template for output of selected filters
There are three ways to change the template:
- Using hooks is a better method for small changes, as it does not change the initial template when changing the template in the plugin.
- Override the template in the theme – use only if you are completely redesigning the template, then you will most likely need to modify the JavaScript code, so that the filters will work correctly with new style and template.
- Add a new template to the theme – you can use it instead of the second method if you create a new filter type or need to use new JavaScript code. In this case, the functionality of the other templates will remain unchanged. You also need to create new styles that will use this template.
Modifying the template with hooks
Different templates use different sets of filters, but some are the same.
Templates for filters use two hooks:
- BeRocket_AAPF_template_full_content – filtering of elements of the same filter value
- BeRocket_AAPF_template_full_element_content – filtering of all elements of one filter to build HTML code
Template for other elements uses one hook:
- BeRocket_AAPF_template_full_element_content – filtering of the Update button, Reset button, Selected filter area elements for HTML code builder
Example code for adding a block to filter before attribute/taxonomy values:
add_filter('BeRocket_AAPF_template_full_content', 'some_custom_berocket_aapf_template_full_content', 4000, 3);
function some_custom_berocket_aapf_template_full_content($template_content, $terms, $berocket_query_var_title) {
if( $berocket_query_var_title['new_template'] == 'checkbox') {
$template_content['template']['content']['filter']['content'] = berocket_insert_to_array(
$template_content['template']['content']['filter']['content'],
'list',
array(
'custom_content' => '<div><h1>SOME CUSTOM HTML</h1><p>Display there anything after title</p></div>'
),
true
);
}
return $template_content;
}Example code to replace H3 tag with H5 tag in the header:
add_filter('BeRocket_AAPF_template_full_content', 'some_custom_berocket_aapf_template_full_content', 4000, 1);
add_filter('BeRocket_AAPF_template_full_element_content', 'some_custom_berocket_aapf_template_full_content', 4000, 1);
function some_custom_berocket_aapf_template_full_content($template_content) {
$template_content['template']['content']['header']['content']['title']['tag'] = 'h5';
return $template_content;
}Changing the template by overriding the theme
To override a template, you need to create a directory woocommerce-ajax_filters\filters in the root of the theme. The original templates can be found in the directory templates\filters. It is necessary to copy the necessary template and then edit it.
Create a new template for the plugin
To create a new template, you need to create the woocommerce-ajax_filters\filters directory in the root of the topic and create a new file there or copy any standard template from the templates\filters directory and rename it. It is necessary to use a name that does not coincide with the standard templates.In order to use the created template you need to create a new style. More details about creation of styles can be found at this link Добавить дополнительные стили.
