1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
<?php
namespace SIW\Widgets;
use SIW\HTML;
class Quick_Search_Results extends Widget {
protected $widget_id ='quick_search_results';
protected $widget_dashicon = 'search';
protected function set_widget_properties() {
$this->widget_name = __( 'Snel Zoeken - resultaat', 'siw');
$this->widget_description = __( 'Toont zoekresultaten', 'siw' );
}
public function get_widget_form() {
$widget_form = [
'title' => [
'type' => 'text',
'label' => __( 'Titel', 'siw'),
'default' => __( 'Groepsprojecten', 'siw' ),
],
];
return $widget_form;
}
public function initialize() {
add_filter( 'query_vars', [ $this, 'register_query_vars'] );
add_filter( 'rocket_cache_query_strings', [ $this, 'register_query_vars'] );
}
public function register_query_vars( $vars ) {
$vars[] = 'bestemming';
$vars[] = 'maand';
return $vars;
}
protected function get_content( array $instance, array $args, array $template_vars, string $css_name ) {
$url = wc_get_page_permalink( 'shop' );
$text = __( 'Bekijk alle projecten', 'siw' );
$category_arg = '';
$category_slug = sanitize_key( get_query_var( 'bestemming', false ) );
$category = get_term_by( 'slug', $category_slug, 'product_cat' );
if ( is_a( $category, '\WP_Term') ) {
$category_arg = sprintf( 'category="%s"', $category_slug );
$url = get_term_link( $category->term_id );
$text .= SPACE . sprintf( __( 'in %s', 'siw' ), $category->name );
}
$month_arg = '';
$month_slug = sanitize_key( get_query_var( 'maand', false ) );
$month = get_term_by( 'slug', $month_slug, 'pa_maand');
if ( is_a( $month, '\WP_Term') ) {
$month_id = $month->term_id;
$month_arg = sprintf( 'attribute="maand" terms="%s"', $month_id );
$url = add_query_arg( 'filter_maand', $month_slug, $url );
$text .= SPACE . sprintf( __( 'in %s', 'siw' ), strtolower( $month->name ) );
}
$content =
esc_html__( 'Met een Groepsproject ga je voor 2 tot 3 weken naar een project, de begin- en einddatum van het project staan al vast.', 'siw' ) . SPACE .
esc_html__( 'Hieronder zie je een selectie van de mogelijkheden', 'siw' ) .
do_shortcode( sprintf( '[products limit="6" columns="3" orderby="random" visibility="visible" %s %s cache=false]', $category_arg, $month_arg ) ) .
'<div style="text-align:center">' .
HTML::generate_link( $url, $text, [ 'class' => 'kad-btn kad-btn-primary'] ) .
'</div>';
return $content;
}
}