forked from jigoshop/jigoshop
/
jigoshop-admin-post-types.php
350 lines (295 loc) · 12.5 KB
/
jigoshop-admin-post-types.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<?php
/**
* Functions used for custom post types in admin
*
* These functions control columns in admin, and other admin interface bits
*
* DISCLAIMER
*
* Do not edit or add directly to this file if you wish to upgrade Jigoshop to newer
* versions in the future. If you wish to customise Jigoshop core for your needs,
* please use our GitHub repository to publish essential changes for consideration.
*
* @package Jigoshop
* @category Admin
* @author Jigowatt
* @copyright Copyright (c) 2011 Jigowatt Ltd.
* @license http://jigoshop.com/license/commercial-edition
/**
* Custom columns
**/
function jigoshop_edit_variation_columns($columns){
$columns = array();
$columns["cb"] = "<input type=\"checkbox\" />";
$columns["thumb"] = __("Thumb", 'jigoshop');
$columns["id"] = __("ID", 'jigoshop');
$columns["title"] = __("Name", 'jigoshop');
$columns["parent"] = __("Parent Product", 'jigoshop');
return $columns;
}
add_filter('manage_edit-product_variation_columns', 'jigoshop_edit_variation_columns');
function jigoshop_custom_variation_columns($column) {
global $post;
$product = &new jigoshop_product($post->ID);
switch ($column) {
case "thumb" :
if (has_post_thumbnail($post->ID)) :
echo get_the_post_thumbnail($post->ID, 'shop_tiny');
endif;
break;
case "id" :
echo '#'.$post->ID;
break;
case "parent" :
if ($post->post_parent) :
$parent = get_post( $post->post_parent );
echo '#'.$parent->ID.' — <a href="'.admin_url('post.php?post='.$parent->ID.'&action=edit').'">'.$parent->post_title.'</a>';
endif;
break;
}
}
add_action('manage_product_variation_posts_custom_column', 'jigoshop_custom_variation_columns', 2);
function jigoshop_edit_product_columns($columns){
$columns = array();
$columns["cb"] = "<input type=\"checkbox\" />";
$columns["thumb"] = __("Thumb", 'jigoshop');
$columns["title"] = __("Name", 'jigoshop');
$columns["product_type"] = __("Type", 'jigoshop');
$columns["sku"] = __("ID/SKU", 'jigoshop');
$columns["product_cat"] = __("Category", 'jigoshop');
$columns["product_tags"] = __("Tags", 'jigoshop');
$columns["visibility"] = __("Visibility", 'jigoshop');
$columns["featured"] = __("Featured", 'jigoshop');
if (get_option('jigoshop_manage_stock')=='yes') :
$columns["is_in_stock"] = __("In Stock?", 'jigoshop');
$columns["inventory"] = __("Inventory", 'jigoshop');
endif;
$columns["price"] = __("Price", 'jigoshop');
return $columns;
}
add_filter('manage_edit-product_columns', 'jigoshop_edit_product_columns');
function jigoshop_custom_product_columns($column) {
global $post;
$product = &new jigoshop_product($post->ID);
switch ($column) {
case "thumb" :
if (has_post_thumbnail($post->ID)) :
echo get_the_post_thumbnail($post->ID, 'shop_tiny');
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', '', ', ','');
break;
case "product_tags" :
echo get_the_term_list($post->ID, 'product_tag', '', ', ','');
break;
case "sku" :
if ( $sku = get_post_meta( $post->ID, 'SKU', true )) :
echo '#'.$post->ID.' - SKU: ' . $sku;
else :
echo '#'.$post->ID;
endif;
break;
case "featured" :
$url = wp_nonce_url( admin_url('admin-ajax.php?action=jigoshop-feature-product&product_id=' . $post->ID) );
echo '<a href="'.$url.'" title="'.__('Change','jigoshop') .'">';
if ($product->is_featured()) echo '<a href="'.$url.'"><img src="'.jigoshop::plugin_url().'/assets/images/success.gif" alt="yes" />';
else echo '<img src="'.jigoshop::plugin_url().'/assets/images/success-off.gif" alt="no" />';
echo '</a>';
break;
case "visibility" :
if ( $this_data = $product->visibility ) :
echo $this_data;
else :
echo '<span class="na">–</span>';
endif;
break;
case "is_in_stock" :
if ( !$product->is_type( 'grouped' ) && $product->is_in_stock() ) echo '<img src="'.jigoshop::plugin_url().'/assets/images/success.gif" alt="yes" />';
else echo '<span class="na">–</span>';
break;
case "inventory" :
if ( $product->managing_stock() ) :
echo $product->stock.' in stock';
else :
echo '<span class="na">–</span>';
endif;
break;
case "product_type" :
echo ucwords($product->product_type);
break;
case "id" :
echo '#'.$post->ID;
break;
}
}
add_action('manage_product_posts_custom_column', 'jigoshop_custom_product_columns', 2);
function jigoshop_edit_order_columns($columns){
$columns = array();
//$columns["cb"] = "<input type=\"checkbox\" />";
$columns["order_status"] = __("Status", 'jigoshop');
$columns["order_title"] = __("Order", 'jigoshop');
$columns["customer"] = __("Customer", 'jigoshop');
$columns["billing_address"] = __("Billing Address", 'jigoshop');
$columns["shipping_address"] = __("Shipping Address", 'jigoshop');
$columns["billing_and_shipping"] = __("Billing & Shipping", 'jigoshop');
$columns["total_cost"] = __("Order Cost", 'jigoshop');
return $columns;
}
add_filter('manage_edit-shop_order_columns', 'jigoshop_edit_order_columns');
function jigoshop_custom_order_columns($column) {
global $post;
$order = &new jigoshop_order( $post->ID );
switch ($column) {
case "order_status" :
echo sprintf( __('<mark class="%s">%s</mark>', 'jigoshop'), sanitize_title($order->status), $order->status );
break;
case "order_title" :
echo '<a href="'.admin_url('post.php?post='.$post->ID.'&action=edit').'">'.sprintf( __('Order #%s', 'jigoshop'), $post->ID ).'</a>';
echo '<time title="'.date_i18n('c', strtotime($post->post_date)).'">'.date_i18n('F j, Y, g:i a', strtotime($post->post_date)).'</time>';
break;
case "customer" :
if ($order->user_id) $user_info = get_userdata($order->user_id);
?>
<dl>
<dt><?php _e('User:', 'jigoshop'); ?></dt>
<dd><?php
if (isset($user_info) && $user_info) :
echo '<a href="user-edit.php?user_id='.$user_info->ID.'">#'.$user_info->ID.' – <strong>';
if ($user_info->first_name || $user_info->last_name) echo $user_info->first_name.' '.$user_info->last_name;
else echo $user_info->display_name;
echo '</strong></a>';
else :
_e('Guest', 'jigoshop');
endif;
?></dd>
<?php if ($order->billing_email) : ?><dt><?php _e('Billing Email:', 'jigoshop'); ?></dt>
<dd><a href="mailto:<?php echo $order->billing_email; ?>"><?php echo $order->billing_email; ?></a></dd><?php endif; ?>
<?php if ($order->billing_phone) : ?><dt><?php _e('Billing Tel:', 'jigoshop'); ?></dt>
<dd><?php echo $order->billing_phone; ?></dd><?php endif; ?>
</dl>
<?php
break;
case "billing_address" :
echo '<strong>'.$order->billing_first_name . ' ' . $order->billing_last_name;
if ($order->billing_company) echo ', '.$order->billing_company;
echo '</strong><br/>';
echo '<a target="_blank" href="http://maps.google.co.uk/maps?&q='.urlencode($order->formatted_billing_address).'&z=16">'.$order->formatted_billing_address.'</a>';
break;
case "shipping_address" :
if ($order->formatted_shipping_address) :
echo '<strong>'.$order->shipping_first_name . ' ' . $order->shipping_last_name;
if ($order->shipping_company) : echo ', '.$order->shipping_company; endif;
echo '</strong><br/>';
echo '<a target="_blank" href="http://maps.google.co.uk/maps?&q='.urlencode($order->formatted_shipping_address).'&z=16">'.$order->formatted_shipping_address.'</a>';
else :
echo '–';
endif;
break;
case "billing_and_shipping" :
?>
<dl>
<dt><?php _e('Payment:', 'jigoshop'); ?></dt>
<dd><?php echo $order->payment_method; ?></dd>
<dt><?php _e('Shipping:', 'jigoshop'); ?></dt>
<dd><?php echo $order->shipping_method; ?></dd>
</dl>
<?php
break;
case "total_cost" :
?>
<table cellpadding="0" cellspacing="0" class="cost">
<tr>
<th><?php _e('Subtotal', 'jigoshop'); ?></th>
<td><?php echo jigoshop_price($order->order_subtotal); ?></td>
</tr>
<?php if ($order->order_shipping>0) : ?><tr>
<th><?php _e('Shipping', 'jigoshop'); ?></th>
<td><?php echo jigoshop_price($order->order_shipping); ?></td>
</tr><?php endif; ?>
<?php if ($order->get_total_tax()>0) : ?><tr>
<th><?php _e('Tax', 'jigoshop'); ?></th>
<td><?php echo jigoshop_price($order->get_total_tax()); ?></td>
</tr><?php endif; ?>
<?php if ($order->order_discount>0) : ?><tr>
<th><?php _e('Discount', 'jigoshop'); ?></th>
<td><?php echo jigoshop_price($order->order_discount); ?></td>
</tr><?php endif; ?>
<tr>
<th><?php _e('Total', 'jigoshop'); ?></th>
<td><?php echo jigoshop_price($order->order_total); ?></td>
</tr>
</table>
<?php
break;
}
}
add_action('manage_shop_order_posts_custom_column', 'jigoshop_custom_order_columns', 2);
/**
* Order page filters
**/
function jigoshop_custom_order_views( $views ) {
$jigoshop_orders = &new jigoshop_orders();
$pending = (isset($_GET['shop_order_status']) && $_GET['shop_order_status']=='pending') ? 'current' : '';
$onhold = (isset($_GET['shop_order_status']) && $_GET['shop_order_status']=='on-hold') ? 'current' : '';
$processing = (isset($_GET['shop_order_status']) && $_GET['shop_order_status']=='processing') ? 'current' : '';
$completed = (isset($_GET['shop_order_status']) && $_GET['shop_order_status']=='completed') ? 'current' : '';
$cancelled = (isset($_GET['shop_order_status']) && $_GET['shop_order_status']=='cancelled') ? 'current' : '';
$refunded = (isset($_GET['shop_order_status']) && $_GET['shop_order_status']=='refunded') ? 'current' : '';
$views['pending'] = '<a class="'.$pending.'" href="?post_type=shop_order&shop_order_status=pending">Pending <span class="count">('.$jigoshop_orders->pending_count.')</span></a>';
$views['onhold'] = '<a class="'.$onhold.'" href="?post_type=shop_order&shop_order_status=on-hold">On-Hold <span class="count">('.$jigoshop_orders->on_hold_count.')</span></a>';
$views['processing'] = '<a class="'.$processing.'" href="?post_type=shop_order&shop_order_status=processing">Processing <span class="count">('.$jigoshop_orders->processing_count.')</span></a>';
$views['completed'] = '<a class="'.$completed.'" href="?post_type=shop_order&shop_order_status=completed">Completed <span class="count">('.$jigoshop_orders->completed_count.')</span></a>';
$views['cancelled'] = '<a class="'.$cancelled.'" href="?post_type=shop_order&shop_order_status=cancelled">Cancelled <span class="count">('.$jigoshop_orders->cancelled_count.')</span></a>';
$views['refunded'] = '<a class="'.$refunded.'" href="?post_type=shop_order&shop_order_status=refunded">Refunded <span class="count">('.$jigoshop_orders->refunded_count.')</span></a>';
if ($pending || $onhold || $processing || $completed || $cancelled || $refunded) :
$views['all'] = str_replace('current', '', $views['all']);
endif;
unset($views['publish']);
if (isset($views['trash'])) :
$trash = $views['trash'];
unset($views['draft']);
unset($views['trash']);
$views['trash'] = $trash;
endif;
return $views;
}
add_filter('views_edit-shop_order', 'jigoshop_custom_order_views');
/**
* Order page actions
**/
function jigoshop_remove_row_actions( $actions ) {
if( get_post_type() === 'shop_order' ) :
unset( $actions['view'] );
unset( $actions['inline hide-if-no-js'] );
endif;
return $actions;
}
add_filter( 'post_row_actions', 'jigoshop_remove_row_actions', 10, 1 );
/**
* Order page views
**/
function jigoshop_bulk_actions( $actions ) {
return array();
}
add_filter( 'bulk_actions-edit-shop_order', 'jigoshop_bulk_actions' );
/**
* Order messages
**/
function jigoshop_post_updated_messages( $messages ) {
if( get_post_type() === 'shop_order' ) :
$messages['post'][1] = sprintf( __('Order updated.', 'jigoshop') );
$messages['post'][4] = sprintf( __('Order updated.', 'jigoshop') );
$messages['post'][6] = sprintf( __('Order published.', 'jigoshop') );
$messages['post'][8] = sprintf( __('Order submitted.', 'jigoshop') );
$messages['post'][10] = sprintf( __('Order draft updated.', 'jigoshop') );
endif;
return $messages;
}
add_filter( 'post_updated_messages', 'jigoshop_post_updated_messages' );