For custom attributes, try to turn back to 'name' from saved slug in emails/view order templates Closes #4833

This commit is contained in:
Mike Jolley 2014-02-24 15:14:32 +00:00
parent 4280f5ab78
commit 38872b8536
4 changed files with 12 additions and 5 deletions

View File

@ -12,6 +12,7 @@
class WC_Order_Item_Meta {
public $meta;
public $product;
/**
* Constructor
@ -20,8 +21,9 @@ class WC_Order_Item_Meta {
* @param string $item_meta (default: '')
* @return void
*/
public function __construct( $item_meta = array() ) {
$this->meta = $item_meta;
public function __construct( $item_meta = array(), $product = null ) {
$this->meta = $item_meta;
$this->product = $product;
}
/**
@ -55,6 +57,11 @@ class WC_Order_Item_Meta {
$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 we have a product, and its not a term, try to find its non-sanitized name
} elseif ( $this->product ) {
$product_attributes = $this->product->get_attributes();
$meta_key = wc_attribute_label( $product_attributes[ str_replace( 'attribute_', '', urldecode( $meta_key ) ) ]['name'] );
}
if ( $flat )

View File

@ -15,7 +15,7 @@ global $woocommerce;
foreach ( $items as $item ) :
$_product = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item );
$item_meta = new WC_Order_Item_Meta( $item['item_meta'] );
$item_meta = new WC_Order_Item_Meta( $item['item_meta'], $_product );
?>
<tr>
<td style="text-align:left; vertical-align:middle; border: 1px solid #eee; word-wrap:break-word;"><?php

View File

@ -15,7 +15,7 @@ global $woocommerce;
foreach ( $items as $item ) :
$_product = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item );
$item_meta = new WC_Order_Item_Meta( $item['item_meta'] );
$item_meta = new WC_Order_Item_Meta( $item['item_meta'], $_product );
// Title
echo apply_filters( 'woocommerce_order_item_name', $item['name'], $item );

View File

@ -39,7 +39,7 @@ $order = new WC_Order( $order_id );
foreach( $order->get_items() as $item ) {
$_product = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item );
$item_meta = new WC_Order_Item_Meta( $item['item_meta'] );
$item_meta = new WC_Order_Item_Meta( $item['item_meta'], $_product );
?>
<tr class="<?php echo esc_attr( apply_filters( 'woocommerce_order_item_class', 'order_item', $item, $order ) ); ?>">