control
2 weeks ago
template-library
2 weeks ago
widgets
2 weeks ago
ControlsWidgets.php
2 weeks ago
EditorCondition.php
2 weeks ago
EditorScripts.php
1 year ago
Integration.php
1 year ago
RegisterWidgets.php
1 year ago
ShopPressStyler.php
2 weeks ago
ShopPressWidgets.php
2 weeks ago
ControlsWidgets.php
646 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Widgets Controls Base. |
| 4 | * |
| 5 | * @package ShopPress |
| 6 | */ |
| 7 | |
| 8 | namespace ShopPress\Elementor; |
| 9 | |
| 10 | defined( 'ABSPATH' ) || exit; |
| 11 | |
| 12 | use Elementor\Controls_Manager; |
| 13 | use ShopPress\Templates; |
| 14 | |
| 15 | class ControlsWidgets { |
| 16 | /** |
| 17 | * Instance of this class. |
| 18 | * |
| 19 | * @since 1.0.0 |
| 20 | */ |
| 21 | public static $instance; |
| 22 | |
| 23 | /** |
| 24 | * Provides access to a single instance of a module using the singleton pattern. |
| 25 | * |
| 26 | * @since 1.0.0 |
| 27 | * |
| 28 | * @return object |
| 29 | */ |
| 30 | public static function instance() { |
| 31 | if ( self::$instance === null ) { |
| 32 | self::$instance = new self(); |
| 33 | } |
| 34 | return self::$instance; |
| 35 | } |
| 36 | |
| 37 | public static function select( $id, $label, $options, $default, &$class ) { |
| 38 | |
| 39 | $class->add_control( |
| 40 | $id, |
| 41 | array( |
| 42 | 'type' => Controls_Manager::SELECT, |
| 43 | 'label' => $label, |
| 44 | 'default' => $default, |
| 45 | 'options' => $options['options'] ?? array(), |
| 46 | 'condition' => $options['condition'] ?? '', |
| 47 | ) |
| 48 | ); |
| 49 | } |
| 50 | |
| 51 | public static function select2( $id, $label, $options, $default, &$class, $multiple = false, $description = '', $other_options = array() ) { |
| 52 | |
| 53 | $class->add_control( |
| 54 | $id, |
| 55 | array( |
| 56 | 'type' => Controls_Manager::SELECT2, |
| 57 | 'label' => $label, |
| 58 | 'default' => $default, |
| 59 | 'options' => $options['options'] ?? array(), |
| 60 | 'multiple' => $multiple, |
| 61 | 'description' => $description, |
| 62 | 'condition' => $options['condition'] ?? '', |
| 63 | ) |
| 64 | ); |
| 65 | } |
| 66 | |
| 67 | public static function number( $id, $label, $options, $default, &$class ) { |
| 68 | |
| 69 | $class->add_control( |
| 70 | $id, |
| 71 | array( |
| 72 | 'type' => Controls_Manager::NUMBER, |
| 73 | 'label' => $label, |
| 74 | 'default' => $default, |
| 75 | 'min' => $options['min'] ?? '', |
| 76 | 'max' => $options['max'] ?? '', |
| 77 | 'step' => $options['step'] ?? '', |
| 78 | 'condition' => $options['condition'] ?? '', |
| 79 | ) |
| 80 | ); |
| 81 | } |
| 82 | |
| 83 | public static function text( $id, $label, $options, $default, &$class ) { |
| 84 | |
| 85 | $class->add_control( |
| 86 | $id, |
| 87 | array( |
| 88 | 'type' => Controls_Manager::TEXT, |
| 89 | 'label' => $label, |
| 90 | 'default' => $default, |
| 91 | 'placeholder' => $options['placeholder'] ?? '', |
| 92 | 'condition' => $options['condition'] ?? '', |
| 93 | ) |
| 94 | ); |
| 95 | } |
| 96 | |
| 97 | public static function switcher( $id, $label, $options, $default, &$class ) { |
| 98 | |
| 99 | $class->add_control( |
| 100 | $id, |
| 101 | array( |
| 102 | 'type' => Controls_Manager::SWITCHER, |
| 103 | 'label' => $label, |
| 104 | 'default' => $default, |
| 105 | 'label_on' => $options['label_on'] ?? __( 'Show', 'shop-press' ), |
| 106 | 'label_off' => $options['label_off'] ?? __( 'Hide', 'shop-press' ), |
| 107 | 'return_value' => $options['return_value'] ?? 'yes', |
| 108 | 'selectors' => $options['selectors'] ?? '', |
| 109 | 'condition' => $options['condition'] ?? '', |
| 110 | ) |
| 111 | ); |
| 112 | } |
| 113 | |
| 114 | public static function icons( $id, $label, $options, $default, &$class ) { |
| 115 | |
| 116 | $class->add_control( |
| 117 | $id, |
| 118 | array( |
| 119 | 'type' => Controls_Manager::ICONS, |
| 120 | 'label' => $label, |
| 121 | 'default' => $default, |
| 122 | 'condition' => $options['condition'] ?? '', |
| 123 | ) |
| 124 | ); |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Add Query Controls |
| 129 | * |
| 130 | * @param ShopPressWidgets $class |
| 131 | * |
| 132 | * @since 1.0.0 |
| 133 | * |
| 134 | * @return void |
| 135 | */ |
| 136 | public static function add_query_controls( &$class ) { |
| 137 | $templates = Templates\Utils::get_loop_builder_templates(); |
| 138 | $product_tags = Templates\Utils::get_terms_for_select( 'product_tag' ); |
| 139 | $product_cats = Templates\Utils::get_terms_for_select( 'product_cat' ); |
| 140 | $product_brands = sp_is_module_active( 'brands' ) ? Templates\Utils::get_terms_for_select( 'product_brand' ) : array(); |
| 141 | |
| 142 | if ( 'sp-product-collection' === $class->get_name() ) { |
| 143 | |
| 144 | $collections = array( |
| 145 | 'sp-recent-products' => __( 'Recent Products', 'shop-press' ), |
| 146 | 'sp-featured-products' => __( 'Featured Products', 'shop-press' ), |
| 147 | 'sp-best-selling-products' => __( 'Best Selling Products', 'shop-press' ), |
| 148 | 'sp-top-rated-products' => __( 'Top Rated Products', 'shop-press' ), |
| 149 | 'sp-sales-products' => __( 'Sale Products', 'shop-press' ), |
| 150 | ); |
| 151 | $collections = apply_filters( 'shoppress/product-loop/collections', $collections, $class ); |
| 152 | |
| 153 | self::select2( |
| 154 | 'product_collection', |
| 155 | __( 'Product Collection', 'shop-press' ), |
| 156 | array( |
| 157 | 'options' => $collections, |
| 158 | ), |
| 159 | 'sp-recent-products', |
| 160 | $class, |
| 161 | false |
| 162 | ); |
| 163 | } |
| 164 | |
| 165 | $product_loop_status = sp_is_template_active( 'products_loop' ); |
| 166 | static::select2( |
| 167 | 'template_id', |
| 168 | __( 'Template', 'shop-press' ), |
| 169 | array( |
| 170 | 'options' => $templates, |
| 171 | ), |
| 172 | 0, |
| 173 | $class, |
| 174 | false, |
| 175 | /* translators: %s: link to products loop component */ |
| 176 | ! $product_loop_status ? sprintf( esc_html__( 'To display the custom template in the front, you need to activate the %s component', 'shop-press' ), '<a href="' . esc_url( admin_url( 'admin.php?page=shoppress&sub=templates' ) ) . '" target="_blank">' . esc_html__( 'products loop', 'shop-press' ) . '</a>' ) : '' |
| 177 | ); |
| 178 | |
| 179 | static::number( |
| 180 | 'limit', |
| 181 | __( 'Limit', 'shop-press' ), |
| 182 | array( |
| 183 | 'min' => 1, |
| 184 | 'max' => 200, |
| 185 | 'step' => 1, |
| 186 | ), |
| 187 | '', |
| 188 | $class |
| 189 | ); |
| 190 | |
| 191 | static::number( |
| 192 | 'columns', |
| 193 | __( 'Columns', 'shop-press' ), |
| 194 | array(), |
| 195 | '', |
| 196 | $class |
| 197 | ); |
| 198 | |
| 199 | // static::switcher( |
| 200 | // 'paginate', |
| 201 | // __( 'Pagination', 'shop-press' ), |
| 202 | // array(), |
| 203 | // '', |
| 204 | // $class, |
| 205 | // array( |
| 206 | // 'condition' => array( |
| 207 | // 'display_as_slider!' => 'yes', |
| 208 | // ), |
| 209 | // ) |
| 210 | // ); |
| 211 | |
| 212 | static::switcher( |
| 213 | 'infinite_scroll', |
| 214 | __( 'Infinite scroll', 'shop-press' ), |
| 215 | array( |
| 216 | 'selectors' => array( |
| 217 | '{{WRAPPER}} .woocommerce-pagination' => 'display:none;', |
| 218 | ), |
| 219 | 'condition' => array( |
| 220 | 'paginate' => 'yes', |
| 221 | 'load_more_button!' => 'yes', |
| 222 | ), |
| 223 | ), |
| 224 | '', |
| 225 | $class |
| 226 | ); |
| 227 | |
| 228 | static::switcher( |
| 229 | 'load_more_button', |
| 230 | __( 'Load More Button', 'shop-press' ), |
| 231 | array( |
| 232 | 'selectors' => array( |
| 233 | '{{WRAPPER}} .woocommerce-pagination' => 'display:none;', |
| 234 | '{{WRAPPER}} .sp-loadmore-wrapper' => 'display:block;', |
| 235 | ), |
| 236 | 'condition' => array( |
| 237 | 'paginate' => 'yes', |
| 238 | 'infinite_scroll!' => 'yes', |
| 239 | ), |
| 240 | ), |
| 241 | '', |
| 242 | $class |
| 243 | ); |
| 244 | |
| 245 | static::text( |
| 246 | 'loadmore_text', |
| 247 | __( 'Load More Button Text', 'shop-press' ), |
| 248 | array( |
| 249 | 'condition' => array( |
| 250 | 'paginate' => 'yes', |
| 251 | 'load_more_button' => 'yes', |
| 252 | ), |
| 253 | ), |
| 254 | __( 'Load More', 'shop-press' ), |
| 255 | $class |
| 256 | ); |
| 257 | |
| 258 | static::switcher( |
| 259 | 'result_count', |
| 260 | __( 'Result Count', 'shop-press' ), |
| 261 | array( |
| 262 | 'condition' => array( |
| 263 | 'paginate' => 'yes', |
| 264 | ), |
| 265 | ), |
| 266 | '', |
| 267 | $class |
| 268 | ); |
| 269 | |
| 270 | static::switcher( |
| 271 | 'catalog_ordering', |
| 272 | __( 'Order By Form', 'shop-press' ), |
| 273 | array( |
| 274 | 'condition' => array( |
| 275 | 'paginate' => 'yes', |
| 276 | ), |
| 277 | ), |
| 278 | '', |
| 279 | $class |
| 280 | ); |
| 281 | |
| 282 | static::select( |
| 283 | 'orderby', |
| 284 | __( 'Order By', 'shop-press' ), |
| 285 | array( |
| 286 | 'options' => array( |
| 287 | 'id' => __( 'ID', 'shop-press' ), |
| 288 | 'title' => __( 'Title', 'shop-press' ), |
| 289 | 'date' => __( 'Date', 'shop-press' ), |
| 290 | 'rand' => __( 'Random', 'shop-press' ), |
| 291 | 'price' => __( 'Price', 'shop-press' ), |
| 292 | 'popularity' => __( 'Popularity', 'shop-press' ), |
| 293 | 'rating' => __( 'Rating', 'shop-press' ), |
| 294 | ), |
| 295 | ), |
| 296 | '', |
| 297 | $class |
| 298 | ); |
| 299 | |
| 300 | static::select( |
| 301 | 'order', |
| 302 | __( 'Order', 'shop-press' ), |
| 303 | array( |
| 304 | 'options' => array( |
| 305 | 'ASC' => __( 'ASC', 'shop-press' ), |
| 306 | 'DESC' => __( 'DESC', 'shop-press' ), |
| 307 | ), |
| 308 | ), |
| 309 | '', |
| 310 | $class |
| 311 | ); |
| 312 | |
| 313 | static::text( |
| 314 | 'ids', |
| 315 | __( 'Product IDs', 'shop-press' ), |
| 316 | array( |
| 317 | 'placeholder' => __( 'ex: 1,2,3,4', 'shop-press' ), |
| 318 | 'condition' => array( |
| 319 | 'product_collection' => array( |
| 320 | 'sp-products', |
| 321 | 'sp-recent-products', |
| 322 | 'sp-featured-products', |
| 323 | 'sp-best-selling-products', |
| 324 | 'sp-top-rated-products', |
| 325 | 'sp-sales-products', |
| 326 | ), |
| 327 | ), |
| 328 | ), |
| 329 | '', |
| 330 | $class |
| 331 | ); |
| 332 | |
| 333 | static::text( |
| 334 | 'skus', |
| 335 | __( 'SKUs', 'shop-press' ), |
| 336 | array( |
| 337 | 'placeholder' => __( 'ex: 1,2,3,4', 'shop-press' ), |
| 338 | 'condition' => array( |
| 339 | 'product_collection' => array( |
| 340 | 'sp-products', |
| 341 | 'sp-recent-products', |
| 342 | 'sp-featured-products', |
| 343 | 'sp-best-selling-products', |
| 344 | 'sp-top-rated-products', |
| 345 | 'sp-sales-products', |
| 346 | ), |
| 347 | ), |
| 348 | ), |
| 349 | '', |
| 350 | $class |
| 351 | ); |
| 352 | |
| 353 | static::select( |
| 354 | 'cat_operator', |
| 355 | __( 'Category Operator', 'shop-press' ), |
| 356 | array( |
| 357 | 'options' => array( |
| 358 | 'IN' => __( 'Include', 'shop-press' ), |
| 359 | 'NOT IN' => __( 'Exclude', 'shop-press' ), |
| 360 | ), |
| 361 | 'condition' => array( |
| 362 | 'product_collection' => array( |
| 363 | 'sp-products', |
| 364 | 'sp-recent-products', |
| 365 | 'sp-featured-products', |
| 366 | 'sp-best-selling-products', |
| 367 | 'sp-top-rated-products', |
| 368 | 'sp-sales-products', |
| 369 | ), |
| 370 | ), |
| 371 | ), |
| 372 | 'IN', |
| 373 | $class |
| 374 | ); |
| 375 | |
| 376 | static::select2( |
| 377 | 'category', |
| 378 | __( 'Categories', 'shop-press' ), |
| 379 | array( |
| 380 | 'options' => $product_cats, |
| 381 | 'condition' => array( |
| 382 | 'product_collection' => array( |
| 383 | 'sp-products', |
| 384 | 'sp-recent-products', |
| 385 | 'sp-featured-products', |
| 386 | 'sp-best-selling-products', |
| 387 | 'sp-top-rated-products', |
| 388 | 'sp-sales-products', |
| 389 | ), |
| 390 | ), |
| 391 | ), |
| 392 | array(), |
| 393 | $class, |
| 394 | true |
| 395 | ); |
| 396 | |
| 397 | static::select( |
| 398 | 'tag_operator', |
| 399 | __( 'Tag Operator', 'shop-press' ), |
| 400 | array( |
| 401 | 'options' => array( |
| 402 | 'IN' => __( 'Include', 'shop-press' ), |
| 403 | 'NOT IN' => __( 'Exclude', 'shop-press' ), |
| 404 | ), |
| 405 | 'condition' => array( |
| 406 | 'product_collection' => array( |
| 407 | 'sp-products', |
| 408 | 'sp-recent-products', |
| 409 | 'sp-featured-products', |
| 410 | 'sp-best-selling-products', |
| 411 | 'sp-top-rated-products', |
| 412 | 'sp-sales-products', |
| 413 | ), |
| 414 | ), |
| 415 | ), |
| 416 | 'IN', |
| 417 | $class |
| 418 | ); |
| 419 | |
| 420 | static::select2( |
| 421 | 'tag', |
| 422 | __( 'Tags', 'shop-press' ), |
| 423 | array( |
| 424 | 'options' => $product_tags, |
| 425 | 'condition' => array( |
| 426 | 'product_collection' => array( |
| 427 | 'sp-products', |
| 428 | 'sp-recent-products', |
| 429 | 'sp-featured-products', |
| 430 | 'sp-best-selling-products', |
| 431 | 'sp-top-rated-products', |
| 432 | 'sp-sales-products', |
| 433 | ), |
| 434 | ), |
| 435 | ), |
| 436 | array(), |
| 437 | $class, |
| 438 | true |
| 439 | ); |
| 440 | |
| 441 | if ( sp_is_module_active( 'brands' ) ) { |
| 442 | |
| 443 | static::select( |
| 444 | 'brand_operator', |
| 445 | __( 'Brand Operator', 'shop-press' ), |
| 446 | array( |
| 447 | 'options' => array( |
| 448 | 'IN' => __( 'Include', 'shop-press' ), |
| 449 | 'NOT IN' => __( 'Exclude', 'shop-press' ), |
| 450 | ), |
| 451 | 'condition' => array( |
| 452 | 'product_collection' => array( |
| 453 | 'sp-products', |
| 454 | 'sp-recent-products', |
| 455 | 'sp-featured-products', |
| 456 | 'sp-best-selling-products', |
| 457 | 'sp-top-rated-products', |
| 458 | 'sp-sales-products', |
| 459 | ), |
| 460 | ), |
| 461 | ), |
| 462 | 'IN', |
| 463 | $class |
| 464 | ); |
| 465 | |
| 466 | static::select2( |
| 467 | 'brand', |
| 468 | __( 'Brands', 'shop-press' ), |
| 469 | array( |
| 470 | 'options' => $product_brands, |
| 471 | 'condition' => array( |
| 472 | 'product_collection' => array( |
| 473 | 'sp-products', |
| 474 | 'sp-recent-products', |
| 475 | 'sp-featured-products', |
| 476 | 'sp-best-selling-products', |
| 477 | 'sp-top-rated-products', |
| 478 | 'sp-sales-products', |
| 479 | ), |
| 480 | ), |
| 481 | ), |
| 482 | array(), |
| 483 | $class, |
| 484 | true |
| 485 | ); |
| 486 | } |
| 487 | |
| 488 | if ( 'sp-related-products' === $class->get_name() ) { |
| 489 | |
| 490 | static::switcher( |
| 491 | 'custom_heading', |
| 492 | __( 'Custom Heading', 'shop-press' ), |
| 493 | array( |
| 494 | 'return_value' => 'true', |
| 495 | ), |
| 496 | '', |
| 497 | $class, |
| 498 | ); |
| 499 | |
| 500 | static::text( |
| 501 | 'products_heading', |
| 502 | __( 'Heading', 'shop-press' ), |
| 503 | array( |
| 504 | 'condition' => array( |
| 505 | 'custom_heading' => 'true', |
| 506 | ), |
| 507 | ), |
| 508 | '', |
| 509 | $class |
| 510 | ); |
| 511 | |
| 512 | static::select( |
| 513 | 'heading_tag', |
| 514 | __( 'Heading HTML Tag', 'shop-press' ), |
| 515 | array( |
| 516 | 'options' => array( |
| 517 | 'h1' => __( 'h1', 'shop-press' ), |
| 518 | 'h2' => __( 'h2', 'shop-press' ), |
| 519 | 'h3' => __( 'h3', 'shop-press' ), |
| 520 | 'h4' => __( 'h4', 'shop-press' ), |
| 521 | 'h5' => __( 'h5', 'shop-press' ), |
| 522 | 'h6' => __( 'h6', 'shop-press' ), |
| 523 | 'div' => __( 'div', 'shop-press' ), |
| 524 | 'span' => __( 'span', 'shop-press' ), |
| 525 | ), |
| 526 | 'condition' => array( |
| 527 | 'custom_heading' => 'true', |
| 528 | ), |
| 529 | ), |
| 530 | 'h4', |
| 531 | $class |
| 532 | ); |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | /** |
| 537 | * Add Filter Controls |
| 538 | * |
| 539 | * @param ShopPressWidgets $class |
| 540 | * |
| 541 | * @since 1.0.0 |
| 542 | * |
| 543 | * @return void |
| 544 | */ |
| 545 | public static function add_filter_controls( &$class, $product_attributes = array() ) { |
| 546 | |
| 547 | $filter_by = apply_filters( |
| 548 | 'shoppress_filter_by_options', |
| 549 | array( |
| 550 | 'layered_nav_filters' => __( 'Active Filters', 'shop-press' ), |
| 551 | 'layered_nav' => __( 'Filter by Attribute', 'shop-press' ), |
| 552 | 'rating_filter' => __( 'Filter by Rating', 'shop-press' ), |
| 553 | 'price_filter' => __( 'Filter by Price', 'shop-press' ), |
| 554 | // 'stock_filter' => __( 'Filter by Stock', 'shop-press' ), |
| 555 | ) |
| 556 | ); |
| 557 | |
| 558 | static::select( |
| 559 | 'filter_repeater_select', |
| 560 | __( 'Template', 'shop-press' ), |
| 561 | array( |
| 562 | 'options' => $filter_by, |
| 563 | ), |
| 564 | 'cats', |
| 565 | $class |
| 566 | ); |
| 567 | |
| 568 | static::text( |
| 569 | 'layered_nav_title', |
| 570 | __( 'Title', 'shop-press' ), |
| 571 | array( |
| 572 | 'condition' => array( |
| 573 | 'filter_repeater_select' => 'layered_nav', |
| 574 | ), |
| 575 | ), |
| 576 | 'Attribute', |
| 577 | $class |
| 578 | ); |
| 579 | |
| 580 | static::select( |
| 581 | 'attribute', |
| 582 | __( 'Attribute', 'shop-press' ), |
| 583 | array( |
| 584 | 'options' => $product_attributes, |
| 585 | 'condition' => array( |
| 586 | 'filter_repeater_select' => 'layered_nav', |
| 587 | ), |
| 588 | ), |
| 589 | '0', |
| 590 | $class |
| 591 | ); |
| 592 | |
| 593 | static::select( |
| 594 | 'attribute_display_type', |
| 595 | __( 'Display type', 'shop-press' ), |
| 596 | array( |
| 597 | 'options' => array( |
| 598 | 'dropdown' => __( 'Dropdown', 'shop-press' ), |
| 599 | 'list' => __( 'List', 'shop-press' ), |
| 600 | ), |
| 601 | 'condition' => array( |
| 602 | 'filter_repeater_select' => 'layered_nav', |
| 603 | ), |
| 604 | ), |
| 605 | 'list', |
| 606 | $class |
| 607 | ); |
| 608 | |
| 609 | static::text( |
| 610 | 'price_filter_title', |
| 611 | __( 'Title', 'shop-press' ), |
| 612 | array( |
| 613 | 'condition' => array( |
| 614 | 'filter_repeater_select' => 'price_filter', |
| 615 | ), |
| 616 | ), |
| 617 | 'Price', |
| 618 | $class |
| 619 | ); |
| 620 | |
| 621 | static::text( |
| 622 | 'rating_filter_title', |
| 623 | __( 'Title', 'shop-press' ), |
| 624 | array( |
| 625 | 'condition' => array( |
| 626 | 'filter_repeater_select' => 'rating_filter', |
| 627 | ), |
| 628 | ), |
| 629 | 'Rating', |
| 630 | $class |
| 631 | ); |
| 632 | |
| 633 | static::text( |
| 634 | 'layered_nav_filters_title', |
| 635 | __( 'Title', 'shop-press' ), |
| 636 | array( |
| 637 | 'condition' => array( |
| 638 | 'filter_repeater_select' => 'layered_nav_filters', |
| 639 | ), |
| 640 | ), |
| 641 | 'Active Filters', |
| 642 | $class |
| 643 | ); |
| 644 | } |
| 645 | } |
| 646 |