PluginProbe
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution with eCommerce Templates & Woo Widgets / 2.2.2
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution with eCommerce Templates & Woo Widgets v2.2.2
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 All 85 releases
shopengine / modules / comparison / group-meta.php

group-meta.php in ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution with eCommerce Templates & Woo Widgets 2.2.2, at modules/comparison/group-meta.php

66 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 namespace ShopEngine\Modules\Comparison;
5
6
7 use ShopEngine\Modules\Swatches\Helper;
8 use ShopEngine\Modules\Swatches\Swatches;
9
10 class Group_Meta {
11
12
13 public function index(\WC_Product $product){
14
15 if( $product->get_status() !== 'publish' ){
16 return false;
17 }
18
19 $product_id = $product->get_id();
20
21 $formatted_attributes[ $product_id ] = [];
22
23 if ( $product->has_attributes() ) {
24 $attributes = $product->get_attributes();
25
26 foreach ( $attributes as $attribute ) {
27 $attribute_id = $attribute->get_name();
28
29 $assigned_terms = $attribute->get_options();
30
31 $formatted_attributes[ $product_id ][ $attribute_id ]['name'] = wc_attribute_label( $attribute->get_name() );
32 $formatted_attributes[ $product_id ][ $attribute_id ]['plain_name'] = $attribute->get_name();
33 $formatted_attributes[ $product_id ][ $attribute_id ]['taxonomy'] = '';
34
35 if ( $attribute->is_taxonomy() ) {
36 $txo_meta = Helper::get_tax_attribute( $attribute->get_name() );
37
38 $formatted_attributes[ $product_id ][ $attribute_id ]['taxonomy'] = $txo_meta->attribute_type;
39
40 foreach ( $assigned_terms as $assigned_term ) {
41 $term = get_term_by( 'id', $assigned_term, $attribute->get_name() );
42
43 if ( $txo_meta->attribute_type === Swatches::PA_COLOR ) {
44 $t_val = get_term_meta( $assigned_term, 'shopengine_color', true );
45
46 $formatted_attributes[ $product_id ][ $attribute_id ]['taxonomy_value'][ $assigned_term ] = $t_val;
47 }
48
49 $formatted_attributes[ $product_id ][ $attribute_id ]['value'][] = $term->name;
50 }
51 } else {
52 foreach ( $assigned_terms as $term ) {
53 $formatted_attributes[ $product_id ][ $attribute_id ]['value'][] = $term;
54 }
55 }
56 }
57 }
58
59 //die(json_encode($formatted_attributes));
60
61 return $formatted_attributes;
62
63 }
64
65
66 }