uo_course_before_grid_ribbon_text
Fires before the course grid ribbon text is displayed, allowing modification.
add_action( 'uo_course_before_grid_ribbon_text', $callback, 10, 1 );
Description
Fires before the price ribbon text is displayed for a course on the grid. This hook allows developers to inject custom content or modify the display before the ribbon text. Useful for adding custom pricing information or conditional elements related to the course's price display.
Usage
add_action( 'uo_course_before_grid_ribbon_text', 'your_function_name', 10, 1 );
Parameters
-
$course(mixed) - This parameter contains the course object being displayed in the grid.
Examples
<?php
/**
* Example: Display a custom message before the price ribbon text for a course grid item.
*
* This function hooks into the 'uo_course_before_grid_ribbon_text' action.
* It receives the course object as a parameter.
* It checks if the course has a specific meta key set and, if so,
* echoes a personalized message.
*/
add_action( 'uo_course_before_grid_ribbon_text', function( $course ) {
// Ensure we have a valid course object and it has an ID property.
if ( ! $course || ! isset( $course->ID ) ) {
return;
}
// Check if a custom message meta key exists for this course.
$custom_message = get_post_meta( $course->ID, '_course_grid_ribbon_message', true );
if ( ! empty( $custom_message ) ) {
// Sanitize and display the custom message.
echo '<span class="custom-ribbon-message">' . esc_html( $custom_message ) . '</span> ';
}
}, 10, 1 ); // Priority 10, accepts 1 argument.
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:38
<?php do_action_deprecated( 'uo-course-grid-before-course-info-holder', array( $course ), '3.7.11', 'uo_course_grid_before_course_info_holder' ); ?>
<?php do_action( 'uo_course_grid_before_course_info_holder', $course ); ?>
<!-- Price Ribbon section -->
<?php if ( 'yes' === $atts['price'] && 'yes' === $atts['show_image'] ) { ?>
<div id="ribbon"
class="price <?php echo ! empty( $course_price_type ) ? esc_attr( 'price_' . $currency ) : esc_html( $course_price_type ); ?>">
<?php
do_action( 'uo_course_before_grid_ribbon_text', $course->ID );
if ( empty( $course_price ) ) {
switch ( strtolower( $course_price_type ) ) {
case 'open':
case 'free':
$output = esc_attr__( 'Free', 'uncanny-pro-toolkit' );
break;