1 <?php
2 3 4 5 6 7 8 9 10
11
12
13 if ( ! defined( 'ABSPATH' ) ) exit;
14
15 16 17 18 19 20 21
22 function edd_register_dashboard_widgets() {
23 if ( current_user_can( apply_filters( 'edd_dashboard_stats_cap', 'edit_pages' ) ) ) {
24 wp_add_dashboard_widget( 'edd_dashboard_sales', __('Easy Digital Downloads Sales Summary', 'edd'), 'edd_dashboard_sales_widget' );
25 }
26 }
27 add_action('wp_dashboard_setup', 'edd_register_dashboard_widgets' );
28
29 30 31 32 33 34 35 36 37 38 39
40 function edd_dashboard_sales_widget() {
41 $top_selling_args = array(
42 'post_type' => 'download',
43 'posts_per_page' => 1,
44 'post_status' => 'publish',
45 'meta_key' => '_edd_download_sales',
46 'meta_compare' => '>',
47 'meta_value' => 0,
48 'orderby' => 'meta_value_num',
49 'update_post_term_cache' => false,
50 'order' => 'DESC'
51 );
52
53 $top_selling = get_posts( $top_selling_args );
54 ?>
55 <div class="edd_dashboard_widget">
56 <div class="table table_left table_current_month">
57 <p class="sub"><?php _e( 'Current Month', 'edd' ) ?></p>
58 <table>
59 <tbody>
60 <tr class="first">
61 <td class="first b"><?php echo edd_currency_filter( edd_format_amount( edd_get_earnings_by_date( null, date( 'n' ), date( 'Y' ) ) ) ); ?></td>
62 <td class="t monthly_earnings"><?php _e( 'Earnings', 'edd' ); ?></td>
63 </tr>
64 <tr>
65 <?php $monthly_sales = edd_get_sales_by_date( null, date( 'n' ), date( 'Y' ) ); ?>
66 <td class="first b"><?php echo $monthly_sales; ?></td>
67 <td class="t monthly_sales"><?php echo _n( 'Sale', 'Sales', $monthly_sales, 'edd' ); ?></td>
68 </tr>
69 </tbody>
70 </table>
71 <p class="label_heading"><?php _e( 'Last Month', 'edd' ) ?></p>
72 <?php
73 $previous_month = date( 'n' ) == 1 ? 12 : date( 'n' ) - 1;
74 $previous_year = $previous_month == 12 ? date( 'Y' ) - 1 : date( 'Y' );
75 ?>
76 <div>
77 <?php echo __( 'Earnings', 'edd' ) . ': <span class="edd_price_label">' . edd_currency_filter( edd_format_amount( edd_get_earnings_by_date( null, $previous_month, $previous_year ) ) ) . '</span>'; ?>
78 </div>
79 <div>
80 <?php $last_month_sales = edd_get_sales_by_date( null, $previous_month, $previous_year ); ?>
81 <?php echo _n( 'Sale', 'Sales', $last_month_sales, 'edd' ) . ': ' . '<span class="edd_price_label">' . $last_month_sales . '</span>'; ?>
82 </div>
83 </div>
84 <div class="table table_right table_totals">
85 <p class="sub"><?php _e( 'Totals', 'edd' ) ?></p>
86 <table>
87 <tbody>
88 <tr class="first">
89 <td class="b b-earnings"><?php echo edd_currency_filter( edd_format_amount( edd_get_total_earnings() ) ); ?></td>
90 <td class="last t earnings"><?php _e( 'Total Earnings', 'edd' ); ?></td>
91 </tr>
92 <tr>
93 <td class="b b-sales"><?php echo edd_get_total_sales(); ?></td>
94 <td class="last t sales"><?php _e( 'Total Sales', 'edd' ); ?></td>
95 </tr>
96 </tbody>
97 </table>
98 <?php if ( $top_selling ) {
99 foreach( $top_selling as $list ) { ?>
100 <p class="lifetime_best_selling label_heading"><?php _e('Lifetime Best Selling', 'edd') ?></p>
101 <p><span class="lifetime_best_selling_label"><?php echo edd_get_download_sales_stats( $list->ID ); ?></span> <a href="<?php echo get_permalink( $list->ID ); ?>"><?php echo get_the_title( $list->ID ); ?></a></p>
102 <?php } } ?>
103 </div>
104 <div style="clear: both"></div>
105 <?php
106 $payments = edd_get_payments( array(
107 'number' => 5,
108 'mode' => 'live',
109 'orderby' => 'post_date',
110 'order' => 'DESC',
111 'user' => null,
112 'status' => 'publish',
113 'meta_key' => null,
114 'fields' => 'ids',
115 ) );
116
117 if ( $payments ) { ?>
118 <p class="edd_dashboard_widget_subheading"><?php _e( 'Recent Purchases', 'edd' ); ?></p>
119 <div class="table recent_purchases">
120 <table>
121 <tbody>
122 <?php
123 foreach ( $payments as $payment ) {
124 $payment_meta = edd_get_payment_meta( $payment );
125 ?>
126 <tr>
127 <td><?php echo get_the_title( $payment ) ?> - (<?php echo $payment_meta['email'] ?>) - <span class="edd_price_label"><?php echo edd_currency_filter( edd_format_amount( edd_get_payment_amount( $payment ) ) ); ?></span> - <a href="#TB_inline?width=640&inlineId=purchased-files-<?php echo $payment; ?>" class="thickbox" title="<?php printf( __( 'Purchase Details for Payment #%s', 'edd' ), $payment ); ?> "><?php _e( 'View Order Details', 'edd' ); ?></a>
128 <div id="purchased-files-<?php echo $payment; ?>" style="display:none;">
129 <?php
130 $cart_items = edd_get_payment_meta_cart_details( $payment );
131 if ( empty( $cart_items ) || !$cart_items ) {
132 $cart_items = maybe_unserialize( $payment_meta['downloads'] );
133 }
134 ?>
135 <h4><?php echo _n( __( 'Purchased File', 'edd' ), __( 'Purchased Files', 'edd' ), count( $cart_items ) ); ?></h4>
136 <ul class="purchased-files-list">
137 <?php
138 if ( $cart_items ) {
139 foreach ( $cart_items as $key => $cart_item ) {
140 echo '<li>';
141 $id = isset( $payment_meta['cart_details'] ) ? $cart_item['id'] : $cart_item;
142 $price_override = isset( $payment_meta['cart_details'] ) ? $cart_item['price'] : null;
143 $user_info = edd_get_payment_meta_user_info( $payment );
144 $price = edd_get_download_final_price( $id, $user_info, $price_override );
145 echo '<a href="' . admin_url( 'post.php?post=' . $id . '&action=edit' ) . '" target="_blank">' . get_the_title( $id ) . '</a>';
146 echo ' - ';
147 if( isset( $cart_items[ $key ]['item_number'])) {
148 $price_options = $cart_items[ $key ]['item_number']['options'];
149 if( isset( $price_options['price_id'] ) ) {
150 echo edd_get_price_option_name( $id, $price_options['price_id'], $payment);
151 echo ' - ';
152 }
153 }
154 echo edd_currency_filter( edd_format_amount( $price ) );
155 echo '</li>';
156 }
157 }
158 ?>
159 </ul>
160 <?php $payment_date = strtotime( get_post_field( 'post_date', $payment ) ); ?>
161 <p><?php echo __( 'Date and Time:', 'edd' ) . ' ' . date_i18n( get_option( 'date_format' ), $payment_date ) . ' ' . date_i18n( get_option( 'time_format' ), $payment_date ) ?>
162 <p><?php echo __( 'Discount used:', 'edd' ) . ' '; if( isset( $user_info['discount'] ) && $user_info['discount'] != 'none' ) { echo $user_info['discount']; } else { _e( 'none', 'edd' ); } ?>
163 <?php
164 $fees = edd_get_payment_fees( $payment );
165 if( ! empty( $fees ) ) : ?>
166 <ul class="payment-fees">
167 <?php foreach( $fees as $fee ) : ?>
168 <li><?php echo $fee['label'] . ': ' . edd_currency_filter( $fee['amount'] ); ?></li>
169 <?php endforeach; ?>
170 </ul>
171 <?php endif; ?>
172 <p><?php echo __( 'Total:', 'edd' ) . ' ' . edd_currency_filter( edd_format_amount( edd_get_payment_amount( $payment ) ) ); ?></p>
173
174 <div class="purcase-personal-details">
175 <h4><?php _e( 'Buyer\'s Personal Details:', 'edd' ); ?></h4>
176 <ul>
177 <li><?php echo __( 'Name:', 'edd' ) . ' ' . $user_info['first_name'] . ' ' . $user_info['last_name']; ?></li>
178 <li><?php echo __( 'Email:', 'edd' ) . ' ' . $payment_meta['email']; ?></li>
179 <?php do_action( 'edd_payment_personal_details_list', $payment_meta, $user_info ); ?>
180 </ul>
181 </div>
182 <div class="payment-notes">
183 <h4><?php _e( 'Payment Notes', 'edd' ); ?></h4>
184 <?php
185 $notes = edd_get_payment_notes( $payment );
186 if ( ! empty( $notes ) ) :
187 echo '<ul id="payment-notes">';
188 foreach ( $notes as $note ):
189 if ( ! empty( $note->user_id ) ) {
190 $user = get_userdata( $note->user_id );
191 $user = $user->display_name;
192 } else {
193 $user = __( 'EDD Bot', 'edd' );
194 }
195 echo '<div class="edd-payment-note"><strong>' . $user . '</strong> <em>' . $note->comment_date . '</em> —' . $note->comment_content . '</div>';
196 endforeach;
197 echo '</ul>';
198 else :
199 echo '<p>' . __( 'No payment notes', 'edd' ) . '</p>';
200 endif;
201 ?>
202 </div>
203 <?php
204 $gateway = edd_get_payment_gateway( $payment );
205 if ( $gateway ) { ?>
206 <div class="payment-method">
207 <h4><?php _e( 'Payment Method:', 'edd' ); ?></h4>
208 <span class="payment-method-name"><?php echo edd_get_gateway_admin_label( $gateway ); ?></span>
209 </div>
210 <?php } ?>
211 <div class="purchase-key-wrap">
212 <h4><?php _e('Purchase Key', 'edd'); ?></h4>
213 <span class="purchase-key"><?php echo $payment_meta['key']; ?></span>
214 </div>
215
216 <?php do_action( 'edd_payment_view_details', $payment ); ?>
217
218 <p><a id="edd-close-purchase-details" class="button-secondary" onclick="tb_remove();" title="<?php _e( 'Close', 'edd' ); ?>"><?php _e( 'Close', 'edd' ); ?></a></p>
219 </div>
220 </td>
221 </tr>
222 <?php }
223 </tbody>
224 </table>
225 </div>
226 <?php }
227 </div>
228 <?php
229 }