Badges¶
Functions for working with listing badges.
See the Badge object reference for all methods available on the returned object.
Functions¶
dms_get_badge( int|string $id ): Badge¶
Retrieves a single badge by its ID or text value.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$id |
int\|string |
- | The badge ID or badge text |
Returns - Badge
Example
$badge = dms_get_badge( 1 );
echo esc_html( $badge->get( 'text' ) );
echo esc_html( $badge->get( 'badge_color' ) );
dms_get_type_badges( int $type_id = 0, array $args = [] ): array¶
Returns all badges registered for a specific inventory type. Defaults to the current type when $type_id is 0.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$type_id |
int |
0 |
The type ID. 0 uses the current type. |
$args |
array |
[] |
Optional args to filter the results |
Returns - Badge[]
Example
// Current type's badges
$badges = dms_get_type_badges();
foreach ( $badges as $badge ) {
echo esc_html( $badge->get( 'text' ) );
}
// Specific type
$badges = dms_get_type_badges( 1 );
dms_add_type_badge( array $badge_data ): int¶
Creates a new badge for an inventory type. Returns the new badge ID.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$badge_data |
array |
- | Badge data including type_id, text, badge_color, font_color, and font_size |
Returns - int
Example
$badge_id = dms_add_type_badge( [
'type_id' => 1,
'text' => 'New Arrival',
'badge_color' => '#e74c3c',
'font_color' => '#ffffff',
'font_size' => 11,
] );
dms_delete_badge( int $id ): bool¶
Deletes a badge by ID.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$id |
int |
- | The badge ID to delete |
Returns - bool
Example
dms_get_badge_options(): array¶
Returns all registered badge option field definitions.
Returns - array
Example