Clean up variation display in admin. Closes #2241.
This commit is contained in:
parent
fc0179e914
commit
ad1eb92b4c
|
@ -75,16 +75,11 @@ function woocommerce_coupon_data_meta_box( $post ) {
|
|||
if ( $product_ids ) {
|
||||
$product_ids = array_map( 'absint', explode( ',', $product_ids ) );
|
||||
foreach ( $product_ids as $product_id ) {
|
||||
$title = get_the_title( $product_id );
|
||||
$sku = get_post_meta( $product_id, '_sku', true );
|
||||
|
||||
if ( ! $title )
|
||||
continue;
|
||||
$product = get_product( $product_id );
|
||||
$product_name = woocommerce_get_formatted_product_name( $product );
|
||||
|
||||
if ( ! empty( $sku ) )
|
||||
$sku = ' (SKU: ' . $sku . ')';
|
||||
|
||||
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $title . $sku ) . '</option>';
|
||||
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $product_name ) . '</option>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -100,16 +95,11 @@ function woocommerce_coupon_data_meta_box( $post ) {
|
|||
if ( $product_ids ) {
|
||||
$product_ids = array_map( 'absint', explode( ',', $product_ids ) );
|
||||
foreach ( $product_ids as $product_id ) {
|
||||
$title = get_the_title( $product_id );
|
||||
$sku = get_post_meta( $product_id, '_sku', true );
|
||||
|
||||
if ( ! $title )
|
||||
continue;
|
||||
$product = get_product( $product_id );
|
||||
$product_name = woocommerce_get_formatted_product_name( $product );
|
||||
|
||||
if ( ! empty( $sku ) )
|
||||
$sku = ' (SKU: ' . $sku . ')';
|
||||
|
||||
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $title . $sku ) . '</option>';
|
||||
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $product_name ) . '</option>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -75,12 +75,10 @@ function woocommerce_order_downloads_meta_box() {
|
|||
|
||||
if ( $products ) foreach ( $products as $product ) {
|
||||
|
||||
$sku = get_post_meta( $product->ID, '_sku', true );
|
||||
$product_object = get_product( $product->ID );
|
||||
$product_name = woocommerce_get_formatted_product_name( $product );
|
||||
|
||||
if ( $sku )
|
||||
$sku = ' SKU: ' . $sku;
|
||||
|
||||
echo '<option value="' . esc_attr( $product->ID ) . '">' . esc_html( $product->post_title . ' (#' . $product->ID . '' . $sku . ')' ) . '</option>';
|
||||
echo '<option value="' . esc_attr( $product->ID ) . '">' . esc_html( $product_name ) . '</option>';
|
||||
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -507,16 +507,11 @@ function woocommerce_product_data_box() {
|
|||
$product_ids = ! empty( $upsell_ids ) ? array_map( 'absint', $upsell_ids ) : null;
|
||||
if ( $product_ids ) {
|
||||
foreach ( $product_ids as $product_id ) {
|
||||
$title = get_the_title( $product_id );
|
||||
$sku = get_post_meta( $product_id, '_sku', true );
|
||||
|
||||
if ( ! $title )
|
||||
continue;
|
||||
$product = get_product( $product_id );
|
||||
$product_name = woocommerce_get_formatted_product_name( $product );
|
||||
|
||||
if ( ! empty( $sku ) )
|
||||
$sku = ' (SKU: ' . $sku . ')';
|
||||
|
||||
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $title . $sku ) . '</option>';
|
||||
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $product_name ) . '</option>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -529,16 +524,11 @@ function woocommerce_product_data_box() {
|
|||
$product_ids = ! empty( $crosssell_ids ) ? array_map( 'absint', $crosssell_ids ) : null;
|
||||
if ( $product_ids ) {
|
||||
foreach ( $product_ids as $product_id ) {
|
||||
$title = get_the_title( $product_id );
|
||||
$sku = get_post_meta( $product_id, '_sku', true );
|
||||
|
||||
if ( ! $title )
|
||||
continue;
|
||||
$product = get_product( $product_id );
|
||||
$product_name = woocommerce_get_formatted_product_name( $product );
|
||||
|
||||
if ( ! empty( $sku ) )
|
||||
$sku = ' (SKU: ' . $sku . ')';
|
||||
|
||||
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $title . $sku ) . '</option>';
|
||||
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $product_name ) . '</option>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -60,7 +60,7 @@ class WC_Product_Variation extends WC_Product {
|
|||
*/
|
||||
public function __construct( $variation, $args = array() ) {
|
||||
|
||||
$this->product_type = 'variable';
|
||||
$this->product_type = 'variation';
|
||||
|
||||
if ( is_object( $variation ) ) {
|
||||
$this->variation_id = absint( $variation->ID );
|
||||
|
|
|
@ -1616,17 +1616,15 @@ function woocommerce_json_search_products( $x = '', $post_types = array('product
|
|||
|
||||
$found_products = array();
|
||||
|
||||
if ($posts) foreach ($posts as $post) {
|
||||
if ( $posts ) foreach ( $posts as $post ) {
|
||||
|
||||
$SKU = get_post_meta($post, '_sku', true);
|
||||
$product = get_product( $post );
|
||||
|
||||
if (isset($SKU) && $SKU) $SKU = ' (SKU: ' . $SKU . ')';
|
||||
|
||||
$found_products[$post] = get_the_title( $post ) . ' – #' . $post . $SKU;
|
||||
$found_products[ $post ] = woocommerce_get_formatted_product_name( $product );
|
||||
|
||||
}
|
||||
|
||||
$found_products = apply_filters( 'woocommerce_json_search_found_products', $found_products);
|
||||
$found_products = apply_filters( 'woocommerce_json_search_found_products', $found_products );
|
||||
|
||||
echo json_encode( $found_products );
|
||||
|
||||
|
@ -1692,63 +1690,6 @@ function woocommerce_json_search_customers() {
|
|||
add_action('wp_ajax_woocommerce_json_search_customers', 'woocommerce_json_search_customers');
|
||||
|
||||
|
||||
/**
|
||||
* Search for products for upsells/crosssells
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function woocommerce_upsell_crosssell_search_products() {
|
||||
|
||||
check_ajax_referer( 'search-products', 'security' );
|
||||
|
||||
$search = (string) urldecode(stripslashes(strip_tags($_POST['search'])));
|
||||
$name = (string) urldecode(stripslashes(strip_tags($_POST['name'])));
|
||||
|
||||
if (empty($search)) die();
|
||||
|
||||
if (is_numeric($search)) :
|
||||
|
||||
$args = array(
|
||||
'post_type' => 'product',
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => 15,
|
||||
'post__in' => array(0, $search)
|
||||
);
|
||||
|
||||
else :
|
||||
|
||||
$args = array(
|
||||
'post_type' => 'product',
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => 15,
|
||||
's' => $search
|
||||
);
|
||||
|
||||
endif;
|
||||
|
||||
$posts = apply_filters('woocommerce_upsell_crosssell_search_products', get_posts( $args ));
|
||||
|
||||
if ($posts) : foreach ($posts as $post) :
|
||||
|
||||
$SKU = get_post_meta($post->ID, '_sku', true);
|
||||
|
||||
?>
|
||||
<li rel="<?php echo $post->ID; ?>"><button type="button" name="Add" class="button add_crosssell" title="Add"><?php _e( 'Cross-sell', 'woocommerce' ); ?> →</button><button type="button" name="Add" class="button add_upsell" title="Add"><?php _e( 'Up-sell', 'woocommerce' ); ?> →</button><strong><?php echo $post->post_title; ?></strong> – #<?php echo $post->ID; ?> <?php if (isset($SKU) && $SKU) echo 'SKU: '.esc_attr( $SKU ); ?><input type="hidden" class="product_id" value="0" /></li>
|
||||
<?php
|
||||
|
||||
endforeach; else :
|
||||
|
||||
?><li><?php _e( 'No products found', 'woocommerce' ); ?></li><?php
|
||||
|
||||
endif;
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
add_action('wp_ajax_woocommerce_upsell_crosssell_search_products', 'woocommerce_upsell_crosssell_search_products');
|
||||
|
||||
|
||||
/**
|
||||
* Ajax request handling for categories ordering
|
||||
*
|
||||
|
|
|
@ -76,6 +76,13 @@ function woocommerce_get_product_ids_on_sale() {
|
|||
return $product_ids_on_sale;
|
||||
}
|
||||
|
||||
/**
|
||||
* woocommerce_sanitize_taxonomy_name function.
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $taxonomy
|
||||
* @return void
|
||||
*/
|
||||
function woocommerce_sanitize_taxonomy_name( $taxonomy ) {
|
||||
return str_replace( array( ' ', '_' ), '-', strtolower( $taxonomy ) );
|
||||
}
|
||||
|
@ -97,6 +104,13 @@ function woocommerce_get_attachment_image_attributes( $attr ) {
|
|||
add_filter( 'wp_get_attachment_image_attributes', 'woocommerce_get_attachment_image_attributes' );
|
||||
|
||||
|
||||
/**
|
||||
* woocommerce_prepare_attachment_for_js function.
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $response
|
||||
* @return void
|
||||
*/
|
||||
function woocommerce_prepare_attachment_for_js( $response ) {
|
||||
|
||||
if ( isset( $response['url'] ) && strstr( $response['url'], 'woocommerce_uploads/' ) ) {
|
||||
|
@ -217,6 +231,35 @@ function woocommerce_get_weight( $weight, $to_unit ) {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get product name with extra details such as SKU price and attributes. Used within admin.
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $product
|
||||
* @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;
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the placeholder image URL for products etc
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue