get_id();
$title = $product->get_name();
$categories = wc_get_product_category_list( $product_id, ‘, ‘, ‘‘, ‘‘ );
$thumbnail_id = $product->get_image_id();
// 80×80 thumbnail size custom output
$image_html = $thumbnail_id ? wp_get_attachment_image( $thumbnail_id, [ 80, 80 ], false, [ ‘class’ => ‘course-card-img’ ] ) : wc_placeholder_img( [ 80, 80 ], [ ‘class’ => ‘course-card-img’ ] );
// Fetch ACF fields dynamically
$course_level = get_field( ‘course_level’, $product_id );
$duration = get_field( ‘duration’, $product_id );
$duration_unit= get_field( ‘course_duration_unit’, $product_id );
$credits = get_field( ‘credits’, $product_id );
$study_mode = get_field( ‘study_mode’, $product_id );
$overview = get_field( ‘course_overview’, $product_id );
// Fallback overview if empty
if ( ! $overview ) {
$overview = wp_strip_all_tags( $product->get_short_description() );
if ( ! $overview ) {
$overview = wp_trim_words( wp_strip_all_tags( $product->get_description() ), 18 );
}
}
// Study mode label mapping
$study_mode_label = ”;
if ( $study_mode ) {
$choices = [
‘online’ => ‘Online’,
‘on-campus’ => ‘On Campus’,
‘blended’ => ‘Blended’,
];
$study_mode_label = isset( $choices[ $study_mode ] ) ? $choices[ $study_mode ] : ucfirst( $study_mode );
}
// Formatted duration string
$duration_str = ”;
if ( $duration ) {
$unit_label = $duration_unit ? ucfirst( $duration_unit ) : ‘Months’;
$duration_str = esc_html( $duration . ‘ ‘ . $unit_label );
}
// Price and Enroll Button Url
$price_html = $product->get_price_html();
$enroll_url = esc_url( get_permalink( $product_id ) );
$button_text = __( ‘Enroll Now’, ‘angie-snippets’ );
?>