learn.php
9.93 KB
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
<?php
add_shortcode( 'breadcrumbs', 'the_bread' );
function the_bread() {
if(!is_admin()){
$ingredients = array(
'separator' => ' | ',
'offset' => -3,
'length' => 3,
);
ob_start();
$flour = $_SERVER['REQUEST_URI'];
if ( str_contains( $flour, '?' ) )
$flour = substr( $flour, 0, strpos( $flour, '?' ) );
$flour = ( str_ends_with( $flour, '/' ) ? explode( '/', substr( $flour, 1, -1 ) ) : explode( '/', substr( $flour, 1 ) ) );
$crumbs = [];
foreach ( $flour as $crumb ) {
$slug = esc_html( $crumb );
$url = esc_url( $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . '/' . substr( implode( '/', $flour ), 0, strpos( implode( '/', $flour ), $crumb ) ) . $crumb. '/' );
array_push( $crumbs, ( object )
[
'slug' => $slug,
'url' => $url,
]
);
};
$offset = ( empty( $ingredients['offset'] ) ? 0 : $ingredients['offset'] );
$length = ( empty( $ingredients['length'] ) ? null : $ingredients['length'] );
$crumbs = array_slice( $crumbs, $offset, $length );
echo '<ul class="bread">';
$i = 0;
if ( is_singular( 'sfwd-lessons' ) ) {
echo '<li class="crumb" itemprop="itemListElement">
<a class="item" itemprop="item" href="https://thecommonwell.ca/learning-2/">
<span itemprop="name">Learning Opportunities</span>
</a>
<meta itemprop="position" content="1">
</li>>';
}
foreach ( $crumbs as $crumb ) {
$i++;
echo '<li class="crumb" itemprop="itemListElement">
<a class="item" itemprop="item" href="' . $crumb->url . '">
<span itemprop="name">' . ( url_to_postid( $crumb->url ) ? get_the_title( url_to_postid( $crumb->url ) ) : ucfirst( str_replace( '-', ' ', $crumb->slug ) ) ) . '</span>
</a>
<meta itemprop="position" content="' . $i . '">
</li>';
if ( $i !== sizeof( $crumbs ) && ! empty( $ingredients['separator'] ) )
echo $ingredients['separator'];
};
echo '</ul>';
$output = ob_get_clean();
return $output;
}
};
add_filter( 'woocommerce_account_menu_items', 'misha_rename_downloads' );
function misha_rename_downloads( $menu_links ){
// $menu_links[ 'TAB ID HERE' ] = 'NEW TAB NAME HERE';
$menu_links[ 'dashboard' ] = 'My Account';
$menu_links[ 'edit-address' ] = 'Address';
return $menu_links;
}
add_shortcode( 'certs', 'certs' );
function certs(){
try{
$enrolled_courses = learndash_user_get_enrolled_courses( get_current_user_id(), array(), false);
ob_start();
if (is_array($enrolled_courses)):?>
<div class="carousel">
<div id="cert" class="cert-carousel carousel-items container">
<div class='swiper-wrapper'>
<?php foreach($enrolled_courses as $enrolled_course){
$cert = learndash_get_course_certificate_link($enrolled_course, get_current_user_id());
if(!empty($cert)){
$sfwd_course = get_post_meta($enrolled_course , '_sfwd-courses', true );
$thumbnail_id = "911"; ?>
<div class="swiper-slide">
<div class="cert">
<?php echo '<a target="_blank" style="background-image:url('.wp_get_attachment_url( $thumbnail_id).')" class="cert_link" href="'.$cert.'">'. wp_get_attachment_image($thumbnail_id,'medium' ).'<div class="cert-text"><p><strong>'
.get_user_meta(get_current_user_id(), 'first_name', true )." ". get_user_meta(get_current_user_id(), 'last_name', true ).'</strong></p>'
.get_the_title( $enrolled_course ).'</div></a>';
?>
</div>
</div>
<?php }
}; ?>
</div>
<div class="swiper-pagination"></div>
<div class="swiper-button-prev" data-id="cert"></div>
<div class="swiper-button-next" data-id="cert"></div>
</div>
</div>
<?php endif;
wp_reset_query();
$output = ob_get_clean();
return $output;
}catch(Throwable $e) {
error_log("certs()". $e->getMessage()) ;
}
}
function wooc_extra_register_fields() {?>
<p class="form-row form-row-first">
<label for="reg_billing_first_name"><?php _e( 'First name', 'woocommerce' ); ?><span class="required">*</span></label>
<input type="text" class="woocommerce-Input woocommerce-Input--text input-text form-control" name="billing_first_name" id="reg_billing_first_name" value="<?php if ( ! empty( $_POST['billing_first_name'] ) ) esc_attr_e( $_POST['billing_first_name'] ); ?>" />
</p>
<p class="form-row form-row-last">
<label for="reg_billing_last_name"><?php _e( 'Last name', 'woocommerce' ); ?><span class="required">*</span></label>
<input type="text" class="woocommerce-Input woocommerce-Input--text input-text form-control" name="billing_last_name" id="reg_billing_last_name" value="<?php if ( ! empty( $_POST['billing_last_name'] ) ) esc_attr_e( $_POST['billing_last_name'] ); ?>" />
</p>
<div class="clear"></div>
<?php
}
add_action( 'woocommerce_register_form_start', 'wooc_extra_register_fields' );
function wooc_validate_extra_register_fields( $username, $email, $validation_errors ) {
if ( isset( $_POST['billing_first_name'] ) && empty( $_POST['billing_first_name'] ) ) {
$validation_errors->add( 'billing_first_name_error', __( '<strong>Error</strong>: First name is required!', 'woocommerce' ) );
}
if ( isset( $_POST['billing_last_name'] ) && empty( $_POST['billing_last_name'] ) ) {
$validation_errors->add( 'billing_last_name_error', __( '<strong>Error</strong>: Last name is required!.', 'woocommerce' ) );
}
return $validation_errors;
}
add_action( 'woocommerce_register_post', 'wooc_validate_extra_register_fields', 10, 3 );
/**
* Below code save extra fields.
*/
function wooc_save_extra_register_fields( $customer_id ) {
if ( isset( $_POST['billing_phone'] ) ) {
// Phone input filed which is used in WooCommerce
update_user_meta( $customer_id, 'billing_phone', sanitize_text_field( $_POST['billing_phone'] ) );
}
if ( isset( $_POST['billing_first_name'] ) ) {
//First name field which is by default
update_user_meta( $customer_id, 'first_name', sanitize_text_field( $_POST['billing_first_name'] ) );
// First name field which is used in WooCommerce
update_user_meta( $customer_id, 'billing_first_name', sanitize_text_field( $_POST['billing_first_name'] ) );
}
if ( isset( $_POST['billing_last_name'] ) ) {
// Last name field which is by default
update_user_meta( $customer_id, 'last_name', sanitize_text_field( $_POST['billing_last_name'] ) );
// Last name field which is used in WooCommerce
update_user_meta( $customer_id, 'billing_last_name', sanitize_text_field( $_POST['billing_last_name'] ) );
}
}
add_action( 'woocommerce_created_customer', 'wooc_save_extra_register_fields' );
// ----- validate password match on the registration page
function registration_errors_validation($reg_errors, $sanitized_user_login, $user_email) {
global $woocommerce;
extract( $_POST );
if ( strcmp( $password, $password2 ) !== 0 ) {
return new WP_Error( 'registration-error', __( 'Passwords do not match.', 'woocommerce' ) );
}
return $reg_errors;
}
add_filter('woocommerce_registration_errors', 'registration_errors_validation', 10,3);
// ----- add a confirm password fields match on the registration page
function wc_register_form_password_repeat() {
?>
<p class="form-row form-row-wide">
<label for="reg_password2"><?php _e( 'Password Repeat', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="password" class="woocommerce-Input woocommerce-Input--text input-text form-control" name="password2" id="reg_password2" value="<?php if ( ! empty( $_POST['password2'] ) ) echo esc_attr( $_POST['password2'] ); ?>" />
</p>
<?php
}
add_action( 'woocommerce_register_form', 'wc_register_form_password_repeat' );
// ----- Validate confirm password field match to the checkout page
function lit_woocommerce_confirm_password_validation( $posted ) {
$checkout = WC()->checkout;
if ( ! is_user_logged_in() && ( $checkout->must_create_account || ! empty( $posted['createaccount'] ) ) ) {
if ( strcmp( $posted['account_password'], $posted['account_confirm_password'] ) !== 0 ) {
wc_add_notice( __( 'Passwords do not match.', 'woocommerce' ), 'error' );
}
}
}
add_action( 'woocommerce_after_checkout_validation', 'lit_woocommerce_confirm_password_validation', 10, 2 );
// ----- Add a confirm password field to the checkout page
function lit_woocommerce_confirm_password_checkout( $checkout ) {
if ( get_option( 'woocommerce_registration_generate_password' ) == 'no' ) {
$fields = $checkout->get_checkout_fields();
$fields['account']['account_confirm_password'] = array(
'type' => 'password',
'label' => __( 'Confirm password', 'woocommerce' ),
'required' => true,
'placeholder' => _x( 'Confirm Password', 'placeholder', 'woocommerce' )
);
$checkout->__set( 'checkout_fields', $fields );
}
}
add_action( 'woocommerce_checkout_init', 'lit_woocommerce_confirm_password_checkout', 10, 1 );
add_filter( 'woocommerce_enable_order_notes_field', '__return_false', 9999 );