-1

The WC_Order_Item_Meta::get_formatted() function returns terms array of the order. Each term is an array of three things:

'key'   => $meta->key // attribute key
'label' => wc_attribute_label( $attribute_key, $this->product ) // attribute label
'value' => apply_filters( 'woocommerce_order_item_display_meta_value', $meta->value ) // term value

Also I need term slug, how do I can get the slug of the term if I know attribute key/attribute label/term value??

3 Answers 3

0

This is the output of the function:

array(
        'pa_size' => array(
          'label' => 'Size',
          'value' => 'Medium',
        )
     )

You get the slug like this:

$terms =  WC_Order_Item_Meta::get_formatted();
foreach($terms as $slug => $term){

}
1
  • No, label is not a slug of the term, it is slug of the attribute.
    – Sevi
    Oct 27, 2015 at 19:41
0

Ok, I found solution:

$slug = '';
$item_ = $this->item['item_meta'];
foreach ($item_ as $meta_ => $term_)
{
    if(substr($meta_,0,3) == 'pa_' && $meta_ == $meta->key)
    {
        $slug = $term_[0];
        break;
    }
}

$formatted_meta[ $meta_id ] = array(
    'key'   => $meta->key,
    'label' => wc_attribute_label( $attribute_key, $this->product ),
    'value' => apply_filters( 'woocommerce_order_item_display_meta_value', $meta->value ),
    'slug'  => $slug,
);
-1
$term = get_term_by( '1', '2', '3' );
  1. Replace with what you are trying to retrieve by so 'name' or 'slug' or 'ID'

  2. Your term label

  3. The taxonomy so if you wanted to search by post category you would put 'category'

3
  • What I write instead of 'name' and 'taxonomytype'?
    – Sevi
    Oct 27, 2015 at 19:46
  • Sorry trying to do this from a mobile let me amend to make more clear Oct 27, 2015 at 19:48
  • I tried to add 'slug' => get_term_by( 'slug', wc_attribute_label( $attribute_key, $this->product), $meta->key ) but it does not return anything.
    – Sevi
    Oct 27, 2015 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.