Skip to content

Instantly share code, notes, and snippets.

@Mamaduka
Created February 23, 2012 19:16
Show Gist options
  • Save Mamaduka/1894448 to your computer and use it in GitHub Desktop.
Save Mamaduka/1894448 to your computer and use it in GitHub Desktop.
Separate WooCommerce Right Now dashboard widget.
<?php
/*
Plugin Name: Mamaduka WooCommerce Right Now Widget
Plugin URI: http://mamaduka.wordpress.com/
Description: Code for separated WooCommerce Right Now widget.
Version: 0.1
Author: George Mamadashvili
Author URI: http://mamaduka.wordpress.com/
*/
/**
* WooCommerce Right Now widget.
* Adds a dashboard widget with shop statistics.
*
* @since WooCommerce 1.4.x
*/
function woocommerce_dashboard_widget_right_now() {
global $woocommerce;
$product_count = wp_count_posts( 'product' );
$product_cat_count = wp_count_terms( 'product_cat' );
$product_tag_count = wp_count_terms( 'product_tag' );
$product_attr_count = count( $woocommerce->get_attribute_taxonomies() );
$pending_count = get_term_by( 'slug', 'pending', 'shop_order_status' )->count;
$completed_count = get_term_by( 'slug', 'completed', 'shop_order_status' )->count;
$on_hold_count = get_term_by( 'slug', 'on-hold', 'shop_order_status' )->count;
$processing_count = get_term_by( 'slug', 'processing', 'shop_order_status' )->count;
?>
<div class="table table_shop_content">
<p class="sub woocommerce_sub"><?php _e( 'Shop Content', 'woocommerce' ); ?></p>
<table>
<tr class="first">
<?php
$num = number_format_i18n( $product_count->publish );
$text = _n( 'Product', 'Products', intval($product_count->publish), 'woocommerce' );
$link = add_query_arg( array( 'post_type' => 'product' ), get_admin_url( null, 'edit.php' ) );
$num = '<a href="' . $link . '">' . $num . '</a>';
$text = '<a href="' . $link . '">' . $text . '</a>';
?>
<td class="first b b-products"><?php echo $num; ?></td>
<td class="t products"><?php echo $text; ?></td>
</tr>
<tr>
<?php
$num = number_format_i18n( $product_cat_count );
$text = _n( 'Product Category', 'Product Categories', $product_cat_count, 'woocommerce' );
$link = add_query_arg( array( 'taxonomy' => 'product_cat', 'post_type' => 'product' ), get_admin_url( null, 'edit-tags.php' ) );
$num = '<a href="' . $link . '">' . $num . '</a>';
$text = '<a href="' . $link . '">' . $text . '</a>';
?>
<td class="first b b-product_cats"><?php echo $num; ?></td>
<td class="t product_cats"><?php echo $text; ?></td>
</tr>
<tr>
<?php
$num = number_format_i18n( $product_tag_count );
$text = _n( 'Product Tag', 'Product Tags', $product_tag_count, 'woocommerce' );
$link = add_query_arg( array( 'taxonomy' => 'product_tag', 'post_type' => 'product' ), get_admin_url( null, 'edit-tags.php' ) );
$num = '<a href="' . $link . '">' . $num . '</a>';
$text = '<a href="' . $link . '">' . $text . '</a>';
?>
<td class="first b b-product_tags"><?php echo $num; ?></td>
<td class="t product_tags"><?php echo $text; ?></td>
</tr>
<tr>
<?php
$num = number_format_i18n( $product_attr_count );
$text = _n( 'Attribute', 'Attributes', $product_attr_count, 'woocommerce' );
$link = add_query_arg( array( 'page' => 'woocommerce_attributes' ), get_admin_url( null, 'admin.php' ) );
$num = '<a href="' . $link . '">' . $num . '</a>';
$text = '<a href="' . $link . '">' . $text . '</a>';
?>
<td class="first b b-attributes"><?php echo $num; ?></td>
<td class="t attributes"><?php echo $text; ?></td>
</tr>
<?php do_action( 'woocommerce_right_now_shop_content_table_end' ); ?>
</table>
</div>
<div class="table table_orders">
<p class="sub woocommerce_sub"><?php _e( 'Orders', 'woocommerce' ); ?></p>
<table>
<tr class="first">
<?php
$num = number_format_i18n( $pending_count );
$text = __( 'Pending', 'woocommerce' );
$link = add_query_arg( array( 'post_type' => 'shop_order', 'shop_order_status' => 'pending' ), get_admin_url( null, 'edit.php' ) );
$num = '<a href="' . $link . '">' . $num . '</a>';
$text = '<a href="' . $link . '">' . $text . '</a>';
?>
<td class="b b-pending"><?php echo $num; ?></td>
<td class="last t pending"><?php echo $text; ?></td>
</tr>
<tr>
<?php
$num = number_format_i18n( $on_hold_count );
$text = __( 'On-Hold', 'woocommerce' );
$link = add_query_arg( array( 'post_type' => 'shop_order', 'shop_order_status' => 'on-hold' ), get_admin_url( null, 'edit.php' ) );
$num = '<a href="' . $link . '">' . $num . '</a>';
$text = '<a href="' . $link . '">' . $text . '</a>';
?>
<td class="b b-on-hold"><?php echo $num; ?></td>
<td class="last t on-hold"><?php echo $text; ?></td>
</tr>
<tr>
<?php
$num = number_format_i18n( $processing_count );
$text = __( 'Processing', 'woocommerce' );
$link = add_query_arg( array( 'post_type' => 'shop_order', 'shop_order_status' => 'processing' ), get_admin_url( null, 'edit.php' ) );
$num = '<a href="' . $link . '">' . $num . '</a>';
$text = '<a href="' . $link . '">' . $text . '</a>';
?>
<td class="b b-processing"><?php echo $num; ?></td>
<td class="last t processing"><?php echo $text; ?></td>
</tr>
<tr>
<?php
$num = number_format_i18n( $completed_count );
$text = __( 'Completed', 'woocommerce' );
$link = add_query_arg( array( 'taxonomy' => 'product_cat', 'post_type' => 'completed' ), get_admin_url( null, 'edit-tags.php' ) );
$num = '<a href="' . $link . '">' . $num . '</a>';
$text = '<a href="' . $link . '">' . $text . '</a>';
?>
<td class="b b-completed"><?php echo $num; ?></td>
<td class="last t completed"><?php echo $text; ?></td>
</tr>
<?php do_action( 'woocommerce_right_now_orders_table_end' ); ?>
</table>
</div>
<div class="versions">
<span id="wp-version-message">
<?php printf( __( 'You are using <span class="b">WooCommerce %s</span>.', 'woocommerce' ), WOOCOMMERCE_VERSION ); ?>
</span>
</div>
<br class="clear" />
<?php
}
// Init
function mamaduka_dashboard_widgets_init() {
wp_add_dashboard_widget( 'woocommerce_dashboard_right_now', __( 'WooCommerce Right Now', 'woocommerce' ), 'woocommerce_dashboard_widget_right_now' );
}
add_action( 'wp_dashboard_setup', 'mamaduka_dashboard_widgets_init' );
// Enqueue style for WC Right Now Widget
function mamaduka_wc_print_styles() {
?>
<style type="text/css" media="screen">
/*<![CDATA[*/
#woocommerce_dashboard_right_now p.sub,
#woocommerce_dashboard_right_now .table, #woocommerce_dashboard_right_now .versions {
margin: -12px;
}
#woocommerce_dashboard_right_now .inside {
font-size: 12px;
padding-top: 20px;
}
#woocommerce_dashboard_right_now p.sub {
padding: 5px 0 15px;
color: #8f8f8f;
font-size: 14px;
position: absolute;
top: -17px;
left: 15px;
}
#woocommerce_dashboard_right_now .table {
margin: 0;
padding: 0;
position: relative;
}
#woocommerce_dashboard_right_now .table_shop_content {
float: left;
border-top: #ececec 1px solid;
width: 45%;
}
#woocommerce_dashboard_right_now .table_orders {
float: right;
border-top: #ececec 1px solid;
width: 45%;
}
#woocommerce_dashboard_right_now table td {
padding: 3px 0;
white-space: nowrap;
}
#woocommerce_dashboard_right_now table tr.first td {
border-top: none;
}
#woocommerce_dashboard_right_now td.b {
padding-right: 6px;
text-align: right;
font-family: Georgia, "Times New Roman", "Bitstream Charter", Times, serif;
font-size: 14px;
width: 1%;
}
#woocommerce_dashboard_right_now td.b a {
font-size: 18px;
}
#woocommerce_dashboard_right_now td.b a:hover {
color: #d54e21;
}
#woocommerce_dashboard_right_now .t {
font-size: 12px;
padding-right: 12px;
padding-top: 6px;
color: #777;
}
#woocommerce_dashboard_right_now .t a {
white-space: nowrap;
}
#woocommerce_dashboard_right_now .on-hold a {
color: red;
}
#woocommerce_dashboard_right_now .pending a {
color: #e66f00;
}
#woocommerce_dashboard_right_now .completed a {
color: green;
}
#woocommerce_dashboard_right_now .versions a {
padding: 6px 10px 12px;
clear: both;
}
#woocommerce_dashboard_right_now a.button {
float: right;
clear: right;
position: relative;
top: -5px;
}
/*]]>*/
</style>
<?php
}
add_action( 'admin_head', 'mamaduka_wc_print_styles' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment