-
Notifications
You must be signed in to change notification settings - Fork 12
/
order-form.php
163 lines (148 loc) · 6.33 KB
/
order-form.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
<?php
/**
* Форма заказа
*/
// ---------------------- Регистрация типа данных ----------------------
define('SIMPLE_BASKET_ORDER_TYPE', 'simple_basket_order');
add_action( 'init', 'createOrderPost', 0);
function createOrderPost()
{
$labels = array(
'name' => __( 'Orders', 'simple_basket' ),
'singular_name' => __( 'Order', 'simple_basket' ),
'menu_name' => __( 'Orders', 'simple_basket' ),
'all_items' => __( 'All orders', 'simple_basket' ),
'view_item' => __( 'View orders', 'simple_basket' ),
'add_new_item' => __( 'Add new order', 'simple_basket' ),
'add_new' => __( 'New order', 'simple_basket' ),
'edit_item' => __( 'Edit order', 'simple_basket' ),
'update_item' => __( 'Update order', 'simple_basket' ),
'search_items' => __( 'Search order', 'simple_basket' ),
'not_found' => __( 'No orders found', 'simple_basket' ),
'not_found_in_trash' => __( 'No orders found in Trash', 'simple_basket' ),
);
$args = array(
'label' => __( 'Order', 'simple_basket' ),
'description' => __( 'Orders', 'simple_basket' ),
'labels' => $labels,
'supports' => array( 'title', 'author', 'custom-fields', 'editor'),
'taxonomies' => array(),
'hierarchical' => false,
'public' => false,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => false,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => plugins_url('/img/order-icon16x16.png', __FILE__ ),
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => true,
'publicly_queryable' => false,
'rewrite' => false,
'capability_type' => 'post',
);
register_post_type(SIMPLE_BASKET_ORDER_TYPE, $args);
}
// Иконка на странице аминистрирования
add_action('admin_head', 'simple_basket_admin_order_css');
function simple_basket_admin_order_css()
{ ?>
<style type="text/css">
.icon32-posts-simple_basket_order {
background: url('/wp-content/plugins/simple-basket/img/order-icon32x32.png') no-repeat !important;
}
</style>
<?php
}
// Register Status Taxonomy
define('SIMPLE_BASKET_ORDER_STATUS', 'simple_basket_status');
add_action( 'init', 'createOrderTaxonomy', 0 );
function createOrderTaxonomy()
{
$labels = array(
'name' => __( 'Statuses', 'simple_basket' ),
'singular_name' => __( 'Status', 'simple_basket' ),
'menu_name' => __( 'Status', 'simple_basket' ),
'all_items' => __( 'All Statuses', 'simple_basket' ),
'parent_item' => __( 'Parent Status', 'simple_basket' ),
'parent_item_colon' => __( 'Parent Status:', 'simple_basket' ),
'new_item_name' => __( 'New Status Name', 'simple_basket' ),
'add_new_item' => __( 'Add New Status', 'simple_basket' ),
'edit_item' => __( 'Edit Status', 'simple_basket' ),
'update_item' => __( 'Update Status', 'simple_basket' ),
'separate_items_with_commas' => __( 'Separate statuses with commas', 'simple_basket' ),
'search_items' => __( 'Search statuses', 'simple_basket' ),
'add_or_remove_items' => __( 'Add or remove statuses', 'simple_basket' ),
'choose_from_most_used' => __( 'Choose from the most used statuses', 'simple_basket' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => false,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => false,
'show_tagcloud' => false,
'rewrite' => false,
);
register_taxonomy(SIMPLE_BASKET_ORDER_STATUS, SIMPLE_BASKET_ORDER_TYPE, $args);
// Статусы по уумолчанию
$defaultStatuses = array(
'new' => array('title' => __('New', 'simple_basket'), 'description' => __('New Order', 'simple_basket')),
'in_process' => array('title' => __('In Process', 'simple_basket'), 'description' => __('Order In Process', 'simple_basket')),
'completed' => array('title' => __('Completed', 'simple_basket'), 'description' => __('Order Completed', 'simple_basket')),
'canceled' => array('title' => __('Canceled', 'simple_basket'), 'description' => __('Order Canceled', 'simple_basket')),
);
foreach ($defaultStatuses as $slug => $status)
{
if (!term_exists($status['title'], SIMPLE_BASKET_ORDER_STATUS))
{
wp_insert_term(
$status['title'], // the term
SIMPLE_BASKET_ORDER_STATUS, // the taxonomy
array(
'description' => $status['description'],
'slug' => $slug,
'parent' => 0
));
}
}
}
// Дополнительные колонки в таблице заказов
define('SIMPLE_BASKET_COLUMN_ORDER_SUMM', 'colOrderSumm');
add_filter('manage_' . SIMPLE_BASKET_ORDER_TYPE . '_posts_columns', 'getOrderColumnsHead');
add_action('manage_' . SIMPLE_BASKET_ORDER_TYPE . '_posts_custom_column', 'showOrderColumnsContent', 10, 2);
// Названия колонок в таблице заказов
function getOrderColumnsHead($defaults)
{
// Изменяем существующие колонки
$defaults['title'] = __('Order Code', 'simple_basket');
$defaults['author'] = __('Customer', 'simple_basket');
// Добавляем новые колонки
$defaults[SIMPLE_BASKET_COLUMN_ORDER_SUMM] = __('Summ', 'simple_basket');
return $defaults;
}
// Вывод данных в таблице заказов
function showOrderColumnsContent($column_name, $postId)
{
switch ($column_name)
{
case SIMPLE_BASKET_COLUMN_ORDER_SUMM:
echo simple_basket_custom_fields($postId, __('Summ', 'simple_basket')), ' ',
/* translators: please replace USD by your country currency */
__('USD', 'simple_basket');
break;
}
}
// Свойства заказа (произвольные поля) по умолчанию при ручном добавлении
add_action('wp_insert_post', 'setOrderDefaults');
function setOrderDefaults($postId)
{
if (isset($_GET['post_type']) && $_GET['post_type'] == SIMPLE_BASKET_ORDER_TYPE)
{
add_post_meta($postId, __('Summ', 'simple_basket'), '0', true);
}
return true;
}
?>