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 123 124 125 126
<?php
namespace SIW\Widgets;
use SIW\HTML;
use SIW\Util;
class Quick_Search_Form extends Widget {
protected $widget_id ='quick_search_form';
protected $widget_dashicon = 'search';
protected function set_widget_properties() {
$this->widget_name = __( 'Snel Zoeken - formulier', 'siw');
$this->widget_description = __( 'Toont zoekformulier', 'siw' );
}
public function get_widget_form() {
$widget_forms = [
'title' => [
'type' => 'text',
'label' => __( 'Titel', 'siw'),
'default' => __( 'Snel Zoeken', 'siw' ),
],
'result_page' => [
'type' => 'select',
'label' => __( 'Resultatenpagina', 'siw' ),
'prompt' => __( 'Selecteer een pagina', 'siw' ),
'options' => Util::get_pages(),
],
];
return $widget_forms;
}
protected function get_content( array $instance, array $args, array $template_vars, string $css_name ) {
$result_page_url = wp_make_link_relative( get_permalink( $instance['result_page'] ) );
ob_start();
?>
<div>
<form id="siw_quick_search" method="get" action="<?= esc_url( $result_page_url );?>">
<ul>
<li><?= HTML::generate_field( 'select', [ 'name' => 'bestemming', 'id' => 'bestemming', 'options' => $this->get_destinations() ] );?></li>
<li><?= HTML::generate_field( 'select', [ 'name' => 'maand', 'id' => 'maand', 'options' => $this->get_months() ] );?></li>
<li><?= HTML::generate_field( 'submit', [ 'value' => __( 'Zoeken', 'siw' ) ] );?></li>
</ul>
</form>
</div>
<?php
$content = ob_get_clean();
return $content;
}
protected function get_destinations() {
$categories = get_terms( [
'taxonomy' => 'product_cat',
'hide_empty' => true,
] );
$destinations = [
'' => __( 'Waar wil je heen?', 'siw' ),
];
foreach ( $categories as $category ) {
if ( 'uncategorized' != $category->slug && get_term_meta( $category->term_id, 'project_count', true ) > 0 ) {
$destinations[ $category->slug ] = $category->name;
}
}
return $destinations;
}
protected function get_months() {
$terms = get_terms( [
'taxonomy' => 'pa_maand',
'hide_empty' => true,
]);
$months = [
'' => __( 'Wanneer wil je weg?', 'siw' )
];
foreach ( $terms as $term ) {
if ( get_term_meta( $term->term_id, 'project_count', true ) > 0 ) {
$months[ $term->slug ] = $term->name;
}
}
return $months;
}
}