diff --git a/admin/post-types/writepanels/writepanel-coupon_data.php b/admin/post-types/writepanels/writepanel-coupon_data.php
index 4d68e386517..16494d77fbb 100644
--- a/admin/post-types/writepanels/writepanel-coupon_data.php
+++ b/admin/post-types/writepanels/writepanel-coupon_data.php
@@ -79,10 +79,9 @@ function woocommerce_coupon_data_meta_box( $post ) {
$product_ids = array_map( 'absint', explode( ',', $product_ids ) );
foreach ( $product_ids as $product_id ) {
- $product = get_product( $product_id );
- $product_name = woocommerce_get_formatted_product_name( $product );
+ $product = get_product( $product_id );
- echo '';
+ echo '';
}
}
?>
@@ -99,10 +98,9 @@ function woocommerce_coupon_data_meta_box( $post ) {
$product_ids = array_map( 'absint', explode( ',', $product_ids ) );
foreach ( $product_ids as $product_id ) {
- $product = get_product( $product_id );
- $product_name = woocommerce_get_formatted_product_name( $product );
+ $product = get_product( $product_id );
- echo '';
+ echo '';
}
}
?>
diff --git a/admin/post-types/writepanels/writepanel-order_downloads.php b/admin/post-types/writepanels/writepanel-order_downloads.php
index 434697bfc3b..f823c684b39 100644
--- a/admin/post-types/writepanels/writepanel-order_downloads.php
+++ b/admin/post-types/writepanels/writepanel-order_downloads.php
@@ -76,9 +76,8 @@ function woocommerce_order_downloads_meta_box() {
if ( $products ) foreach ( $products as $product ) {
$product_object = get_product( $product->ID );
- $product_name = woocommerce_get_formatted_product_name( $product_object );
- echo '';
+ echo '';
}
?>
diff --git a/admin/post-types/writepanels/writepanel-product_data.php b/admin/post-types/writepanels/writepanel-product_data.php
index 2430489098f..d0c5b754285 100644
--- a/admin/post-types/writepanels/writepanel-product_data.php
+++ b/admin/post-types/writepanels/writepanel-product_data.php
@@ -527,10 +527,9 @@ function woocommerce_product_data_box() {
if ( $product_ids ) {
foreach ( $product_ids as $product_id ) {
- $product = get_product( $product_id );
- $product_name = woocommerce_get_formatted_product_name( $product );
+ $product = get_product( $product_id );
- echo '';
+ echo '';
}
}
?>
@@ -544,10 +543,9 @@ function woocommerce_product_data_box() {
if ( $product_ids ) {
foreach ( $product_ids as $product_id ) {
- $product = get_product( $product_id );
- $product_name = woocommerce_get_formatted_product_name( $product );
+ $product = get_product( $product_id );
- echo '';
+ echo '';
}
}
?>
diff --git a/classes/abstracts/abstract-wc-product.php b/classes/abstracts/abstract-wc-product.php
index 846cc08d8d0..44111131492 100644
--- a/classes/abstracts/abstract-wc-product.php
+++ b/classes/abstracts/abstract-wc-product.php
@@ -1270,4 +1270,22 @@ class WC_Product {
return $image;
}
+
+
+ /**
+ * Get product name with SKU or ID. Used within admin.
+ *
+ * @access public
+ * @param mixed $product
+ * @return string Formatted product name
+ */
+ function get_formatted_name() {
+
+ if ( $this->get_sku() )
+ $identifier = $this->get_sku();
+ else
+ $identifier = '#' . $this->id;
+
+ return sprintf( __( '%s – %s', 'woocommerce' ), $identifier, $this->get_title() );
+ }
}
\ No newline at end of file
diff --git a/classes/class-wc-product-variation.php b/classes/class-wc-product-variation.php
index c1e5378044a..d9e0e93964e 100644
--- a/classes/class-wc-product-variation.php
+++ b/classes/class-wc-product-variation.php
@@ -452,4 +452,25 @@ class WC_Product_Variation extends WC_Product {
// allow overriding based on the particular file being requested
return apply_filters( 'woocommerce_file_download_path', $file_path, $this->variation_id, $download_id );
}
+
+
+ /**
+ * Get product name with extra details such as SKU, price and attributes. Used within admin.
+ *
+ * @access public
+ * @param mixed $product
+ * @return string Formatted product name, including attributes and price
+ */
+ public function get_formatted_name() {
+
+ if ( $this->get_sku() )
+ $identifier = $this->get_sku();
+ else
+ $identifier = '#' . $this->variation_id;
+
+ $attributes = $this->get_variation_attributes();
+ $extra_data = ' – ' . implode( ', ', $attributes ) . ' – ' . woocommerce_price( $this->get_price() );
+
+ return sprintf( __( '%s – %s%s', 'woocommerce' ), $identifier, $this->get_title(), $extra_data );
+ }
}
\ No newline at end of file
diff --git a/woocommerce-ajax.php b/woocommerce-ajax.php
index 0c7e6f868c1..f2da9337570 100644
--- a/woocommerce-ajax.php
+++ b/woocommerce-ajax.php
@@ -1607,7 +1607,7 @@ function woocommerce_json_search_products( $x = '', $post_types = array('product
$product = get_product( $post );
- $found_products[ $post ] = woocommerce_get_formatted_product_name( $product );
+ $found_products[ $post ] = $product->get_formatted_name();
}
diff --git a/woocommerce-core-functions.php b/woocommerce-core-functions.php
index d0474e76b41..57914d240e9 100644
--- a/woocommerce-core-functions.php
+++ b/woocommerce-core-functions.php
@@ -252,27 +252,14 @@ function woocommerce_get_weight( $weight, $to_unit ) {
*
* @access public
* @param mixed $product
+ * @deprecated 2.1
* @return void
*/
function woocommerce_get_formatted_product_name( $product ) {
- if ( ! $product || ! is_object( $product ) )
- return;
- if ( $product->get_sku() )
- $identifier = $product->get_sku();
- elseif ( $product->is_type( 'variation' ) )
- $identifier = '#' . $product->variation_id;
- else
- $identifier = '#' . $product->id;
+ _deprecated_function( __FUNCTION__, '2.1', 'WC_Product::get_formatted_name()' );
- if ( $product->is_type( 'variation' ) ) {
- $attributes = $product->get_variation_attributes();
- $extra_data = ' – ' . implode( ', ', $attributes ) . ' – ' . woocommerce_price( $product->get_price() );
- } else {
- $extra_data = '';
- }
-
- return sprintf( __( '%s – %s%s', 'woocommerce' ), $identifier, $product->get_title(), $extra_data );
+ return $product->get_formatted_name();
}
@@ -2522,4 +2509,4 @@ function woocommerce_clear_comment_rating_transients( $comment_id ) {
}
add_action( 'wp_set_comment_status', 'woocommerce_clear_comment_rating_transients' );
-add_action( 'edit_comment', 'woocommerce_clear_comment_rating_transients' );
\ No newline at end of file
+add_action( 'edit_comment', 'woocommerce_clear_comment_rating_transients' );