Merge pull request #2828 from thenbrent/formatted_product_name
Encapsulate formatted product name
This commit is contained in:
commit
656c897448
|
@ -80,9 +80,8 @@ function woocommerce_coupon_data_meta_box( $post ) {
|
|||
foreach ( $product_ids as $product_id ) {
|
||||
|
||||
$product = get_product( $product_id );
|
||||
$product_name = woocommerce_get_formatted_product_name( $product );
|
||||
|
||||
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . wp_kses_post( $product_name ) . '</option>';
|
||||
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . wp_kses_post( $product->get_formatted_name() ) . '</option>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -100,9 +99,8 @@ function woocommerce_coupon_data_meta_box( $post ) {
|
|||
foreach ( $product_ids as $product_id ) {
|
||||
|
||||
$product = get_product( $product_id );
|
||||
$product_name = woocommerce_get_formatted_product_name( $product );
|
||||
|
||||
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $product_name ) . '</option>';
|
||||
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $product->get_formatted_name() ) . '</option>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -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 '<option value="' . esc_attr( $product->ID ) . '">' . esc_html( $product_name ) . '</option>';
|
||||
echo '<option value="' . esc_attr( $product->ID ) . '">' . esc_html( $product_object->get_formatted_name() ) . '</option>';
|
||||
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -528,9 +528,8 @@ function woocommerce_product_data_box() {
|
|||
foreach ( $product_ids as $product_id ) {
|
||||
|
||||
$product = get_product( $product_id );
|
||||
$product_name = woocommerce_get_formatted_product_name( $product );
|
||||
|
||||
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $product_name ) . '</option>';
|
||||
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $product->get_formatted_name() ) . '</option>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -545,9 +544,8 @@ function woocommerce_product_data_box() {
|
|||
foreach ( $product_ids as $product_id ) {
|
||||
|
||||
$product = get_product( $product_id );
|
||||
$product_name = woocommerce_get_formatted_product_name( $product );
|
||||
|
||||
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $product_name ) . '</option>';
|
||||
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $product->get_formatted_name() ) . '</option>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
}
|
|
@ -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 );
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue