assets
2 years ago
comparison-cookie.php
2 years ago
comparison-field-value.php
1 year ago
comparison-helper.php
3 years ago
comparison-share.php
3 years ago
comparison.php
3 years ago
group-meta.php
3 years ago
route.php
3 years ago
group-meta.php
62 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ShopEngine\Modules\Comparison; |
| 4 | |
| 5 | use ShopEngine\Modules\Swatches\Helper; |
| 6 | use ShopEngine\Modules\Swatches\Swatches; |
| 7 | |
| 8 | class Group_Meta { |
| 9 | |
| 10 | public function index(\WC_Product $product){ |
| 11 | |
| 12 | if( $product->get_status() !== 'publish' ){ |
| 13 | return false; |
| 14 | } |
| 15 | |
| 16 | $product_id = $product->get_id(); |
| 17 | |
| 18 | $formatted_attributes[ $product_id ] = []; |
| 19 | |
| 20 | try { |
| 21 | if ( $product->has_attributes() ) { |
| 22 | $attributes = $product->get_attributes(); |
| 23 | |
| 24 | foreach ( $attributes as $attribute ) { |
| 25 | $attribute_id = $attribute->get_name(); |
| 26 | |
| 27 | $assigned_terms = $attribute->get_options(); |
| 28 | |
| 29 | $formatted_attributes[$product_id][$attribute_id]['name'] = wc_attribute_label( $attribute->get_name() ); |
| 30 | $formatted_attributes[$product_id][$attribute_id]['plain_name'] = $attribute->get_name(); |
| 31 | $formatted_attributes[$product_id][$attribute_id]['taxonomy'] = ''; |
| 32 | |
| 33 | if ( $attribute->is_taxonomy() ) { |
| 34 | $txo_meta = Helper::get_tax_attribute( $attribute->get_name() ); |
| 35 | |
| 36 | $formatted_attributes[$product_id][$attribute_id]['taxonomy'] = $txo_meta->attribute_type; |
| 37 | |
| 38 | foreach ( $assigned_terms as $assigned_term ) { |
| 39 | $term = get_term_by( 'id', $assigned_term, $attribute->get_name() ); |
| 40 | |
| 41 | if ( $txo_meta->attribute_type === Swatches::PA_COLOR ) { |
| 42 | $t_val = get_term_meta( $assigned_term, 'shopengine_color', true ); |
| 43 | |
| 44 | $formatted_attributes[$product_id][$attribute_id]['taxonomy_value'][$assigned_term] = $t_val; |
| 45 | } |
| 46 | |
| 47 | $formatted_attributes[$product_id][$attribute_id]['value'][] = $term->name; |
| 48 | } |
| 49 | } else { |
| 50 | foreach ( $assigned_terms as $term ) { |
| 51 | $formatted_attributes[$product_id][$attribute_id]['value'][] = $term; |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | return $formatted_attributes; |
| 57 | } catch ( \Throwable $th ) { |
| 58 | return false; |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 |