PluginProbe
Depicter — Popup & Slider Builder / 1.5.2
Depicter — Popup & Slider Builder v1.5.2
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / DataSources / HandPickedProducts.php

HandPickedProducts.php in Depicter — Popup & Slider Builder 1.5.2, at app/src/DataSources/HandPickedProducts.php

74 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Depicter\DataSources;
3
4 use Averta\Core\Utility\Data;
5
6 class HandPickedProducts extends Products {
7
8 /**
9 * Source name
10 *
11 * @var string
12 */
13 protected $type = 'wooHandpicks';
14
15 /**
16 * Input params to filter source result
17 *
18 * @var array
19 */
20 protected $params = [
21 'postType' => 'product',
22 'excerptLength' => 100,
23 'linkSlides' => true,
24 'orderBy' => 'post__in',
25 'order' => 'DESC',
26 'imageSource' => 'featured',
27 'includedIds' => '',
28 'excludeNonThumbnail' => true,
29 'inStockOnly' => true,
30 ];
31
32 /**
33 * Retrieves the list of records based on query params
34 *
35 * @param $args
36 *
37 * @return \WP_Query
38 */
39 protected function getRecords( $args ){
40
41 $queryArgs = [
42 'post_type' => $args['postType'],
43 'order' => $args['order'],
44 'orderby' => $args['orderBy'],
45 'post__in' => $args['includedIds'],
46 'tax_query' => [],
47 'meta_query' => []
48 ];
49
50 if( Data::isTrue( $args['excludeNonThumbnail'] ) ){
51 $queryArgs['meta_query'][] = [
52 'key' => '_thumbnail_id',
53 'compare' => 'EXISTS'
54 ];
55 }
56
57 if ( !empty( $args['excerptLength'] ) ) {
58 add_filter( 'excerpt_length', function () use ($args) {
59 return $args['excerptLength'];
60 });
61 }
62
63 if ( Data::isTrue( $args['inStockOnly'] ) ) {
64 $queryArgs['meta_query'][] = [
65 'key' => '_stock_status',
66 'value' => 'instock',
67 'compare' => '=',
68 ];
69 }
70
71 return new \WP_Query( $queryArgs );
72 }
73 }
74