post_type;
$aelms_allowed_post_type = [
acadlix()->cpt()->course()->get_post_type(),
];
if (acadlix()->helper()->is_course_bundle_addon_active()) {
$aelms_allowed_post_type[] = acadlix()->cpt()->course_bundle()->get_post_type();
}
$type = 'course';
if (in_array($post_type, $aelms_allowed_post_type)) {
if ($post_type == acadlix()->cpt()->course()->get_post_type()) {
$aelms_item = acadlix()->model()->course()->ofCourse()->find($post->ID);
$type = 'course';
} else if ($post_type == acadlix()->cpt()->course_bundle()->get_post_type()) {
$aelms_item = acadlix()->model()->courseBundle()->ofCourseBundle()->find($post->ID);
$type = 'course-bundle';
}
$aelms_courses_url = get_permalink(acadlix()->helper()->acadlix_get_option('acadlix_all_courses_page_id'));
$aelms_checkout_url = get_permalink(acadlix()->helper()->acadlix_get_option('acadlix_checkout_page_id'));
$aelms_dashboard_url = get_permalink(acadlix()->helper()->acadlix_get_option('acadlix_dashboard_page_id'));
$aelms_payment_type = $aelms_item->rendered_metas['payment_type'] ?? 'one_time';
$aelms_cart = [];
$aelms_is_course_purchased = false;
if (is_user_logged_in()) {
$aelms_userId = get_current_user_id();
$aelms_is_course_purchased = $aelms_item->isPurchasedBy($aelms_userId);
$aelms_cart = acadlix()->model()->courseCart()->where([
['user_id', '=', $aelms_userId],
['item_id', '=', $post->ID],
['type', '=', $type],
])->first();
} else {
if (isset($_COOKIE['acadlix_cart_token'])) {
$aelms_cart = acadlix()
->model()
->courseCart()
->where('cart_token', sanitize_text_field(wp_unslash($_COOKIE['acadlix_cart_token'])))
->where('item_id', $post->ID)
->where('type', $type)
->first();
}
}
if ($aelms_item) {
$aelms_enable_sale_price = $aelms_item->rendered_metas['enable_sale_price'] ?? false;
$aelms_price = $aelms_item->rendered_metas['price'] ?? 0;
$aelms_sale_price = $aelms_item->rendered_metas['sale_price'] ?? 0;
$aelms_start_date = $aelms_item->rendered_metas['start_date'] ?? null;
$aelms_end_date = $aelms_item->rendered_metas['end_date'] ?? null;
if ($aelms_item->post_status != 'publish') {
return '';
}
?>