diff --git a/admin/post-types/writepanels/writepanel-coupon_data.php b/admin/post-types/writepanels/writepanel-coupon_data.php index e65aff09a2e..682dd12c48c 100644 --- a/admin/post-types/writepanels/writepanel-coupon_data.php +++ b/admin/post-types/writepanels/writepanel-coupon_data.php @@ -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 ''; + echo ''; } } ?> @@ -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 ''; + echo ''; } } ?> diff --git a/admin/post-types/writepanels/writepanel-order_downloads.php b/admin/post-types/writepanels/writepanel-order_downloads.php index 6ea2cbe88c8..707bc3cc3d2 100644 --- a/admin/post-types/writepanels/writepanel-order_downloads.php +++ b/admin/post-types/writepanels/writepanel-order_downloads.php @@ -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 ''; + echo ''; } ?> diff --git a/admin/post-types/writepanels/writepanel-product_data.php b/admin/post-types/writepanels/writepanel-product_data.php index cb38030b5b9..a23da761ce6 100644 --- a/admin/post-types/writepanels/writepanel-product_data.php +++ b/admin/post-types/writepanels/writepanel-product_data.php @@ -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 ''; + echo ''; } } ?> @@ -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 ''; + echo ''; } } ?> diff --git a/classes/class-wc-product-variation.php b/classes/class-wc-product-variation.php index 8bd2700720c..581aa19f85b 100644 --- a/classes/class-wc-product-variation.php +++ b/classes/class-wc-product-variation.php @@ -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 ); diff --git a/woocommerce-ajax.php b/woocommerce-ajax.php index 6ab5a58ffb9..4ffd12e460e 100644 --- a/woocommerce-ajax.php +++ b/woocommerce-ajax.php @@ -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); - - ?> -