009eecde by Jeff Balicki

woo

Signed-off-by: Jeff <jeff@gotenzing.com>
1 parent 9959f24a
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
3 add_filter( 'woocommerce_account_menu_items', 'misha_rename_downloads' ); 3 add_filter( 'woocommerce_account_menu_items', 'misha_rename_downloads' );
4 4
5 function misha_rename_downloads( $menu_links ){ 5 function misha_rename_downloads( $menu_links ){
6 6
7 // $menu_links[ 'TAB ID HERE' ] = 'NEW TAB NAME HERE';
8 $menu_links[ 'dashboard' ] = 'My Account'; 7 $menu_links[ 'dashboard' ] = 'My Account';
9 $menu_links[ 'edit-address' ] = 'Address'; 8 $menu_links[ 'edit-address' ] = 'Address';
10 9
...@@ -64,8 +63,6 @@ add_action( 'woocommerce_created_customer', 'wooc_save_extra_register_fields' ); ...@@ -64,8 +63,6 @@ add_action( 'woocommerce_created_customer', 'wooc_save_extra_register_fields' );
64 63
65 64
66 65
67
68
69 // ----- validate password match on the registration page 66 // ----- validate password match on the registration page
70 function registration_errors_validation($reg_errors, $sanitized_user_login, $user_email) { 67 function registration_errors_validation($reg_errors, $sanitized_user_login, $user_email) {
71 global $woocommerce; 68 global $woocommerce;
...@@ -146,66 +143,58 @@ function my_remove_cart_product_image() { ...@@ -146,66 +143,58 @@ function my_remove_cart_product_image() {
146 143
147 144
148 add_action('acf/save_post', 'create_and_attach_woocommerce_product', 1); 145 add_action('acf/save_post', 'create_and_attach_woocommerce_product', 1);
146 add_action('wp_after_insert_post', 'create_and_attach_woocommerce_product', 1);
149 147
150 148
151 function create_and_attach_woocommerce_product( $course_id ) { 149 function create_and_attach_woocommerce_product( $course_id ) {
152 if ( get_post_type($course_id) == 'sfwd-courses') { 150 $post = get_post($course_id);
153 151 if ( !wp_is_post_autosave( $post ) && $post->post_status !== 'auto-draft' && !wp_is_post_revision( $course_id ) ) {
154 error_log('create_and_attach_woocommerce_product'); 152 if ( get_post_type($course_id) == 'sfwd-courses') {
155 // Set the product data 153
156 $product_data = array( 154 if(!get_post_meta( $course_id, '_woocommerce_product', true )){
157 'post_title' => get_the_title( $course_id ), 155 $product_data = array(
158 'post_type' => 'product', 156 'post_title' => get_the_title( $course_id ),
159 'post_status' => 'publish' 157 'post_type' => 'product',
160 ); 158 'post_status' => 'publish'
161 159 );
162 // Insert the product 160 $product_id = wp_insert_post( $product_data );
163 $product_id = wp_insert_post( $product_data ); 161 update_post_meta( $course_id, '_woocommerce_product', $product_id );
164 update_post_meta( $course_id, '_woocommerce_product', $product_id ); 162 // Set the product type
165 // Set the product type 163 wp_set_object_terms( $product_id, 'course', 'product_type' );
166 wp_set_object_terms( $product_id, 'course', 'product_type' ); 164 wp_set_object_terms( $product_id, 'uncategorized', 'product_cat' );
167 wp_set_object_terms( $product_id, 'uncategorized', 'product_cat' ); 165 // Set the related_course
168 // Set the related_course 166 $related_course = array($course_id);
169 $related_course = array($course_id); 167 update_post_meta( $product_id, '_related_course', $related_course);
170 update_post_meta( $product_id, '_related_course', $related_course); 168 }else{
171 // Set the prices 169 $product_id = get_post_meta( $course_id, '_woocommerce_product', true );
172 update_post_meta( $product_id, '_regular_price', $price ); 170 $product_data = array(
173 update_post_meta( $product_id, '_price', $price ); 171 'ID' => $product_id,
174 update_post_meta( $product_id, '_role_based_price',$sp ); 172 'post_title' => get_the_title( $course_id )
175 173 );
176 } 174 $product = wp_update_post( $product_data );
177 175 }
178 } 176 learndash_update_setting($course_id, 'sfwd-courses_course_price_type', 'closed' );
179 177 learndash_update_setting($course_id, 'sfwd-courses_certificate', 426 );
180
181 add_action( 'wp_after_insert_post', 'my_wp_after_insert_post', 10, 4 );
182
183 function my_wp_after_insert_post( $post_id, $post, $update, $post_before ) {
184 if ( 'publish' !== $post->post_status || ( $post_before && 'publish' === $post_before->post_status ) || wp_is_post_revision( $post_id )) {
185 if ( get_post_type($post_id) == 'sfwd-courses') {
186 error_log('woocommerce_learndash_product');
187 learndash_update_setting($post_id, 'sfwd-courses_course_price_type', 'closed' );
188 $product_id = get_post_meta($post_id, '_woocommerce_product',true);
189 learndash_update_setting($post_id, 'sfwd-courses_certificate', 426 );
190 if($product_id !=""){ 178 if($product_id !=""){
191 $courses_custom_button_url = learndash_update_setting($post_id, 'sfwd-courses_custom_button_url', get_site_url().'/cart/?add-to-cart='.$product_id ); 179 $courses_custom_button_url = learndash_update_setting($course_id, 'sfwd-courses_custom_button_url', get_site_url().'/cart/?add-to-cart='.$product_id );
192 } 180 }
193 $price = get_post_meta($post_id, 'program_info_cost_&_dates_0_cost',true ); 181 $price = get_post_meta($course_id, 'program_info_cost_&_dates_0_cost',true );
194 if($price !=""){ 182 if($price !=""){
195 learndash_update_setting($post_id, 'sfwd-courses_course_price', $price ); 183 learndash_update_setting($course_id, 'sfwd-courses_course_price', $price );
196 } 184 }
197 $staff_price = get_post_meta($post_id, 'program_info_cost_&_dates_0_cost_staff',true ); 185 $staff_price = get_post_meta($course_id, 'program_info_cost_&_dates_0_cost_staff',true );
198 if($staff_price !=""){ 186 if($staff_price !=""){
199 $sp = array('staff' =>array('regular_price' => $staff_price)); 187 $sp = array('staff' =>array('regular_price' => $staff_price));
200 update_post_meta( $product_id, '_regular_price', $price ); 188 update_post_meta( $product_id, '_regular_price', $price );
201 update_post_meta( $product_id, '_price', $price ); 189 update_post_meta( $product_id, '_price', $price );
202 update_post_meta( $product_id, '_role_based_price',$sp ); 190 update_post_meta( $product_id, '_role_based_price',$sp );
203 } 191 }
204 } 192 }
205 } 193 }
206
207 } 194 }
208 195
196
197
209 // Redirect to All posts dashboard after post update/publish 198 // Redirect to All posts dashboard after post update/publish
210 function webroomtech_redirect_to_post_list() { 199 function webroomtech_redirect_to_post_list() {
211 global $pagenow; 200 global $pagenow;
......