Skip to content

Badge

Namespace: DMS\Badge Obtained via: dms_get_badge(), dms_get_type_badges()

Represents a single listing badge. Badges are displayed on listing cards and VDP pages and can be triggered by sold/sale-pending status or configurable conditions.


Core

get_id(): int

Returns the badge ID.

$id = $badge->get_id();

exists(): bool

Returns true if the badge was found.

if ( $badge->exists() ) { ... }

get( string $name ): mixed

Returns a badge property or setting value.

Direct properties: id, type_id, text, badge_color, font_color, font_size

echo esc_html( $badge->get( 'text' ) );         // e.g. "New Arrival"
echo esc_html( $badge->get( 'badge_color' ) );  // e.g. "#e74c3c"
echo esc_html( $badge->get( 'font_color' ) );   // e.g. "#ffffff"
echo $badge->get( 'font_size' );    // e.g. 11
echo $badge->get( 'type_id' );

set( $name, $value ): bool|int

Updates a badge property or setting and persists to the database. Direct properties (text, font_color, badge_color, font_size) update their own column; everything else is stored in the serialized settings column.

$badge->set( 'text', 'Featured' );
$badge->set( 'badge_color', '#2ecc71' );

delete(): bool

Deletes the badge.

$badge->delete();