From 5f66b49fd18abe52091affdd75b75b89740f8556 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 19 Sep 2011 13:25:06 +0100 Subject: [PATCH] Product page cleanup and filter by product type --- admin/admin-post-types.php | 126 +++++++++++++++++++++++++------------ assets/css/admin.css | 8 +-- assets/css/admin.less | 51 ++++++++------- 3 files changed, 118 insertions(+), 67 deletions(-) diff --git a/admin/admin-post-types.php b/admin/admin-post-types.php index b241cf4bd85..ca7fd592f78 100644 --- a/admin/admin-post-types.php +++ b/admin/admin-post-types.php @@ -123,21 +123,21 @@ function woocommerce_edit_product_columns($columns){ $columns["cb"] = ""; $columns["thumb"] = __("Image", 'woothemes'); + $columns["title"] = __("Name", 'woothemes'); + if( get_option('woocommerce_enable_sku', true) == 'yes' ) $columns["sku"] = __("ID", 'woothemes'); $columns["product_type"] = __("Type", 'woothemes'); - $columns["sku"] = __("ID/SKU", 'woothemes'); - $columns["product_cat"] = __("Category", 'woothemes'); + + $columns["product_cat"] = __("Categories", 'woothemes'); $columns["product_tags"] = __("Tags", 'woothemes'); - $columns["visibility"] = __("Visibility", 'woothemes'); $columns["featured"] = __("Featured", 'woothemes'); if (get_option('woocommerce_manage_stock')=='yes') : $columns["is_in_stock"] = __("In Stock?", 'woothemes'); - $columns["inventory"] = __("Inventory", 'woothemes'); endif; $columns["price"] = __("Price", 'woothemes'); - $columns["date"] = __("Date", 'woothemes'); + $columns["product_date"] = __("Date", 'woothemes'); return $columns; } @@ -158,17 +158,14 @@ function woocommerce_custom_product_columns($column) { echo get_the_post_thumbnail($post->ID, 'shop_thumbnail'); endif; break; - case "summary" : - echo $post->post_excerpt; - break; case "price": echo $product->get_price_html(); break; case "product_cat" : - echo get_the_term_list($post->ID, 'product_cat', '', ', ',''); + if (!$terms = get_the_term_list($post->ID, 'product_cat', '', ', ','')) echo ''; else echo $terms; break; case "product_tags" : - echo get_the_term_list($post->ID, 'product_tag', '', ', ',''); + if (!$terms = get_the_term_list($post->ID, 'product_tag', '', ', ','')) echo ''; else echo $terms; break; case "sku" : if ( $sku = get_post_meta( $post->ID, 'sku', true )) : @@ -184,27 +181,55 @@ function woocommerce_custom_product_columns($column) { else echo 'no'; echo ''; break; - case "visibility" : - if ( $this_data = $product->visibility ) : - echo $this_data; - else : - echo ''; - endif; - break; case "is_in_stock" : - if ( !$product->is_type( 'grouped' ) && $product->is_in_stock() ) echo 'yes'; - else echo ''; - break; - case "inventory" : - if ( $product->managing_stock() ) : - echo $product->stock.' in stock'; + if ( !$product->is_type( 'grouped' ) && $product->is_in_stock() ) : + echo 'yes '; else : - echo ''; + echo 'no '; + endif; + if ( $product->managing_stock() ) : + echo $product->stock.__(' in stock', 'woothemes'); endif; break; case "product_type" : echo ucwords($product->product_type); break; + case "product_date" : + if ( '0000-00-00 00:00:00' == $post->post_date ) : + $t_time = $h_time = __( 'Unpublished' ); + $time_diff = 0; + else : + $t_time = get_the_time( __( 'Y/m/d g:i:s A' ) ); + $m_time = $post->post_date; + $time = get_post_time( 'G', true, $post ); + + $time_diff = time() - $time; + + if ( $time_diff > 0 && $time_diff < 24*60*60 ) + $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) ); + else + $h_time = mysql2date( __( 'Y/m/d' ), $m_time ); + endif; + + echo '' . apply_filters( 'post_date_column_time', $h_time, $post, $column_name, $mode ) . '
'; + + if ( 'publish' == $post->post_status ) : + _e( 'Published' ); + elseif ( 'future' == $post->post_status ) : + if ( $time_diff > 0 ) : + echo '' . __( 'Missed schedule' ) . ''; + else : + _e( 'Scheduled' ); + endif; + else : + _e( 'Last Modified' ); + endif; + + if ( $this_data = $product->visibility ) : + echo '
' . ucfirst($this_data); + endif; + + break; } } @@ -217,10 +242,11 @@ add_filter("manage_edit-product_sortable_columns", 'woocommerce_custom_product_s function woocommerce_custom_product_sort($columns) { $custom = array( - 'inventory' => 'inventory', + 'is_in_stock' => 'inventory', 'price' => 'price', 'featured' => 'featured', - 'sku' => 'sku' + 'sku' => 'sku', + 'product_date' => 'date' ); return wp_parse_args($custom, $columns); } @@ -269,22 +295,42 @@ add_action('restrict_manage_posts','woocommerce_products_by_category'); function woocommerce_products_by_category() { global $typenow, $wp_query; - if ($typenow=='product') { - - $terms = get_terms('product_cat'); - $output = ""; - echo $output; - - } + if ($typenow=='product') : + $terms = get_terms('product_cat'); + $output = ""; + echo $output; + endif; } +/** + * Filter products by type + **/ +add_action('restrict_manage_posts', 'woocommerce_products_by_type'); + +function woocommerce_products_by_type() { + global $typenow, $wp_query; + if ($typenow=='product') : + $terms = get_terms('product_type'); + $output = ""; + echo $output; + endif; +} + + /** * Columns for order page diff --git a/assets/css/admin.css b/assets/css/admin.css index 59b6ec9596f..f94b1c8d1a7 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -62,11 +62,11 @@ ul.subsubsub li.onhold a{color:red;} ul.subsubsub li.cancelled a{color:#dfdfdf;} ul.subsubsub li.refunded a{color:#ccc;} table.wp-list-table .column-thumb{width:66px;text-align:center;white-space:nowrap;} -table.wp-list-table .column-sku{width:100px;} -table.wp-list-table img{margin:2px 0;} -table.wp-list-table .column-thumb img{padding:2px;border:1px solid #dfdfdf;vertical-align:middle;width:42px;height:42px;} +table.wp-list-table .column-title{width:25%;} +table.wp-list-table img{margin:1px 2px;} +table.wp-list-table .column-thumb img{padding:2px;margin:0;border:1px solid #dfdfdf;vertical-align:middle;width:42px;height:42px;} table.wp-list-table span.na{color:#999;} -table.wp-list-table .column-featured,table.wp-list-table .column-sellable,table.wp-list-table .column-is_in_stock{text-align:center !important;} +table.wp-list-table .column-featured,table.wp-list-table .column-is_in_stock{text-align:left !important;} #dashboard_right_now p.woocommerce_sub{position:static;top:auto;left:auto;margin:15px 5px 0;padding:0 0 5px 0;border-bottom:#ECECEC 1px solid;} #dashboard_right_now .onhold{color:red;} #dashboard_right_now .pending{color:#e66f00;} diff --git a/assets/css/admin.less b/assets/css/admin.less index 55a91d11778..9bd263a158e 100644 --- a/assets/css/admin.less +++ b/assets/css/admin.less @@ -334,29 +334,34 @@ ul.subsubsub { } /* Product list */ -table.wp-list-table .column-thumb { - width: 66px; - text-align: center; - white-space: nowrap -} -table.wp-list-table .column-sku { - width: 100px; -} -table.wp-list-table img { - margin: 2px 0; -} -table.wp-list-table .column-thumb img { - padding: 2px; - border: 1px solid #dfdfdf; - vertical-align: middle; - width: 42px; - height: 42px; -} -table.wp-list-table span.na { - color: #999; -} -table.wp-list-table .column-featured, table.wp-list-table .column-sellable, table.wp-list-table .column-is_in_stock { - text-align: center !important; +table.wp-list-table { + .column-thumb { + width: 66px; + text-align: center; + white-space: nowrap + } + .column-title { + width: 25%; + } + .column-sku { + } + img { + margin: 1px 2px; + } + .column-thumb img { + padding: 2px; + margin: 0; + border: 1px solid #dfdfdf; + vertical-align: middle; + width: 42px; + height: 42px; + } + span.na { + color: #999; + } + .column-featured, .column-is_in_stock { + text-align: left !important; + } } /* Dashboard */