Geen omschrijving

widget-description.php 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. class BeRocket_product_brand_description_Widget extends BeRocket_Base_Product_List_Widget {
  3. public function __construct() {
  4. parent::__construct(
  5. "berocket_product_brand_description_widget",
  6. __( "WooCommerce Product Brands Description", 'brands-for-woocommerce' ),
  7. array( "description" => "" )
  8. );
  9. $this->defaults += array(
  10. 'brand_id' => '',
  11. 'display_title' => '',
  12. 'display_description' => '',
  13. 'banner_display' => '',
  14. 'banner_width' => 100,
  15. 'banner_width_units' => '%',
  16. 'banner_height' => '',
  17. 'banner_height_units' => 'px',
  18. 'banner_fit' => 'cover',
  19. 'banner_align' => 'center',
  20. 'thumbnail_display' => '',
  21. 'thumbnail_width' => 100,
  22. 'thumbnail_width_units' => '%',
  23. 'thumbnail_height' => '',
  24. 'thumbnail_height_units' => 'px',
  25. 'thumbnail_fit' => 'cover',
  26. 'thumbnail_align' => 'none',
  27. 'related_products_display' => '',
  28. 'display_link' => '',
  29. 'featured' => '',
  30. );
  31. // $related_keys = array_diff( array_keys( $this->form_fields ), array( 'title' ) );
  32. $title = array( 'title' => $this->form_fields['title'] );
  33. $related = $this->form_fields;
  34. unset( $related['title'] );
  35. foreach ( $related as $key => $value ) {
  36. $related[$key]['class'] .= ' related_products_display_depending';
  37. }
  38. $this->form_fields = $title + array(
  39. 'brand_id' => array(
  40. "title" => __( 'Brand', 'brands-for-woocommerce' ),
  41. 'type' => 'autocomplete',
  42. 'class' => 'width100',
  43. // 'walker' => 'Br_Walker_Brand_Selectlist',
  44. ),
  45. 'display_title' => array(
  46. "title" => __( 'Display brand title', 'brands-for-woocommerce' ),
  47. 'type' => 'checkbox',
  48. 'class' => 'br_brands_checkbox_block',
  49. ),
  50. 'display_description' => array(
  51. "title" => __( 'Display brand description', 'brands-for-woocommerce' ),
  52. 'type' => 'checkbox',
  53. 'class' => 'br_brands_checkbox_block',
  54. ),
  55. 'thumbnail' => array(
  56. "title" => __( 'Thumbnail:', 'brands-for-woocommerce' ),
  57. 'type' => 'image',
  58. 'class' => 'width100',
  59. 'align_options' => array(
  60. "left" => array( 'name' => __( 'Left to text', 'brands-for-woocommerce' ) ),
  61. "right" => array( 'name' => __( 'Right to text', 'brands-for-woocommerce' ) ),
  62. "none" => array( 'name' => __( 'None', 'brands-for-woocommerce' ) ),
  63. )
  64. ),
  65. 'banner' => array(
  66. "title" => __( 'Banner:', 'brands-for-woocommerce' ),
  67. 'type' => 'image',
  68. 'class' => 'width100',
  69. 'align_options' => array(
  70. "left" => array( 'name' => __( 'Left', 'brands-for-woocommerce' ) ),
  71. "right" => array( 'name' => __( 'Right', 'brands-for-woocommerce' ) ),
  72. "center" => array( 'name' => __( 'Center', 'brands-for-woocommerce' ) ),
  73. )
  74. ),
  75. 'related_products' => array(
  76. "title" => __( 'Related products', 'brands-for-woocommerce' ),
  77. 'type' => 'fieldset',
  78. 'items' => array(
  79. 'related_products_display' => array(
  80. "title" => __( 'Display', 'brands-for-woocommerce' ),
  81. 'type' => 'checkbox',
  82. 'class' => 'width100 br_brand_show_more_options',
  83. 'id' => "related_products_display_depending",
  84. )
  85. ) + $related,
  86. ),
  87. 'display_link' => array(
  88. "title" => __( 'Display external link', 'brands-for-woocommerce' ),
  89. 'type' => 'checkbox',
  90. 'class' => 'br_brands_checkbox_block',
  91. ),
  92. 'featured' => array(
  93. "title" => __( 'Display last created featured brand', 'brands-for-woocommerce' ),
  94. 'type' => 'checkbox',
  95. 'class' => 'br_brands_checkbox_block',
  96. ),
  97. );
  98. $this->shortcode_args = array(
  99. 'display_thumbnail' => 'thumbnail_display',
  100. 'width' => 'thumbnail_width',
  101. 'align' => 'thumbnail_align',
  102. );
  103. }
  104. public function update( $new_instance, $old_instance ) {
  105. $new_instance['brand_id'] = empty( $_REQUEST['berocket_brand'] ) ? '' : serialize( $_REQUEST['berocket_brand'] );
  106. $instance = parent::update( $new_instance, $old_instance );
  107. return $instance;
  108. }
  109. public function widget( $args, $instance ) {
  110. $instance = $this->replace_shortcode_keys( $instance );
  111. $instance = $this->get_size( 'thumbnail_width', $instance );
  112. $instance = $this->get_size( 'thumbnail_height', $instance );
  113. $instance = $this->get_size( 'banner_width', $instance );
  114. $instance = $this->get_size( 'banner_height', $instance );
  115. if ( ( !is_tax( BeRocket_product_brand::$taxonomy_name ) || !get_query_var( 'term' ) ) && empty( $instance['id'] )
  116. && empty( $instance['featured'] ) ) {
  117. return;
  118. }
  119. $instance['display_title'] = apply_filters( 'widget_title', empty($instance['display_title']) ? '' : $instance['display_title'], $instance );
  120. $instance = wp_parse_args( (array) $instance, $this->defaults );
  121. if ( !empty( $instance['featured'] ) ) {
  122. $terms = get_terms(
  123. array(
  124. 'hide_empty' => false, // also retrieve terms which are not used yet
  125. 'meta_query' => array(
  126. array(
  127. 'key' => 'br_brand_featured',
  128. 'value' => 1,
  129. )
  130. ),
  131. 'number' => 1,
  132. 'orderby' => 'id',
  133. 'order' => 'DESC',
  134. 'taxonomy' => BeRocket_product_brand::$taxonomy_name,
  135. )
  136. );
  137. if ( empty( $terms ) ) return;
  138. $term = $terms[0];
  139. } else {
  140. $term = empty( $instance['id'] ) ?
  141. get_term_by( 'slug', get_query_var( 'term' ), BeRocket_product_brand::$taxonomy_name ) :
  142. get_term_by( 'id', $instance['id'], BeRocket_product_brand::$taxonomy_name );
  143. }
  144. $image = get_term_meta( $term->term_id, 'brand_image_url', true );
  145. $BeRocket_product_brand = BeRocket_product_brand::getInstance();
  146. $options = $BeRocket_product_brand->get_option();
  147. $instance['link_text'] = empty( $options['link_text'] ) ? '' : $options['link_text'];
  148. $instance['link_open_in_new_tab'] = empty( $options['link_open_in_new_tab'] ) ? '' : $options['link_open_in_new_tab'];
  149. $related_products_options = array(
  150. 'columns',
  151. 'orderby',
  152. 'order',
  153. 'slider',
  154. 'hide_brands',
  155. 'per_page',
  156. 'cache_key',
  157. );
  158. foreach ( $related_products_options as $option ) {
  159. $instance["related_products_$option"] = $instance[$option];
  160. }
  161. set_query_var( 'options', $instance );
  162. set_query_var( 'brand_term', $term );
  163. set_query_var( 'tooltip', BeRocket_product_brand::get_tooltip( $term->term_id ) );
  164. $args['template'] = 'description';
  165. parent::widget( $args, $instance );
  166. }
  167. protected function replace_shortcode_keys( $instance ) {
  168. $instance = parent::replace_shortcode_keys( $instance );
  169. $instance = $this->get_size( 'thumbnailw', $instance );
  170. return $instance;
  171. }
  172. }