ajax-search-for-woocommerce
Last commit date
assets
5 years ago
composer
5 years ago
fs
5 years ago
includes
5 years ago
languages
5 years ago
partials
5 years ago
vendor
5 years ago
ajax-search-for-woocommerce.php
5 years ago
readme.txt
5 years ago
widget.php
5 years ago
wpml-config.xml
5 years ago
widget.php
74 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | // Exit if accessed directly |
| 5 | if ( ! defined( 'ABSPATH' ) ) { |
| 6 | exit; |
| 7 | } |
| 8 | |
| 9 | if ( class_exists( 'WC_Widget' ) ) { |
| 10 | |
| 11 | |
| 12 | add_action( 'widgets_init', function () { |
| 13 | register_widget( 'DGWT_WCAS_Search_Widget' ); |
| 14 | } ); |
| 15 | |
| 16 | class DGWT_WCAS_Search_Widget extends WC_Widget { |
| 17 | |
| 18 | /** |
| 19 | * Constructor |
| 20 | */ |
| 21 | public function __construct() { |
| 22 | |
| 23 | |
| 24 | $this->widget_cssclass = 'woocommerce dgwt-wcas-widget'; |
| 25 | $this->widget_description = __( 'AJAX (live) search form for WooCommerce', 'ajax-search-for-woocommerce' ); |
| 26 | $this->widget_id = 'dgwt_wcas_ajax_search'; |
| 27 | $this->widget_name = __( 'FiboSearch bar', 'ajax-search-for-woocommerce' ); |
| 28 | $this->settings = array( |
| 29 | 'title' => array( |
| 30 | 'type' => 'text', |
| 31 | 'std' => '', |
| 32 | 'label' => __( 'Title', 'ajax-search-for-woocommerce' ) |
| 33 | ), |
| 34 | 'layout' => array( |
| 35 | 'type' => 'select', |
| 36 | 'std' => 'default', |
| 37 | 'options' => array( |
| 38 | 'default' => __( 'Default', 'ajax-search-for-woocommerce' ), |
| 39 | 'classic' => __( 'Search bar only', 'ajax-search-for-woocommerce' ), |
| 40 | 'icon' => __( 'Search icon', 'ajax-search-for-woocommerce' ), |
| 41 | 'icon-flexible' => __( 'Icon on mobile, search bar on desktop', 'ajax-search-for-woocommerce' ), |
| 42 | ), |
| 43 | 'label' => __( 'Layout', 'ajax-search-for-woocommerce' ) |
| 44 | ) |
| 45 | ); |
| 46 | |
| 47 | parent::__construct(); |
| 48 | } |
| 49 | |
| 50 | |
| 51 | /** |
| 52 | * Outputs the content of the widget |
| 53 | * |
| 54 | * @param array $args |
| 55 | * @param array $instance |
| 56 | */ |
| 57 | public function widget( $args, $instance ) { |
| 58 | |
| 59 | $this->widget_start( $args, $instance ); |
| 60 | |
| 61 | $layoutParam = ''; |
| 62 | if ( ! empty( $instance['layout'] ) && in_array( $instance['layout'], array( 'classic', 'icon', 'icon-flexible' ) ) ) { |
| 63 | $layoutParam = ' layout="' . $instance['layout'] . '"'; |
| 64 | } |
| 65 | |
| 66 | echo do_shortcode( '[wcas-search-form' . $layoutParam . ']' ); |
| 67 | |
| 68 | $this->widget_end( $args ); |
| 69 | } |
| 70 | |
| 71 | } |
| 72 | |
| 73 | } |
| 74 |