-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
120 lines (99 loc) · 3.63 KB
/
functions.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
<?php
show_admin_bar(false);
// register navigation menu support
function register_my_menus() {
register_nav_menus(
array(
'header-menu' => __( 'Header Menu' ),
'secondary-menu' => __( 'Secondary Menu' ),
'footer-menu' => __( 'Footer Menu' )
)
);
}
add_action( 'init', 'register_my_menus');
// register thumbnail support
add_theme_support( 'post-thumbnails' );
// register logo support
function theme_prefix_setup() {
add_theme_support( 'custom-logo' );
}
add_action( 'after_setup_theme', 'theme_prefix_setup' );
// register woocommerce support
add_action( 'after_setup_theme', 'woocommerce_support' );
function woocommerce_support() {
add_theme_support( 'woocommerce' );
}
// register acf options page
if( function_exists('acf_add_options_page') ) {
acf_add_options_page();
}
// test if featured product is in cart
function wt_is_in_cart($product_id) {
global $woocommerce;
foreach($woocommerce->cart->get_cart() as $key => $val ) {
$_product = $val['data'];
if($product_id == $_product->id ) {
return true;
}
}
return false;
}
// return featured product quantity count
function wt_get_cart_count($product_id) {
global $woocommerce;
foreach($woocommerce->cart->get_cart() as $key => $val ) {
$_product = $val['data'];
if($product_id == $_product->id ) {
echo $val['quantity'];
}
}
}
// redirect after headers sent
function redirect($url)
{
$string = '<script type="text/javascript">';
$string .= 'window.location = "' . $url . '"';
$string .= '</script>';
echo $string;
}
// remove woocommerce stylesheets
add_filter( 'woocommerce_enqueue_styles', '__return_false' );
// override checkout fields on donation page
function custom_override_checkout_fields( $fields ) {
// placeholders
$fields['billing']['billing_first_name']['label'] = 'What\'s your first name?';
$fields['billing']['billing_last_name']['label'] = 'What\'s your last name?';
$fields['billing']['billing_postcode']['label'] = 'What\'s your postal code?';
$fields['billing']['billing_email']['label'] = 'What\'s your email?';
$fields['billing']['billing_phone']['label'] = 'What\'s your phone number?';
$fields['order']['order_comments']['label'] = 'Why does Wikitongues matter to you? (Optional)';
$fields['order']['order_comments']['placeholder'] = 'Tell us why you care about language rights!';
unset($fields['billing']['billing_company']);
unset($fields['billing']['billing_address_1']);
unset($fields['billing']['billing_address_2']);
unset($fields['billing']['billing_city']);
unset($fields['billing']['billing_state']);
unset($fields['billing']['billing_country']);
return $fields;
}
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
// Override default 'place order' on checkout submit
add_filter( 'woocommerce_order_button_text', 'woo_custom_order_button_text' );
function woo_custom_order_button_text() {
return __( 'Donate now', 'woocommerce' );
}
// Thank you notification
add_action( 'template_redirect', 'wc_custom_redirect_after_purchase' );
function wc_custom_redirect_after_purchase() {
global $wp;
if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) {
wp_redirect( 'https://wikitongues.org/donation-received/' );
exit;
}
}
// function unrequired_wc_fields( $fields ) {
// $fields['billing_company']['required'] = false;
// $fields['billing_address_1']['required'] = false;
// $fields['billing_address_2']['required'] = false;
// }
// add_filter('woocommerce_checkout_fields', 'unrequired_wc_fields');