uo_course_grid_ribbon_price
Filters the course price displayed on the course grid ribbon for customization before rendering.
add_filter( 'uo_course_grid_ribbon_price', $callback, 10, 2 );
Description
Filters the displayed price for a course on the grid. Modify the `$course_price` parameter to change how the course price is presented. This hook is ideal for custom price formatting or conditionally hiding/displaying the price on course grids.
Usage
add_filter( 'uo_course_grid_ribbon_price', 'your_function_name', 10, 2 );
Parameters
-
$course_price(mixed) - This parameter contains the raw price of the course as it's currently being processed for display in the course grid.
-
$course(mixed) - This parameter contains the formatted course price that will be displayed on the course grid ribbon.
Return Value
The filtered value.
Examples
// Example: Add a special "Sale!" badge to courses that are currently on sale.
function my_custom_course_sale_ribbon( $course_price, $course_id ) {
// Check if the course is actually on sale.
// This is a hypothetical check; you'd replace this with your actual logic
// to determine if a course is on sale (e.g., checking custom meta fields).
$is_on_sale = get_post_meta( $course_id, '_is_course_on_sale', true );
if ( $is_on_sale === 'yes' ) {
// If it's on sale, return a special string for the ribbon.
// You might also want to format the actual price differently here.
return '<span class="course-sale-badge">Sale!</span> ' . esc_html( $course_price );
}
// Otherwise, return the original price without modification.
return $course_price;
}
add_filter( 'uo_course_grid_ribbon_price', 'my_custom_course_sale_ribbon', 10, 2 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/templates/course-grid.php:68
default:
$output = esc_html( $course_price_type );
break;
}
echo wp_kses_post( apply_filters( 'uo_course_grid_ribbon_text', $output, $course->ID ) );
do_action( 'uo_course_after_grid_ribbon_text', $course->ID );
} else {
echo wp_kses_post( apply_filters( 'uo_course_grid_ribbon_price', $course_price, $course->ID ) );
do_action( 'uo_course_after_grid_ribbon_price', $course->ID );
}
?>
</div>
<?php } ?>
<!-- Price Ribbon section -- End -->