How to Customize GP Inventory Messages in Gravity Forms

Gravity Forms Inventory (GP Inventory) provides powerful stock management for Gravity Forms. It’s especially useful when selling products or tickets, or when managing bookable resources such as events, appointments, or reservations.

In the case of an event with multiple dates, displaying the number of remaining seats can significantly increase conversions. GP Inventory offers several built-in options, such as:

  • Displaying out-of-stock choices
  • Showing stock quantities
  • Disabling selections automatically

However, it does not allow you to fully customize the message displayed when stock reaches zero (for example, replacing “0 available” with “SOLD OUT” or “FULLY BOOKED”).

The snippet below allows you to override the default behavior and display a custom message when inventory reaches 0.

Example: Display “SOLD OUT” Instead of “0”

Add the following code to your custom plugin (or MU-plugin):

<?php
/**
 * GP Inventory // Sold Out Message (custom)
 */
add_filter( 'gpi_remove_choices', '__return_false' );
add_filter( 'gpi_pre_render_choice', function( $choice, $exceeded_limit, $field, $form, $count ) {
    $limit        = (int) rgar( $choice, 'inventory_limit' );
    $how_many_left = max( $limit - $count, 0 );
    if ( $how_many_left <= 0 ) {
        $message = ' <strong>SOLD OUT</strong>';
        $default_message = gp_inventory_type_choices()->replace_choice_available_inventory_merge_tags(
            gp_inventory_type_choices()->get_inventory_available_message( $field ),
            $field,
            $form,
            $choice,
            $how_many_left
        );
        if ( strpos( $choice['text'], $default_message ) === false ) {
            $choice['text'] .= ' ' . $message;
        } else {
            $choice['text'] = str_replace( $default_message, $message, $choice['text'] );
        }
    }
    return $choice;
}, 10, 5 );
?>

 

Submit a Comment

Your email address will not be published. Required fields are marked *