| 1 |
<?php |
| 2 |
|
| 3 |
namespace UltimateStoreKit\Modules\ProductList\Widgets; |
| 4 |
|
| 5 |
|
| 6 |
use Elementor\Controls_Manager; |
| 7 |
use UltimateStoreKit\Base\Module_Base; |
| 8 |
use Elementor\Group_Control_Border; |
| 9 |
use Elementor\Group_Control_Background; |
| 10 |
use Elementor\Group_Control_Box_Shadow; |
| 11 |
use Elementor\Group_Control_Image_Size; |
| 12 |
use Elementor\Group_Control_Typography; |
| 13 |
use UltimateStoreKit\traits\Global_Widget_Controls; |
| 14 |
use UltimateStoreKit\traits\Global_Widget_Template; |
| 15 |
// use UltimateStoreKit\traits\Global_Swiper_Template; |
| 16 |
use UltimateStoreKit\Includes\Controls\GroupQuery\Group_Control_Query; |
| 17 |
use WP_Query; |
| 18 |
|
| 19 |
if (!defined('ABSPATH')) { |
| 20 |
exit; |
| 21 |
} |
| 22 |
|
| 23 |
// Exit if accessed directly |
| 24 |
|
| 25 |
class Product_List extends Module_Base { |
| 26 |
use Global_Widget_Controls; |
| 27 |
use Global_Widget_Template; |
| 28 |
// use Global_Swiper_Template; |
| 29 |
use Group_Control_Query; |
| 30 |
|
| 31 |
/** |
| 32 |
* @var \WP_Query |
| 33 |
*/ |
| 34 |
private $_query = null; |
| 35 |
public function get_name() { |
| 36 |
return 'usk-product-list'; |
| 37 |
} |
| 38 |
|
| 39 |
public function get_title() { |
| 40 |
return esc_html__('Product List', 'ultimate-store-kit'); |
| 41 |
} |
| 42 |
|
| 43 |
public function get_icon() { |
| 44 |
return 'usk-widget-icon usk-icon-product-list'; |
| 45 |
} |
| 46 |
|
| 47 |
public function get_categories() { |
| 48 |
return ['ultimate-store-kit']; |
| 49 |
} |
| 50 |
|
| 51 |
public function get_keywords() { |
| 52 |
return ['product', 'product list', 'table', 'wc', 'list']; |
| 53 |
} |
| 54 |
|
| 55 |
public function get_script_depends() { |
| 56 |
return ['micromodal']; |
| 57 |
} |
| 58 |
|
| 59 |
public function get_style_depends() { |
| 60 |
if ($this->usk_is_edit_mode()) { |
| 61 |
return ['usk-all-styles']; |
| 62 |
} else { |
| 63 |
return ['usk-font', 'usk-product-list']; |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
public function get_custom_help_url() { |
| 68 |
return 'https://youtu.be/qJQ9wfdoMKg'; |
| 69 |
} |
| 70 |
|
| 71 |
public function get_query() { |
| 72 |
return $this->_query; |
| 73 |
} |
| 74 |
protected function register_controls() { |
| 75 |
|
| 76 |
$this->start_controls_section( |
| 77 |
'section_woocommerce_layout', |
| 78 |
[ |
| 79 |
'label' => esc_html__('Layout', 'ultimate-store-kit'), |
| 80 |
] |
| 81 |
); |
| 82 |
$this->add_responsive_control( |
| 83 |
'items_gap', |
| 84 |
[ |
| 85 |
'label' => esc_html__('Items Gap', 'ultimate-store-kit'), |
| 86 |
'type' => Controls_Manager::SLIDER, |
| 87 |
'selectors' => [ |
| 88 |
'{{WRAPPER}} .ultimate-store-kit .usk-list-wrap' => 'grid-gap: {{SIZE}}px;', |
| 89 |
], |
| 90 |
] |
| 91 |
); |
| 92 |
$this->add_control( |
| 93 |
'title_tags', |
| 94 |
[ |
| 95 |
'label' => esc_html__('Title HTML Tag', 'ultimate-store-kit'), |
| 96 |
'type' => Controls_Manager::SELECT, |
| 97 |
'default' => 'h3', |
| 98 |
'options' => ultimate_store_kit_title_tags(), |
| 99 |
] |
| 100 |
); |
| 101 |
$this->add_group_control( |
| 102 |
Group_Control_Image_Size::get_type(), |
| 103 |
[ |
| 104 |
'name' => 'image', |
| 105 |
'label' => esc_html__('Image Size', 'ultimate-store-kit'), |
| 106 |
'exclude' => ['custom'], |
| 107 |
'default' => 'full', |
| 108 |
] |
| 109 |
); |
| 110 |
|
| 111 |
$this->end_controls_section(); |
| 112 |
$this->start_controls_section( |
| 113 |
'section_post_query_builder', |
| 114 |
[ |
| 115 |
'label' => __('Query', 'ultimate-store-kit'), |
| 116 |
'tab' => Controls_Manager::TAB_CONTENT, |
| 117 |
] |
| 118 |
); |
| 119 |
$this->register_query_builder_controls(); |
| 120 |
$this->register_controls_wc_additional(); |
| 121 |
$this->end_controls_section(); |
| 122 |
|
| 123 |
$this->start_controls_section( |
| 124 |
'section_woocommerce_additional', |
| 125 |
[ |
| 126 |
'label' => esc_html__('Additional', 'ultimate-store-kit'), |
| 127 |
] |
| 128 |
); |
| 129 |
$this->start_controls_tabs( |
| 130 |
'tabs_show_hide_content' |
| 131 |
); |
| 132 |
$this->start_controls_tab( |
| 133 |
'show_content_tab', |
| 134 |
[ |
| 135 |
'label' => esc_html__('Content', 'ultimate-store-kit'), |
| 136 |
] |
| 137 |
); |
| 138 |
$this->add_control( |
| 139 |
'show_image', |
| 140 |
[ |
| 141 |
'label' => esc_html__('Image', 'ultimate-store-kit'), |
| 142 |
'type' => Controls_Manager::SWITCHER, |
| 143 |
'return_value' => 'yes', |
| 144 |
'default' => 'yes', |
| 145 |
] |
| 146 |
); |
| 147 |
$this->add_control( |
| 148 |
'show_title', |
| 149 |
[ |
| 150 |
'label' => esc_html__('Title', 'ultimate-store-kit'), |
| 151 |
'type' => Controls_Manager::SWITCHER, |
| 152 |
'return_value' => 'yes', |
| 153 |
'default' => 'yes', |
| 154 |
] |
| 155 |
); |
| 156 |
$this->add_control( |
| 157 |
'show_price', |
| 158 |
[ |
| 159 |
'label' => esc_html__('Price', 'ultimate-store-kit'), |
| 160 |
'type' => Controls_Manager::SWITCHER, |
| 161 |
'default' => 'yes', |
| 162 |
] |
| 163 |
); |
| 164 |
$this->add_control( |
| 165 |
'show_rating', |
| 166 |
[ |
| 167 |
'label' => esc_html__('Rating', 'ultimate-store-kit'), |
| 168 |
'type' => Controls_Manager::SWITCHER, |
| 169 |
'default' => 'yes', |
| 170 |
] |
| 171 |
); |
| 172 |
$this->add_control( |
| 173 |
'hide_customer_review', |
| 174 |
[ |
| 175 |
'label' => esc_html__('Hide Review Text', 'ultimate-store-kit'), |
| 176 |
'type' => Controls_Manager::SWITCHER, |
| 177 |
'label_on' => esc_html__('Yes', 'product-grid'), |
| 178 |
'label_off' => esc_html__('No', 'product-grid'), |
| 179 |
// 'return_value' => 'yes', |
| 180 |
'default' => 'yes', |
| 181 |
'condition' => [ |
| 182 |
'show_rating' => 'yes', |
| 183 |
], |
| 184 |
'selectors' => [ |
| 185 |
'{{WRAPPER}} .usk-recently-view-products .usk-rating .woocommerce-product-rating .woocommerce-review-link' => 'display:none', |
| 186 |
], |
| 187 |
] |
| 188 |
); |
| 189 |
|
| 190 |
$this->end_controls_tab(); |
| 191 |
$this->start_controls_tab( |
| 192 |
'show_badge_tab', |
| 193 |
[ |
| 194 |
'label' => esc_html__('Badge', 'ultimate-store-kit'), |
| 195 |
] |
| 196 |
); |
| 197 |
$this->add_control( |
| 198 |
'show_sale_badge', |
| 199 |
[ |
| 200 |
'label' => esc_html__('Sale', 'ultimate-store-kit'), |
| 201 |
'type' => Controls_Manager::SWITCHER, |
| 202 |
'default' => 'yes', |
| 203 |
] |
| 204 |
); |
| 205 |
$this->add_control( |
| 206 |
'show_discount_badge', |
| 207 |
[ |
| 208 |
'label' => esc_html__('Percentage', 'ultimate-store-kit'), |
| 209 |
'type' => Controls_Manager::SWITCHER, |
| 210 |
'default' => 'yes', |
| 211 |
] |
| 212 |
); |
| 213 |
$this->add_control( |
| 214 |
'show_stock_status', |
| 215 |
[ |
| 216 |
'label' => esc_html__('Stock Status', 'ultimate-store-kit'), |
| 217 |
'type' => Controls_Manager::SWITCHER, |
| 218 |
'default' => 'yes', |
| 219 |
] |
| 220 |
); |
| 221 |
$this->add_control( |
| 222 |
'show_trending_badge', |
| 223 |
[ |
| 224 |
'label' => esc_html__('Trending', 'ultimate-store-kit'), |
| 225 |
'type' => Controls_Manager::SWITCHER, |
| 226 |
'default' => 'yes', |
| 227 |
] |
| 228 |
); |
| 229 |
$this->add_control( |
| 230 |
'show_new_badge', |
| 231 |
[ |
| 232 |
'label' => esc_html__('New', 'ultimate-store-kit'), |
| 233 |
'type' => Controls_Manager::SWITCHER, |
| 234 |
'default' => 'yes', |
| 235 |
] |
| 236 |
); |
| 237 |
$this->add_control( |
| 238 |
'newness_days', |
| 239 |
[ |
| 240 |
'label' => esc_html__('Newness Days', 'ultimate-store-kit'), |
| 241 |
'type' => Controls_Manager::NUMBER, |
| 242 |
'default' => 90, |
| 243 |
'description' => esc_html__('Define newness day from product created date; default newness day is 30', 'ultimate-store-kit'), |
| 244 |
'condition' => [ |
| 245 |
'show_new_badge' => 'yes', |
| 246 |
], |
| 247 |
] |
| 248 |
); |
| 249 |
$this->end_controls_tab(); |
| 250 |
$this->end_controls_tabs(); |
| 251 |
|
| 252 |
// $this-> add_control( |
| 253 |
// 'heading_show_hide_badge', |
| 254 |
// [ |
| 255 |
// 'label' => esc_html__( 'Badge', 'ultimate-store-kit' ), |
| 256 |
// 'type' => Controls_Manager::HEADING, |
| 257 |
// 'separator' => 'before', |
| 258 |
// ] |
| 259 |
// ); |
| 260 |
|
| 261 |
$this->end_controls_section(); |
| 262 |
$this->start_controls_section( |
| 263 |
'section_style_item', |
| 264 |
[ |
| 265 |
'label' => esc_html__('Items', 'ultimate-store-kit'), |
| 266 |
'tab' => Controls_Manager::TAB_STYLE, |
| 267 |
] |
| 268 |
); |
| 269 |
$this->add_group_control( |
| 270 |
Group_Control_Background::get_type(), |
| 271 |
[ |
| 272 |
'name' => 'item_background', |
| 273 |
'label' => esc_html__('Background', 'ultimate-store-kit'), |
| 274 |
'types' => ['classic', 'gradient'], |
| 275 |
'selector' => '{{WRAPPER}} .ultimate-store-kit .usk-list-wrap .usk-item', |
| 276 |
] |
| 277 |
); |
| 278 |
$this->add_group_control( |
| 279 |
Group_Control_Border::get_type(), |
| 280 |
[ |
| 281 |
'name' => 'item_border', |
| 282 |
'label' => esc_html__('Border', 'ultimate-store-kit'), |
| 283 |
'selector' => '{{WRAPPER}} .ultimate-store-kit .usk-list-wrap .usk-item', |
| 284 |
'separator' => 'before', |
| 285 |
] |
| 286 |
); |
| 287 |
$this->add_control( |
| 288 |
'item_border_radius', |
| 289 |
[ |
| 290 |
'label' => esc_html__('Border Radius', 'ultimate-store-kit'), |
| 291 |
'type' => Controls_Manager::DIMENSIONS, |
| 292 |
'size_units' => ['px', '%', 'em'], |
| 293 |
'selectors' => [ |
| 294 |
'{{WRAPPER}} .ultimate-store-kit .usk-list-wrap .usk-item' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 295 |
], |
| 296 |
] |
| 297 |
); |
| 298 |
$this->add_control( |
| 299 |
'item_padding', |
| 300 |
[ |
| 301 |
'label' => esc_html__('Padding', 'ultimate-store-kit'), |
| 302 |
'type' => Controls_Manager::DIMENSIONS, |
| 303 |
'size_units' => ['px', '%', 'em'], |
| 304 |
'selectors' => [ |
| 305 |
'{{WRAPPER}} .ultimate-store-kit .usk-list-wrap .usk-item' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 306 |
], |
| 307 |
] |
| 308 |
); |
| 309 |
|
| 310 |
$this->add_group_control( |
| 311 |
Group_Control_Box_Shadow::get_type(), |
| 312 |
[ |
| 313 |
'name' => 'item_shadow', |
| 314 |
'selector' => '{{WRAPPER}} .ultimate-store-kit .usk-list-wrap .usk-item', |
| 315 |
] |
| 316 |
); |
| 317 |
$this->end_controls_section(); |
| 318 |
|
| 319 |
$this->start_controls_section( |
| 320 |
'section_style_image', |
| 321 |
[ |
| 322 |
'label' => esc_html__('Image', 'ultimate-store-kit'), |
| 323 |
'tab' => Controls_Manager::TAB_STYLE, |
| 324 |
] |
| 325 |
); |
| 326 |
|
| 327 |
$this->add_group_control( |
| 328 |
Group_Control_Border::get_type(), |
| 329 |
[ |
| 330 |
'name' => 'image_border', |
| 331 |
'label' => esc_html__('Image Border', 'ultimate-store-kit'), |
| 332 |
'selector' => '{{WRAPPER}} .ultimate-store-kit .usk-list-wrap .usk-item .usk-item-box .usk-image-wrap', |
| 333 |
] |
| 334 |
); |
| 335 |
|
| 336 |
$this->add_responsive_control( |
| 337 |
'image_border_radius', |
| 338 |
[ |
| 339 |
'label' => esc_html__('Border Radius', 'ultimate-store-kit'), |
| 340 |
'type' => Controls_Manager::DIMENSIONS, |
| 341 |
'size_units' => ['px', '%'], |
| 342 |
'selectors' => [ |
| 343 |
'{{WRAPPER}} .ultimate-store-kit .usk-list-wrap .usk-item .usk-item-box .usk-image-wrap' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 344 |
], |
| 345 |
] |
| 346 |
); |
| 347 |
|
| 348 |
$this->add_group_control( |
| 349 |
Group_Control_Box_Shadow::get_type(), |
| 350 |
[ |
| 351 |
'name' => 'image_shadow', |
| 352 |
'exclude' => [ |
| 353 |
'shadow_position', |
| 354 |
], |
| 355 |
'selector' => '{{WRAPPER}} .ultimate-store-kit .usk-list-wrap .usk-item .usk-item-box .usk-image-wrap', |
| 356 |
] |
| 357 |
); |
| 358 |
|
| 359 |
$this->add_responsive_control( |
| 360 |
'item_image_size', |
| 361 |
[ |
| 362 |
'label' => esc_html__('Image Size', 'ultimate-store-kit'), |
| 363 |
'type' => Controls_Manager::SLIDER, |
| 364 |
'size_units' => ['px', '%'], |
| 365 |
'range' => [ |
| 366 |
'px' => [ |
| 367 |
'min' => 50, |
| 368 |
'max' => 500, |
| 369 |
], |
| 370 |
'%' => [ |
| 371 |
'min' => 0, |
| 372 |
'max' => 100, |
| 373 |
], |
| 374 |
], |
| 375 |
'selectors' => [ |
| 376 |
'{{WRAPPER}} .ultimate-store-kit .usk-list-wrap .usk-item .usk-item-box .usk-image-wrap' => 'width: {{SIZE}}{{UNIT}};', |
| 377 |
], |
| 378 |
] |
| 379 |
); |
| 380 |
|
| 381 |
$this->end_controls_section(); |
| 382 |
$this->register_global_controls_title(); |
| 383 |
$this->register_global_controls_price(); |
| 384 |
$this->register_global_controls_rating(); |
| 385 |
$this->register_global_controls_badge(); |
| 386 |
} |
| 387 |
|
| 388 |
public function render_header() { |
| 389 |
?> |
| 390 |
<div class="ultimate-store-kit"> |
| 391 |
<div class="usk-product-list"> |
| 392 |
<div class="usk-list-wrap usk-flex usk-flex-column"> |
| 393 |
<?php |
| 394 |
} |
| 395 |
public function render_footer() { |
| 396 |
?> |
| 397 |
</div> |
| 398 |
</div> |
| 399 |
</div> |
| 400 |
<?php |
| 401 |
} |
| 402 |
public function render_image() { |
| 403 |
$settings = $this->get_settings_for_display(); |
| 404 |
global $product; |
| 405 |
?> |
| 406 |
<div class="usk-image-wrap usk-flex"> |
| 407 |
<a href="<?php echo esc_url($product->get_permalink()); ?>"> |
| 408 |
<img class="img image-default" src="<?php echo esc_url(wp_get_attachment_image_url(get_post_thumbnail_id(), $settings['image_size'])); ?>" alt="<?php echo esc_html(get_the_title()); ?>"> |
| 409 |
</a> |
| 410 |
</div> |
| 411 |
<?php |
| 412 |
} |
| 413 |
public function print_price_output($output) { |
| 414 |
$tags = [ |
| 415 |
'del' => ['aria-hidden' => []], |
| 416 |
'span' => ['class' => []], |
| 417 |
'bdi' => [], |
| 418 |
'ins' => [], |
| 419 |
]; |
| 420 |
|
| 421 |
if (isset($output)) { |
| 422 |
echo wp_kses($output, $tags); |
| 423 |
} |
| 424 |
} |
| 425 |
public function render_loop_item() { |
| 426 |
$settings = $this->get_settings_for_display(); |
| 427 |
$this->query_product(); |
| 428 |
$wp_query = $this->get_query(); |
| 429 |
if ($wp_query) { |
| 430 |
while ($wp_query->have_posts()) : $wp_query->the_post(); |
| 431 |
global $product; |
| 432 |
$average = $product->get_average_rating(); |
| 433 |
$rating_count = $product->get_rating_count(); |
| 434 |
?> |
| 435 |
<div class="usk-item"> |
| 436 |
<div class="usk-item-box usk-flex usk-flex-middle"> |
| 437 |
<?php |
| 438 |
if ($settings['show_image']) : |
| 439 |
$this->render_image(); |
| 440 |
endif; |
| 441 |
?> |
| 442 |
<div class="usk-content usk-flex usk-flex-column usk-flex-center"> |
| 443 |
<?php |
| 444 |
if ($settings['show_title']) : |
| 445 |
printf('<a href="%2$s" class="usk-title"><%1$s class="title">%3$s</%1$s></a>', esc_attr($settings['title_tags']), esc_url($product->get_permalink()), esc_html($product->get_title())); |
| 446 |
endif; ?> |
| 447 |
<?php if ($settings['show_rating']) : ?> |
| 448 |
<div class="usk-rating"> |
| 449 |
<?php echo wp_kses_post($this->register_global_template_wc_rating($average, $rating_count)); ?> |
| 450 |
</div> |
| 451 |
<?php endif; ?> |
| 452 |
<?php if ('yes' == $settings['show_price']) : ?> |
| 453 |
<div class="usk-price usk-flex usk-flex-middle"> |
| 454 |
<?php $this->print_price_output($product->get_price_html()); ?> |
| 455 |
</div> |
| 456 |
<?php endif; ?> |
| 457 |
</div> |
| 458 |
<div class="usk-badge-label-wrapper"> |
| 459 |
<div class="usk-badge-label-content usk-flex"> |
| 460 |
<?php $this->register_global_template_badge_label(); ?> |
| 461 |
</div> |
| 462 |
</div> |
| 463 |
</div> |
| 464 |
</div> |
| 465 |
<?php endwhile; ?> |
| 466 |
<?php |
| 467 |
wp_reset_postdata(); |
| 468 |
} else { |
| 469 |
echo '<div class="usk-alert-warning" usk-alert>' . esc_html__('Ops! There no product to display.', 'ultimate-store-kit') . '</div>'; |
| 470 |
} |
| 471 |
} |
| 472 |
|
| 473 |
public function render() { |
| 474 |
$this->render_header(); |
| 475 |
$this->render_loop_item(); |
| 476 |
$this->render_footer(); |
| 477 |
} |
| 478 |
|
| 479 |
public function query_product() { |
| 480 |
$default = $this->getGroupControlQueryArgs(); |
| 481 |
$default['post_type'] = 'product'; |
| 482 |
unset($default['p']); |
| 483 |
$this->_query = new WP_Query($default); |
| 484 |
} |
| 485 |
} |
| 486 |
|