ID); if (empty($product)) { return ''; } if (isset($post->orderItem)) { $allAttrsValues = array(); foreach ($post->orderItem->get_all_formatted_meta_data('') as $metaData) { if (substr($metaData->key, 0, 1) !== '_') { $attributeValue = $metaData->value; if (0 === strpos($metaData->key, 'pa_')) { $option_term = get_term_by('slug', $attributeValue, $metaData->key); $attributeValue = $option_term && ! is_wp_error($option_term) ? str_replace(',', '\\,', $option_term->name) : str_replace(',', '\\,', $attributeValue); $taxonomy = get_taxonomy($metaData->key); $attributeLabel = !empty($taxonomy) ? $taxonomy->labels->singular_name : $metaData->key; } else { $attributeLabel = $metaData->key; } $allAttrsValues[] = ($showLabel ? $attributeLabel . ': ' : '') . $attributeValue; } } return implode($separator, array_filter($allAttrsValues)); } elseif ('product_variation' === $post->post_type) { $parentPost = get_post($post->post_parent); $parentProduct = wc_get_product($parentPost->ID); $parentNotVariableAttributes = array_filter($parentProduct->get_attributes(), function($wcAttribute){ return !$wcAttribute->get_variation(); }); $parentNotVariableAttributesOptions = $this->getAttributesOptions($parentNotVariableAttributes); $attributesValues = array(); foreach ($parentNotVariableAttributesOptions as $attributesOption) { $attributesValues[] = ($showLabel ? ($attributesOption['label'] . ': ') : '') . implode($separator, array_filter($attributesOption['options'])); } return implode($separator, $attributesValues); } elseif ('product' === $post->post_type) { if ('variable' === $product->get_type()) { $parentNotVariableAttributes = array_filter($product->get_attributes(), function($wcAttribute){ return !$wcAttribute->get_variation(); }); $parentNotVariableAttributesOptions = $this->getAttributesOptions($parentNotVariableAttributes); $attributesValues = array(); foreach ($parentNotVariableAttributesOptions as $attributesOption) { $attributesValues[] = ($showLabel ? ($attributesOption['label'] . ': ') : '') . implode($separator, array_filter($attributesOption['options'])); } return implode($separator, $attributesValues); } elseif ('simple' === $product->get_type()) { $simpleProductAttributes = $product->get_attributes(); $simpleProductAttributesOptions = $this->getAttributesOptions($simpleProductAttributes); $attributesValues = array(); foreach ($simpleProductAttributesOptions as $attributesOption) { $attributesValues[] = ($showLabel ? ($attributesOption['label'] . ': ') : '') . implode($separator, array_filter($attributesOption['options'])); } return implode($separator, $attributesValues); } else { return ''; } } else { return ''; } } }