woof_redraw_elements_after_ajax
允许在用户以 AJAX 模式进行过滤时添加任何消息。
Example:
add_filter('woof_redraw_elements_after_ajax', function($fields, $query) {
ob_start();
if (isset($query->query['tax_query']) AND $query->query['tax_query']) {
$html = "<h1 class='entry-title'>Looks like you like the color:";
foreach ($query->query['tax_query'] as $item) {
if (isset($item['taxonomy']) AND $item['taxonomy'] = 'pa_color') {
$term = get_term_by('slug', $item['terms'][0], 'pa_color');
if (is_object($term)) {
$html .= $term->name;
}
}
}
echo $html, "!</h1>";
$fields['.entry-title'] = ob_get_contents();
}
ob_end_clean();
return $fields;
}, 999, 2);
在上面的示例中,用户在过滤器中选择任何颜色时会收到消息。根据此逻辑,您可以在用户使用过滤时向用户提供任何商业建议。
请注意:
- $fields[‘.entry-title‘] = ob_get_contents(); – 红色是消息应显示所在的容器的 CSS 类
- $html = “<h1 class=’entry-title’>Looks like you like the color:”; … echo $html, “!</h1>”; – 这里是消息本身,当然您可以使用 PHP 开关 为不同的搜索请求内容显示不同的消息
