woo
Signed-off-by: Jeff <jeff@gotenzing.com>
Showing
1 changed file
with
19 additions
and
30 deletions
| ... | @@ -4,7 +4,6 @@ add_filter( 'woocommerce_account_menu_items', 'misha_rename_downloads' ); | ... | @@ -4,7 +4,6 @@ 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,20 +143,20 @@ function my_remove_cart_product_image() { | ... | @@ -146,20 +143,20 @@ 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 ) { |
| 150 | $post = get_post($course_id); | ||
| 151 | if ( !wp_is_post_autosave( $post ) && $post->post_status !== 'auto-draft' && !wp_is_post_revision( $course_id ) ) { | ||
| 152 | if ( get_post_type($course_id) == 'sfwd-courses') { | 152 | if ( get_post_type($course_id) == 'sfwd-courses') { |
| 153 | 153 | ||
| 154 | error_log('create_and_attach_woocommerce_product'); | 154 | if(!get_post_meta( $course_id, '_woocommerce_product', true )){ |
| 155 | // Set the product data | ||
| 156 | $product_data = array( | 155 | $product_data = array( |
| 157 | 'post_title' => get_the_title( $course_id ), | 156 | 'post_title' => get_the_title( $course_id ), |
| 158 | 'post_type' => 'product', | 157 | 'post_type' => 'product', |
| 159 | 'post_status' => 'publish' | 158 | 'post_status' => 'publish' |
| 160 | ); | 159 | ); |
| 161 | |||
| 162 | // Insert the product | ||
| 163 | $product_id = wp_insert_post( $product_data ); | 160 | $product_id = wp_insert_post( $product_data ); |
| 164 | update_post_meta( $course_id, '_woocommerce_product', $product_id ); | 161 | update_post_meta( $course_id, '_woocommerce_product', $product_id ); |
| 165 | // Set the product type | 162 | // Set the product type |
| ... | @@ -168,33 +165,24 @@ function create_and_attach_woocommerce_product( $course_id ) { | ... | @@ -168,33 +165,24 @@ function create_and_attach_woocommerce_product( $course_id ) { |
| 168 | // Set the related_course | 165 | // Set the related_course |
| 169 | $related_course = array($course_id); | 166 | $related_course = array($course_id); |
| 170 | update_post_meta( $product_id, '_related_course', $related_course); | 167 | update_post_meta( $product_id, '_related_course', $related_course); |
| 171 | // Set the prices | 168 | }else{ |
| 172 | update_post_meta( $product_id, '_regular_price', $price ); | 169 | $product_id = get_post_meta( $course_id, '_woocommerce_product', true ); |
| 173 | update_post_meta( $product_id, '_price', $price ); | 170 | $product_data = array( |
| 174 | update_post_meta( $product_id, '_role_based_price',$sp ); | 171 | 'ID' => $product_id, |
| 175 | 172 | 'post_title' => get_the_title( $course_id ) | |
| 173 | ); | ||
| 174 | $product = wp_update_post( $product_data ); | ||
| 176 | } | 175 | } |
| 177 | 176 | learndash_update_setting($course_id, 'sfwd-courses_course_price_type', 'closed' ); | |
| 178 | } | 177 | learndash_update_setting($course_id, 'sfwd-courses_certificate', 426 ); |
| 179 | |||
| 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 ); |
| ... | @@ -203,9 +191,10 @@ function my_wp_after_insert_post( $post_id, $post, $update, $post_before ) { | ... | @@ -203,9 +191,10 @@ function my_wp_after_insert_post( $post_id, $post, $update, $post_before ) { |
| 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; | ... | ... |
-
Please register or sign in to post a comment