-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction.php
337 lines (301 loc) · 14.1 KB
/
function.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
<?php
/**
* Astra functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package Astra
* @since 1.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Define Constants
*/
define( 'ASTRA_THEME_VERSION', '4.2.1' );
define( 'ASTRA_THEME_SETTINGS', 'astra-settings' );
define( 'ASTRA_THEME_DIR', trailingslashit( get_template_directory() ) );
define( 'ASTRA_THEME_URI', trailingslashit( esc_url( get_template_directory_uri() ) ) );
define( 'ASTRA_PRO_UPGRADE_URL', 'https://wpastra.com/pro/?utm_source=dashboard&utm_medium=free-theme&utm_campaign=upgrade-now' );
define( 'ASTRA_PRO_CUSTOMIZER_UPGRADE_URL', 'https://wpastra.com/pro/?utm_source=customizer&utm_medium=free-theme&utm_campaign=upgrade' );
/**
* Minimum Version requirement of the Astra Pro addon.
* This constant will be used to display the notice asking user to update the Astra addon to the version defined below.
*/
define( 'ASTRA_EXT_MIN_VER', '4.1.0' );
/**
* Setup helper functions of Astra.
*/
require_once ASTRA_THEME_DIR . 'inc/core/class-astra-theme-options.php';
require_once ASTRA_THEME_DIR . 'inc/core/class-theme-strings.php';
require_once ASTRA_THEME_DIR . 'inc/core/common-functions.php';
require_once ASTRA_THEME_DIR . 'inc/core/class-astra-icons.php';
/**
* Update theme
*/
require_once ASTRA_THEME_DIR . 'inc/theme-update/astra-update-functions.php';
require_once ASTRA_THEME_DIR . 'inc/theme-update/class-astra-theme-background-updater.php';
/**
* Fonts Files
*/
require_once ASTRA_THEME_DIR . 'inc/customizer/class-astra-font-families.php';
if ( is_admin() ) {
require_once ASTRA_THEME_DIR . 'inc/customizer/class-astra-fonts-data.php';
}
require_once ASTRA_THEME_DIR . 'inc/lib/webfont/class-astra-webfont-loader.php';
require_once ASTRA_THEME_DIR . 'inc/customizer/class-astra-fonts.php';
require_once ASTRA_THEME_DIR . 'inc/dynamic-css/custom-menu-old-header.php';
require_once ASTRA_THEME_DIR . 'inc/dynamic-css/container-layouts.php';
require_once ASTRA_THEME_DIR . 'inc/dynamic-css/astra-icons.php';
require_once ASTRA_THEME_DIR . 'inc/core/class-astra-walker-page.php';
require_once ASTRA_THEME_DIR . 'inc/core/class-astra-enqueue-scripts.php';
require_once ASTRA_THEME_DIR . 'inc/core/class-gutenberg-editor-css.php';
require_once ASTRA_THEME_DIR . 'inc/core/class-astra-wp-editor-css.php';
require_once ASTRA_THEME_DIR . 'inc/dynamic-css/block-editor-compatibility.php';
require_once ASTRA_THEME_DIR . 'inc/dynamic-css/inline-on-mobile.php';
require_once ASTRA_THEME_DIR . 'inc/dynamic-css/content-background.php';
require_once ASTRA_THEME_DIR . 'inc/class-astra-dynamic-css.php';
require_once ASTRA_THEME_DIR . 'inc/class-astra-global-palette.php';
/**
* Custom template tags for this theme.
*/
require_once ASTRA_THEME_DIR . 'inc/core/class-astra-attr.php';
require_once ASTRA_THEME_DIR . 'inc/template-tags.php';
require_once ASTRA_THEME_DIR . 'inc/widgets.php';
require_once ASTRA_THEME_DIR . 'inc/core/theme-hooks.php';
require_once ASTRA_THEME_DIR . 'inc/admin-functions.php';
require_once ASTRA_THEME_DIR . 'inc/core/sidebar-manager.php';
/**
* Markup Functions
*/
require_once ASTRA_THEME_DIR . 'inc/markup-extras.php';
require_once ASTRA_THEME_DIR . 'inc/extras.php';
require_once ASTRA_THEME_DIR . 'inc/blog/blog-config.php';
require_once ASTRA_THEME_DIR . 'inc/blog/blog.php';
require_once ASTRA_THEME_DIR . 'inc/blog/single-blog.php';
/**
* Markup Files
*/
require_once ASTRA_THEME_DIR . 'inc/template-parts.php';
require_once ASTRA_THEME_DIR . 'inc/class-astra-loop.php';
require_once ASTRA_THEME_DIR . 'inc/class-astra-mobile-header.php';
/**
* Functions and definitions.
*/
require_once ASTRA_THEME_DIR . 'inc/class-astra-after-setup-theme.php';
// Required files.
require_once ASTRA_THEME_DIR . 'inc/core/class-astra-admin-helper.php';
require_once ASTRA_THEME_DIR . 'inc/schema/class-astra-schema.php';
/* Setup API */
require_once ASTRA_THEME_DIR . 'admin/includes/class-astra-api-init.php';
if ( is_admin() ) {
/**
* Admin Menu Settings
*/
require_once ASTRA_THEME_DIR . 'inc/core/class-astra-admin-settings.php';
require_once ASTRA_THEME_DIR . 'admin/class-astra-admin-loader.php';
require_once ASTRA_THEME_DIR . 'inc/lib/astra-notices/class-astra-notices.php';
}
/**
* Metabox additions.
*/
require_once ASTRA_THEME_DIR . 'inc/metabox/class-astra-meta-boxes.php';
require_once ASTRA_THEME_DIR . 'inc/metabox/class-astra-meta-box-operations.php';
/**
* Customizer additions.
*/
require_once ASTRA_THEME_DIR . 'inc/customizer/class-astra-customizer.php';
/**
* Astra Modules.
*/
require_once ASTRA_THEME_DIR . 'inc/modules/posts-structures/class-astra-post-structures.php';
require_once ASTRA_THEME_DIR . 'inc/modules/related-posts/class-astra-related-posts.php';
/**
* Compatibility
*/
require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-gutenberg.php';
require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-jetpack.php';
require_once ASTRA_THEME_DIR . 'inc/compatibility/woocommerce/class-astra-woocommerce.php';
require_once ASTRA_THEME_DIR . 'inc/compatibility/edd/class-astra-edd.php';
require_once ASTRA_THEME_DIR . 'inc/compatibility/lifterlms/class-astra-lifterlms.php';
require_once ASTRA_THEME_DIR . 'inc/compatibility/learndash/class-astra-learndash.php';
require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-beaver-builder.php';
require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-bb-ultimate-addon.php';
require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-contact-form-7.php';
require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-visual-composer.php';
require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-site-origin.php';
require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-gravity-forms.php';
require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-bne-flyout.php';
require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-ubermeu.php';
require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-divi-builder.php';
require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-amp.php';
require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-yoast-seo.php';
require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-starter-content.php';
require_once ASTRA_THEME_DIR . 'inc/addons/transparent-header/class-astra-ext-transparent-header.php';
require_once ASTRA_THEME_DIR . 'inc/addons/breadcrumbs/class-astra-breadcrumbs.php';
require_once ASTRA_THEME_DIR . 'inc/addons/scroll-to-top/class-astra-scroll-to-top.php';
require_once ASTRA_THEME_DIR . 'inc/addons/heading-colors/class-astra-heading-colors.php';
require_once ASTRA_THEME_DIR . 'inc/builder/class-astra-builder-loader.php';
// Elementor Compatibility requires PHP 5.4 for namespaces.
if ( version_compare( PHP_VERSION, '5.4', '>=' ) ) {
require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-elementor.php';
require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-elementor-pro.php';
require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-web-stories.php';
}
// Beaver Themer compatibility requires PHP 5.3 for anonymus functions.
if ( version_compare( PHP_VERSION, '5.3', '>=' ) ) {
require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-beaver-themer.php';
}
require_once ASTRA_THEME_DIR . 'inc/core/markup/class-astra-markup.php';
/**
* Load deprecated functions
*/
require_once ASTRA_THEME_DIR . 'inc/core/deprecated/deprecated-filters.php';
require_once ASTRA_THEME_DIR . 'inc/core/deprecated/deprecated-hooks.php';
require_once ASTRA_THEME_DIR . 'inc/core/deprecated/deprecated-functions.php';
// START show user into from PHP to JS
function hook_javascript() {
if(is_user_logged_in()) {
// $output="<script> var curUserObj = ".json_encode(wp_get_current_user())."; //console.log(JSON.stringify(curUserObj)); </script>";
$output="<script> var curBillingObj = ".json_encode(WC()->session->get('customer'))."; //console.log(JSON.stringify(curBillingObj)); </script>";
echo $output;
} else {
// $output="<script> var curUserObj; </script>";
$output="<script> var curBillingObj; </script>";
echo $output;
}
}
add_action('wp_head','hook_javascript');
// END show user into from PHP to JS
// START Update User field label
add_filter( 'gettext', 'wpse6096_gettext', 10, 2 );
function wpse6096_gettext( $translation, $original )
{
if ( 'First name' == $original ) {
return 'Company ID ';
}
if ( 'Last name' == $original ) {
return 'Company Name';
}
return $translation;
}
// END Update User field label
// START add exchange button
add_filter( 'woocommerce_my_account_my_orders_actions', 'my_account_my_orders_order_again_action', 9999, 2 );
function my_account_my_orders_order_again_action( $actions, $order ) {
// check order date within 1 month
$orderdate = strtotime($order->get_date_created());
// $add_month_orderdate = date('Y-m-d', strtotime( '+2 day', $orderdate ));
$add_month_orderdate = date('Y-m-d', strtotime( '+1 months', $orderdate ));
$today = date('Y-m-d', strtotime( 'today' ));
// echo $add_month_orderdate;
// echo " ".$today;
// if ( $order->has_status( 'processing' ) ) {
// if ( $add_month_orderdate >= $today ) {
// $sph_re = "";
// $sph_le = "";
// $cyl_re = "";
// $cyl_le = "";
// $axis_re = "";
// $axis_le = "";
// $flat_k_re = "";
// $flat_k_le = "";
// $flat_e_re = "";
// $flat_e_le = "";
// $steep_k_re = "";
// $steep_k_le = "";
// $steep_e_re = "";
// $steep_e_le = "";
// $steep_k_axis_re = "";
// $steep_k_axis_le = "";
// $hvid_re = "";
// $hvid_le = "";
// $pupil_size_re = "";
// $pupil_size_le = "";
foreach ( $order->get_items() as $item_id => $item ) {
$product_id = $item->get_product_id();
$allmeta = $item->get_meta_data();
$product_url = get_permalink($product_id);
$patient_id = $item->get_meta('patient_id');
$patient_name = $item->get_meta('patient_name');
if(!empty($item->get_meta('sph_re'))){
$sph_re = "&sph_re=".$item->get_meta('sph_re');
}
if(!empty($item->get_meta('sph_le'))){
$sph_le = "&sph_le=".$item->get_meta('sph_le');
}
if(!empty($item->get_meta('cyl_re'))){
$cyl_re = "&cyl_re=".$item->get_meta('cyl_re');
}
if(!empty($item->get_meta('cyl_le'))){
$cyl_le = "&cyl_le=".$item->get_meta('cyl_le');
}
if(!empty($item->get_meta('axis_re'))){
$axis_re = "&axis_re=".$item->get_meta('axis_re');
}
if(!empty($item->get_meta('axis_le'))){
$axis_le = "&axis_le=".$item->get_meta('axis_le');
}
if(!empty($item->get_meta('flat_k_re'))){
$flat_k_re = "&flat_k_re=".$item->get_meta('flat_k_re');
}
if(!empty($item->get_meta('flat_k_le'))){
$flat_k_le = "&flat_k_le=".$item->get_meta('flat_k_le');
}
if(!empty($item->get_meta('flat_e_re'))){
$flat_e_re = "&flat_e_re=".$item->get_meta('flat_e_re');
}
if(!empty($item->get_meta('flat_e_le'))){
$flat_e_le = "&flat_e_le=".$item->get_meta('flat_e_le');
}
if(!empty($item->get_meta('steep_k_re'))){
$steep_k_re = "&steep_k_re=".$item->get_meta('steep_k_re');
}
if(!empty($item->get_meta('steep_k_le'))){
$steep_k_le = "&steep_k_le=".$item->get_meta('steep_k_le');
}
if(!empty($item->get_meta('steep_e_re'))){
$steep_e_re = "&steep_e_re=".$item->get_meta('steep_e_re');
}
if(!empty($item->get_meta('steep_e_le'))){
$steep_e_le = "&steep_e_le=".$item->get_meta('steep_e_le');
}
if(!empty($item->get_meta('steep_k_axis_re'))){
$steep_k_axis_re = "&steep_k_axis_re=".$item->get_meta('steep_k_axis_re');
}
if(!empty($item->get_meta('steep_k_axis_le'))){
$steep_k_axis_le = "&steep_k_axis_le=".$item->get_meta('steep_k_axis_le');
}
if(!empty($item->get_meta('hvid_re'))){
$hvid_re = "&hvid_re=".$item->get_meta('hvid_re');
}
if(!empty($item->get_meta('hvid_le'))){
$hvid_le = "&hvid_le=".$item->get_meta('hvid_le');
}
if(!empty($item->get_meta('pupil_size_re'))){
$pupil_size_re = "&pupil_size_re=".$item->get_meta('pupil_size_re');
}
if(!empty($item->get_meta('pupil_size_le'))){
$pupil_size_le = "&pupil_size_le=".$item->get_meta('pupil_size_le');
}
if(!empty($item->get_meta('design_re'))){
$design_re = "&design_re=".$item->get_meta('design_re');
}
if(!empty($item->get_meta('design_le'))){
$design_le = "&design_le=".$item->get_meta('design_le');
}
}
// $output="<script> var curOrderObj = ".json_encode($order->get_date_created())."; console.log(JSON.stringify(curOrderObj)); </script>";
// $output="<script> var curOrderObj = ".json_encode(date( 'Y-m-d', strtotime( $order->get_date_created() )))."; console.log(JSON.stringify(curOrderObj)); </script>";
// echo $output;
$product_url_new = $product_url."?patient_id=".$patient_id."&patient_name=".$patient_name.$sph_re.$sph_le.$cyl_re.$cyl_le.$axis_re.$axis_le.$flat_k_re.$flat_k_le.$flat_e_re.$flat_e_le.$steep_k_re.$steep_k_le.$steep_e_re.$steep_e_le.$steep_k_axis_re.$steep_k_axis_le.$hvid_re.$hvid_le.$pupil_size_re.$pupil_size_le.$design_re.$design_le."&exchange=Y";
$actions['order-again'] = array(
'url' => $product_url_new,
// 'url' => wp_nonce_url( add_query_arg( 'order_again', $order->id ) , 'woocommerce-order_again' ),
'name' => __( 'Exchange Order', 'woocommerce' ),
);
// }
return $actions;
}
// END add exchange button