| @@ -15,15 +15,15 @@ | ||
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | use stdClass; |
| 18 | 18 | use TUTOR\Input; |
| 19 | +use Tutor\Ecommerce\Tax; | |
| 20 | +use Tutor\Models\QuizModel; | |
| 19 | 21 | use Tutor\Helpers\HttpHelper; |
| 20 | 22 | use Tutor\Models\CourseModel; |
| 21 | 23 | use Tutor\Ecommerce\Ecommerce; |
| 22 | -use Tutor\Ecommerce\Tax; | |
| 23 | 24 | use Tutor\Traits\JsonResponse; |
| 24 | 25 | use Tutor\Helpers\ValidationHelper; |
| 25 | -use Tutor\Models\QuizModel; | |
| 26 | 26 | use TutorPro\CourseBundle\Models\BundleModel; |
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * Course Class |
| @@ -2352,23 +2352,19 @@ | ||
| 2352 | 2352 | update_post_meta( $product_id, '_subscription_price', $course_price ); |
| 2353 | 2353 | } |
| 2354 | 2354 | |
| 2355 | 2355 | // Set course regular & sale price. |
| 2356 | - update_post_meta( $post_ID, self::COURSE_PRICE_META, $product_obj->get_regular_price() ); | |
| 2357 | - update_post_meta( $post_ID, self::COURSE_SALE_PRICE_META, $product_obj->get_sale_price() ); | |
| 2356 | + self::set_course_regular_and_sale_price( $post_ID, $product_obj->get_regular_price(), $product_obj->get_sale_price() ); | |
| 2358 | 2357 | } else { |
| 2359 | 2358 | // Create new WC product name with course title. |
| 2360 | 2359 | $product_id = self::create_wc_product( $course->post_title, $course_price, $sale_price ); |
| 2361 | 2360 | if ( $product_id ) { |
| 2362 | 2361 | $product_obj = wc_get_product( $product_id ); |
| 2363 | - update_post_meta( $post_ID, self::COURSE_PRODUCT_ID_META, $product_id ); | |
| 2364 | - // Mark product for woocommerce. | |
| 2365 | - update_post_meta( $product_id, '_virtual', 'yes' ); | |
| 2366 | - update_post_meta( $product_id, '_tutor_product', 'yes' ); | |
| 2367 | 2362 | |
| 2363 | + self::sync_course_with_wc_product( $post_ID, $product_id ); | |
| 2364 | + | |
| 2368 | 2365 | // Set course regular & sale price. |
| 2369 | - update_post_meta( $post_ID, self::COURSE_PRICE_META, $product_obj->get_regular_price() ); | |
| 2370 | - update_post_meta( $post_ID, self::COURSE_SALE_PRICE_META, $product_obj->get_sale_price() ); | |
| 2366 | + self::set_course_regular_and_sale_price( $post_ID, $product_obj->get_regular_price(), $product_obj->get_sale_price() ); | |
| 2371 | 2367 | } |
| 2372 | 2368 | } |
| 2373 | 2369 | |
| 2374 | 2370 | $course_post_thumbnail = Input::post( 'thumbnail_id', 0, Input::TYPE_INT ); |
| @@ -3168,6 +3164,41 @@ | ||
| 3168 | 3164 | 'trash', |
| 3169 | 3165 | 'pending', |
| 3170 | 3166 | 'future', |
| 3171 | 3167 | ); |
| 3168 | + } | |
| 3169 | + | |
| 3170 | + /** | |
| 3171 | + * Link a course/bundle post to a WooCommerce product. | |
| 3172 | + * | |
| 3173 | + * @since 3.8.2 | |
| 3174 | + * | |
| 3175 | + * @param int $post_ID The WordPress post ID of the course. | |
| 3176 | + * @param int $product_id The WooCommerce product ID to associate with the course. | |
| 3177 | + * @return void | |
| 3178 | + */ | |
| 3179 | + public static function sync_course_with_wc_product( $post_ID, $product_id ) { | |
| 3180 | + | |
| 3181 | + update_post_meta( $post_ID, self::COURSE_PRODUCT_ID_META, $product_id ); | |
| 3182 | + | |
| 3183 | + // Mark product for woocommerce. | |
| 3184 | + update_post_meta( $product_id, '_virtual', 'yes' ); | |
| 3185 | + update_post_meta( $product_id, '_tutor_product', 'yes' ); | |
| 3186 | + } | |
| 3187 | + | |
| 3188 | + /** | |
| 3189 | + * Map Tutor's course prices to WooCommerce. | |
| 3190 | + * | |
| 3191 | + * @since 3.8.2 | |
| 3192 | + * | |
| 3193 | + * @param int $post_ID The WordPress post ID of the course. | |
| 3194 | + * @param string|int|float $regular_price The regular price. | |
| 3195 | + * @param string|int|float $sale_price The sale price. | |
| 3196 | + * @return void | |
| 3197 | + */ | |
| 3198 | + private static function set_course_regular_and_sale_price( $post_ID, $regular_price, $sale_price ) { | |
| 3199 | + | |
| 3200 | + // Set course regular & sale price. | |
| 3201 | + update_post_meta( $post_ID, self::COURSE_PRICE_META, $regular_price ); | |
| 3202 | + update_post_meta( $post_ID, self::COURSE_SALE_PRICE_META, $sale_price ); | |
| 3172 | 3203 | } |
| 3173 | 3204 | } |