PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution with eCommerce Templates & Woo Widgets / 0.1.4-beta
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution with eCommerce Templates & Woo Widgets v0.1.4-beta
4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.1 3.0.0 3.1.0 3.1.1 4.0.0 4.0.1 4.1.0 4.1.1 4.2.0 4.2.1 4.3.0 4.3.1 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.6.8 4.6.9 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.8.9 trunk 0.1.2-beta 0.1.3-beta 0.1.4-beta 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.5.0 1.5.1 1.6.0 1.6.1 1.7.0 1.8.0 1.8.1 1.9.0
shopengine / widgets / products.php
shopengine / widgets Last commit date
account-address 5 years ago account-dashboard 5 years ago account-details 5 years ago account-downloads 5 years ago account-form-login 5 years ago account-form-register 5 years ago account-logout 5 years ago account-navigation 5 years ago account-order-details 5 years ago account-orders 5 years ago add-to-cart 5 years ago additional-information 5 years ago advanced-search 5 years ago archive-description 5 years ago archive-products 5 years ago archive-result-count 5 years ago archive-title 5 years ago archive-view-mode 5 years ago breadcrumbs 5 years ago cart-table 5 years ago cart-totals 5 years ago categories 5 years ago checkout-coupon-form 5 years ago checkout-form-additional 5 years ago checkout-form-billing 5 years ago checkout-form-login 5 years ago checkout-form-shipping 5 years ago checkout-payment 5 years ago checkout-review-order 5 years ago checkout-shipping-methods 5 years ago cross-sells 5 years ago deal-products 5 years ago empty-cart-message 5 years ago filter-orderby 5 years ago filter-products-per-page 5 years ago filterable-product-list 5 years ago init 5 years ago product-categories 5 years ago product-category-lists 5 years ago product-description 5 years ago product-excerpt 5 years ago product-filters 5 years ago product-image 5 years ago product-list 5 years ago product-meta 5 years ago product-price 5 years ago product-rating 5 years ago product-review 5 years ago product-share 5 years ago product-sku 5 years ago product-stock 5 years ago product-tabs 5 years ago product-tags 5 years ago product-title 5 years ago recently-viewed-products 5 years ago related 5 years ago return-to-shop 5 years ago thankyou-address-details 5 years ago thankyou-order-confirm 5 years ago thankyou-order-details 5 years ago thankyou-thankyou 5 years ago up-sells 5 years ago manifest.php 5 years ago prod-short-code.php 5 years ago products.php 5 years ago shop.php 5 years ago
products.php
328 lines
1 <?php
2
3 namespace ShopEngine\Widgets;
4
5 use Elementor\Controls_Manager;
6 use ShopEngine\Core\Builders\Action;
7 use ShopEngine\Plugin;
8
9 defined('ABSPATH') || exit;
10
11 class Products
12 {
13
14
15 public static function get_a_simple_product_id($type = 'simple') {
16
17 $args = array(
18 'type' => [$type],
19 'status' => ['publish'],
20 'limit' => 1,
21 'orderby' => 'ID',
22 'order' => 'ASC'
23 );
24
25 $prod = wc_get_products($args);
26
27
28 return empty($prod[0]) ? false : $prod[0]->get_id();
29 }
30
31
32 public static function get_a_simple_product($type = 'simple') {
33
34 $args = array(
35 'type' => [$type],
36 'status' => ['publish'],
37 'limit' => 1,
38 'orderby' => 'ID',
39 'order' => 'ASC'
40 );
41
42 $prod = wc_get_products($args);
43
44
45 return empty($prod[0]) ? false : $prod[0];
46 }
47
48
49 public static function product_tab_content_preview($content) {
50
51 $product_id = \ShopEngine\Widgets\Products::get_a_product_id();
52 $product = wc_get_product($product_id);
53 $get_product_content = get_post($product_id);
54 $content = $get_product_content->post_content;
55
56 return $content;
57 }
58
59
60 public static function get_a_orders_from_my_account() {
61
62 $customer_orders = wc_get_orders(
63 apply_filters(
64 'woocommerce_my_account_my_orders_query',
65 array(
66 'customer' => get_current_user_id(),
67 'limit' => 1,
68 'return' => 'ids',
69 )
70 )
71 );
72
73 return empty($customer_orders) ? 0 : $customer_orders[0];
74 }
75
76 /**
77 * Get order id
78 */
79 public static function get_a_order_id() {
80 return wc_get_orders(['limit' => 1]);
81 }
82
83
84 /**
85 * This to grab a product in editor mode
86 *
87 * @since 1.0.0
88 *
89 * @return int
90 */
91 public static function get_a_product_id() {
92
93 $args = array(
94 'posts_per_page' => 1,
95 'post_type' => 'product',
96 'post_status' => 'publish',
97 );
98
99 $product = get_posts($args);
100
101 return empty($product[0]) ? 0 : $product[0]->ID;
102 }
103
104
105 public static function get_a_variable_product_id() {
106
107 $args = array(
108 'posts_per_page' => 1,
109 'post_type' => 'product_variation',
110 'post_status' => 'publish',
111 );
112
113 $product = get_posts($args);
114
115 return empty($product[0]) ? 0 : $product[0]->post_parent;
116 }
117
118
119 /**
120 * Grab a product for elementor editor preview
121 *
122 * @param $post_type
123 * @return string
124 */
125 public static function get_product($post_type) {
126
127 global $product;
128
129 if('product' == $post_type) {
130
131 return $product;
132 }
133
134 $prod_id = self::get_a_product_id();
135
136 $product = wc_get_product($prod_id);
137
138 return empty($product) ? new \stdClass() : $product;
139 }
140
141
142 public static function get_variation_product() {
143
144 global $product;
145
146 $post_type = get_post_type();
147
148 if('product' == $post_type) {
149
150 return $product;
151 }
152
153 $prod_id = self::get_a_variable_product_id();
154
155 $product = wc_get_product($prod_id);
156
157 return empty($product) ? new \stdClass() : $product;
158 }
159
160
161 public static function get_random_product_id() {
162
163 global $product;
164
165 $post_type = get_post_type();
166
167 if('product' == $post_type) {
168
169 $prod_id = $product->get_id();
170
171 } else {
172
173 $prod_id = self::get_a_product_id();
174 }
175
176 return $prod_id;
177 }
178
179
180 public static function get_widget_template($widget_name, $filename = 'default') {
181
182 return \ShopEngine::widget_dir() . $widget_name . '/screens/' . $filename . '.php';
183 }
184
185
186 public static function get_alignment_conf($prefix = 'elementor%s-align-', $def = 'left', $selectors = [], $selector = []) {
187
188 $arr = [
189 'label' => esc_html__('Alignment', 'shopengine'),
190 'type' => Controls_Manager::CHOOSE,
191 'options' => [
192 'left' => [
193 'description' => esc_html__('Left', 'shopengine'),
194 'icon' => 'fa fa-align-left',
195 ],
196 'center' => [
197 'description' => esc_html__('Center', 'shopengine'),
198 'icon' => 'fa fa-align-center',
199 ],
200 'right' => [
201 'description' => esc_html__('Right', 'shopengine'),
202 'icon' => 'fa fa-align-right',
203 ],
204 ],
205 'prefix_class' => $prefix,
206 'default' => $def,
207 ];
208
209
210 if(!empty($selectors)) {
211
212 $arr['selectors'] = $selectors;
213 }
214
215 if(!empty($selector)) {
216
217 $arr['selector'] = $selector;
218 }
219
220 return $arr;
221 }
222
223
224 public static function get_product_order_by_conf() {
225
226 return [
227 'label' => esc_html__('Orderby', 'shopengine'),
228 'type' => Controls_Manager::SELECT,
229 'default' => 'rand',
230 'options' => [
231 'date' => esc_html__('Publish Date', 'shopengine'),
232 'title' => esc_html__('Alphabetic', 'shopengine'),
233 'price' => esc_html__('Price', 'shopengine'),
234 'popularity' => esc_html__('Popularity', 'shopengine'),
235 'rating' => esc_html__('Rate', 'shopengine'),
236 'modified' => esc_html__('Modified Date', 'shopengine'),
237 ],
238 ];
239 }
240
241
242 public static function get_product_order_conf() {
243
244 return [
245 'label' => esc_html__('Order', 'shopengine'),
246 'type' => Controls_Manager::SELECT,
247 'default' => 'desc',
248 'options' => [
249 'desc' => esc_html__('DESC', 'shopengine'),
250 'asc' => esc_html__('ASC', 'shopengine'),
251 ],
252 ];
253 }
254
255 public static function get_template_type_by_id($page_id) {
256
257 #$allType = Templates::get_template_types();
258
259 $data = get_post_meta($page_id, Action::PK__SHOPENGINE_TEMPLATE, true);
260
261 return empty($data['form_type']) ? '' : $data['form_type'];
262 }
263
264 /**
265 * Undocumented function
266 *
267 * @return void
268 */
269 public static function get_all_color_terms(){
270 $attribute_taxonomies = wc_get_attribute_taxonomies();
271 $taxonomy_terms = [];
272
273 if ( !empty( $attribute_taxonomies ) ) {
274 foreach ( $attribute_taxonomies as $tax) {
275 if( 'color' == $tax->attribute_type ){
276 $attribute_name = wc_attribute_taxonomy_name( $tax->attribute_name );
277 if ( taxonomy_exists( $attribute_name ) ) {
278 $taxonomy_terms[$tax->attribute_name] = get_terms( $attribute_name, 'orderby=name&hide_empty=0' );
279 }
280 }
281 }
282 }
283 $all_color_terms = self::array_flatten($taxonomy_terms);
284 $all_color_terms = self::add_color_meta( $all_color_terms );
285 return $all_color_terms;
286 }
287
288 /**
289 * Undocumented function
290 *
291 * @param array $all_color_terms
292 * @return void
293 */
294 public static function add_color_meta( $all_color_terms = []){
295 if( is_array( $all_color_terms ) && !empty( $all_color_terms )){
296 foreach( $all_color_terms as $term ){
297 $term_id = $term->term_id;
298 $color_mete_value = get_term_meta($term_id, 'color', true);
299 $term->color = $color_mete_value;
300 }
301 }
302 return $all_color_terms;
303 }
304
305 /**
306 * Undocumented function
307 *
308 * @param [type] $array
309 * @return void
310 */
311 public static function array_flatten($array) {
312 if(!is_array($array)) {
313 return FALSE;
314 }
315
316 $result = array();
317 foreach ($array as $key => $value) {
318 if(is_array($value)) {
319 $result = array_merge($result, self::array_flatten($value));
320 }
321 else {
322 $result[$key] = $value;
323 }
324 }
325 return $result;
326 }
327 }
328