All Features

Customization of Single Item Details

In version 2.2.1 of the RW Elephant Rental Inventory Plugin, we've introduced some new WordPress Filters that allow advanced WordPress users and developers to have more control over the information being output for each section of the Item Detail page.

The new Filters include:

  • rw_elephant_product_rental_price – Filter the Item Price
  • rw_elephant_product_quantity – Filter the Item Quantity
  • rw_elephant_product_dimensions – Filter the product Dimensions
  • rw_elephant_product_tags – Filter the Item Tags
  • rw_elephant_product_custom_id – Filter the Custom ID
  • rw_elephant_product_custom_field_1 – Filter Custom Field 1
  • rw_elephant_product_custom_field_2 – Filter the Custom Field 2

We have included some examples below of how the new Filters can be used to Change the output for each section of the Item Detail page.

Filter the product price:

// Add the text "each" after the Price

function rw_elephant_product_rental_price( $price, $item_details ) {

    return sprintf( '%s each', $price );

}

add_filter( 'rw_elephant_product_rental_price', 'rw_elephant_product_rental_price', 10, 2 );

Filter the product quantity:

// If the Quantity is "0" then output "Out of Stock", otherwise output the Quantity value followed by the text "left" (e.g. "6 left")

function rw_elephant_product_quantity( $quantity, $item_details ) {

    if ( 0 === (int) $quantity ) {

        return 'Out of Stock';

    }

    return sprintf( '%s left', $quantity );

}

add_filter( 'rw_elephant_product_quantity', 'rw_elephant_product_quantity', 10, 2 );

Filter the product dimensions:

// If the Dimensions of the item are "10 x 10 x 10" then output "10cubed" other wise output the Dimensions value.

function rw_elephant_product_dimensions( $dimensions, $item_details ) {

    switch ( $dimensions ) {

        default:
            return $dimensions;

        case '10 x 10 x 10':
            return '10³';

    }

}

add_filter( 'rw_elephant_product_dimensions', 'rw_elephant_product_dimensions', 10, 2 );

Output a custom tag for a sepcific Item (by ID):

// If the Item ID matches the value "176483" then output the custom tag, otherwise output the default tag

function rw_elephant_product_tags( $tags, $item_details ) {

    if ( 176483 !== (int) $item_details['inventory_item_id'] ) {

        return $tags;

    }

    $tags[] = '<a href="#" class="custom-tag">Custom Tag</a>';

    return $tags;

}

add_filter( 'rw_elephant_product_tags', 'rw_elephant_product_tags', 10, 2 );

Change the “Custom ID” for an Item Item (by ID):

// If the Item ID matches "176483" then return the specified text "Custom ID for Product 176483", otherwise output the Custom ID

function rw_elephant_product_custom_id( $custom_id, $item_details ) {

    if ( 176483 !== (int) $item_details['inventory_item_id'] ) {

        return $custom_id;

    }

    return 'Custom ID for Product 176483';

}

add_filter( 'rw_elephant_product_custom_id', 'rw_elephant_product_custom_id', 10, 2 );

Change “Custom Field 1” for an Item Item (by ID):

// If the Item ID matches "176483" then return the specified text "Custom Field 1 for Product 176483", otherwise output the "Custom Field 1" value

function rw_elephant_product_custom_field_1( $custom_field, $item_details ) {

    if ( 176483 !== (int) $item_details['inventory_item_id'] ) {

        return $custom_field;

    }

    return 'Custom Field 1 for Product 176483';

}

add_filter( 'rw_elephant_product_custom_field_1', 'rw_elephant_product_custom_field_1', 10, 2 );

Change “Custom Field 2” for an Item Item (by ID):

// If the Item ID matches "176483" then return the specified text "Custom Field 2 for Product 176483", otherwise output the "Custom Field 2" value

function rw_elephant_product_custom_field_2( $custom_field, $item_details ) {

    if ( 176483 !== (int) $item_details['inventory_item_id'] ) {

        return $custom_field;

    }

    return 'Custom Field 2 for Product 176483';

}

add_filter( 'rw_elephant_product_custom_field_2', 'rw_elephant_product_custom_field_2', 10, 2 );