2013-03-12 10:55:01 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Order Item Meta
|
|
|
|
*
|
|
|
|
* A Simple class for managing order item meta so plugins add it in the correct format
|
|
|
|
*
|
|
|
|
* @class order_item_meta
|
|
|
|
* @version 2.0.4
|
|
|
|
* @package WooCommerce/Classes
|
|
|
|
* @author WooThemes
|
|
|
|
*/
|
|
|
|
class WC_Order_Item_Meta {
|
|
|
|
|
|
|
|
public $meta;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param string $item_meta (default: '')
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct( $item_meta = array() ) {
|
|
|
|
$this->meta = $item_meta;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display meta in a formatted list
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param bool $flat (default: false)
|
|
|
|
* @param bool $return (default: false)
|
|
|
|
* @param string $hideprefix (default: _)
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function display( $flat = false, $return = false, $hideprefix = '_' ) {
|
|
|
|
global $woocommerce;
|
|
|
|
|
|
|
|
if ( ! empty( $this->meta ) ) {
|
|
|
|
|
|
|
|
$meta_list = array();
|
|
|
|
|
|
|
|
foreach ( $this->meta as $meta_key => $meta_values ) {
|
|
|
|
|
|
|
|
if ( empty( $meta_values ) || ( ! empty( $hideprefix ) && substr( $meta_key, 0, 1 ) == $hideprefix ) )
|
|
|
|
continue;
|
|
|
|
|
2013-05-28 14:58:40 +00:00
|
|
|
$found_meta = true;
|
|
|
|
|
2013-03-12 10:55:01 +00:00
|
|
|
foreach( $meta_values as $meta_value ) {
|
|
|
|
|
2013-04-16 14:50:09 +00:00
|
|
|
// Skip serialised meta
|
|
|
|
if ( is_serialized( $meta_value ) )
|
|
|
|
continue;
|
|
|
|
|
2013-03-12 10:55:01 +00:00
|
|
|
// If this is a term slug, get the term's nice name
|
|
|
|
if ( taxonomy_exists( esc_attr( str_replace( 'attribute_', '', $meta_key ) ) ) ) {
|
|
|
|
$term = get_term_by('slug', $meta_value, esc_attr( str_replace( 'attribute_', '', $meta_key ) ) );
|
|
|
|
if ( ! is_wp_error( $term ) && $term->name )
|
|
|
|
$meta_value = $term->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $flat )
|
2013-05-15 13:10:41 +00:00
|
|
|
$meta_list[] = esc_attr( $woocommerce->attribute_label( str_replace( 'attribute_', '', $meta_key ) ) . ': ' . apply_filters( 'woocommerce_order_item_display_meta_value', $meta_value ) );
|
2013-03-12 10:55:01 +00:00
|
|
|
else
|
2013-05-15 13:10:41 +00:00
|
|
|
$meta_list[] = '<dt>' . wp_kses_post( $woocommerce->attribute_label( str_replace( 'attribute_', '', $meta_key ) ) ) . ':</dt><dd>' . wp_kses_post( apply_filters( 'woocommerce_order_item_display_meta_value', $meta_value ) ) . '</dd>';
|
2013-03-12 10:55:01 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-28 14:58:40 +00:00
|
|
|
if ( ! sizeof( $meta_list ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
$output = $flat ? '' : '<dl class="variation">';
|
|
|
|
|
2013-03-12 10:55:01 +00:00
|
|
|
if ( $flat )
|
|
|
|
$output .= implode( ", \n", $meta_list );
|
|
|
|
else
|
|
|
|
$output .= implode( '', $meta_list );
|
|
|
|
|
|
|
|
if ( ! $flat )
|
|
|
|
$output .= '</dl>';
|
|
|
|
|
|
|
|
if ( $return )
|
|
|
|
return $output;
|
|
|
|
else
|
|
|
|
echo $output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|