Allow wc_attribute_label to support product-level attribute names.
Closes #7662
This commit is contained in:
parent
5cbd02fef2
commit
3fc7a0ae65
|
@ -222,7 +222,6 @@ abstract class WC_Abstract_Order {
|
|||
|
||||
// Add variation meta
|
||||
if ( ! empty( $args['variation'] ) ) {
|
||||
|
||||
foreach ( $args['variation'] as $key => $value ) {
|
||||
wc_add_order_item_meta( $item_id, str_replace( 'attribute_', '', $key ), $value );
|
||||
}
|
||||
|
|
|
@ -130,14 +130,6 @@ class WC_Order_Item_Meta {
|
|||
if ( ! is_wp_error( $term ) && is_object( $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();
|
||||
|
||||
if ( isset( $product_attributes[ $attribute_key ] ) ) {
|
||||
$meta_key = wc_attribute_label( $product_attributes[ $attribute_key ]['name'] );
|
||||
}
|
||||
}
|
||||
|
||||
// Unique key required
|
||||
|
@ -149,7 +141,7 @@ class WC_Order_Item_Meta {
|
|||
}
|
||||
|
||||
$formatted_meta[ $formatted_meta_key ] = array(
|
||||
'label' => wc_attribute_label( $attribute_key ),
|
||||
'label' => wc_attribute_label( $attribute_key, $this->product ),
|
||||
'value' => apply_filters( 'woocommerce_order_item_display_meta_value', $meta_value ),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -46,10 +46,11 @@ function wc_attribute_taxonomy_name( $name ) {
|
|||
/**
|
||||
* Get a product attributes label.
|
||||
*
|
||||
* @param mixed $name
|
||||
* @param string $name
|
||||
* @param object $product object Optional
|
||||
* @return string
|
||||
*/
|
||||
function wc_attribute_label( $name ) {
|
||||
function wc_attribute_label( $name, $product = '' ) {
|
||||
global $wpdb;
|
||||
|
||||
if ( taxonomy_is_product_attribute( $name ) ) {
|
||||
|
@ -60,11 +61,15 @@ function wc_attribute_label( $name ) {
|
|||
if ( ! $label ) {
|
||||
$label = ucfirst( $name );
|
||||
}
|
||||
} elseif ( $product && ( $attributes = $product->get_attributes() ) && isset( $attributes[ sanitize_title( $name ) ]['name'] ) ) {
|
||||
// Attempt to get label from product, as entered by the user
|
||||
$label = $attributes[ sanitize_title( $name ) ]['name'];
|
||||
} else {
|
||||
// Just format as best as we can
|
||||
$label = ucwords( str_replace( '-', ' ', $name ) );
|
||||
}
|
||||
|
||||
return apply_filters( 'woocommerce_attribute_label', $label, $name );
|
||||
return apply_filters( 'woocommerce_attribute_label', $label, $name, $product );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -153,6 +153,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
|
|||
* Tweak - Move default customer location to general settings tab.
|
||||
* Tweak - Only run save_category_fields for product_cat taxonomy.
|
||||
* Tweak - Improved message when variation attributes are missing.
|
||||
* Tweak - Allow wc_attribute_label to support product-level attribute names.
|
||||
|
||||
= 2.3.5 - 20/02/2015 =
|
||||
* Fix - Plain text address formatting.
|
||||
|
|
Loading…
Reference in New Issue