Filter Image Sizes

Filtering the images field sizes

If you would like to set the images size differently for the listing or display using some easy to use filters, here is how.  Copy and paste the below code into your function.php file:


add_filter( 'wpim_images_size', 'my_function', 10, 2 );

/**
* Return a custom size for images (vs image)
* @param string $size - original size from settings
* @param string $context - detail or listing
*
* @return string - should be thumbnail, medium, large, full
**/
function my_function( $size, $context ) {
if ( 'detail' == $context ) {
// this value is used for detail / single
return 'full';
}

// this value is used for listing
return 'large';
}

Filter Reserve Messages

Filtering WP Inventory Reserve Message

You can set custom success messages in your code for when a user makes a reservation.  There are  a couple:

 Just the core only (no reserve cart):

This will allow you to change the message that is displayed in the page.


add_filter( 'wpim_reserve_email_message', 'my_reserved_message_function');
function my_reserved_message_function( $message ) { 
$message = 'My new "Items Reserved" custom message.';
 
return $message; 
}

With Reserve Cart Add On

This will allow you to change the message displayed in the page.


add_filter('wpim_reserve_reserved_message', 'my_reserved_message_function');

function my_reserved_message_function( $message ) {
$message = 'My new "Items Reserved" custom message.';

return $message;
}

For the Widget

This will change the success message in the widget if you are using the widget in a sidebar on the page


add_filter('wpim_reserve_checkout_message', 'my_checkout_message_function');

function my_checkout_message_function( $message ) {
$message = 'Custom success message for the widget.';

return $message;
}

 

Hide Add to Cart for Certain User Roles

You can suppress the add to cart on both the listing and detail page in this fashion:

Listing Page:

In your theme’s functions.php file add the following code.  Where you see ‘customer’, ‘administrator’; you can add more like ‘, ‘subscriber’, ‘editor’, … etc.  That will suppress the button from any logged in user NOT assigned one of those roles.


add_filter('wpim_cart_hide_button_in_listing','wpim_button_by_role');
function wpim_button_by_role( $hide ) {
$current_user = new WP_User( get_current_user_id() );
$user_role = ( ! empty( $current_user->roles ) ) ? array_shift( $current_user->roles ) : NULL;

if ( ! $user_role || ! in_array( $user_role, array( 'customer', 'administrator' ) ) ) {
$hide = TRUE;
}

return $hide;
}

 

Detail Page:

The detail page can suppress the add to cart in one of the following two ways:

1.  Template Override: –  copy the reserve_cart/views/add-to-cart.php template to the theme’s wpinventory/views/add-to-cart.php folder, then at the top add:


$current_user = new WP_User( get_current_user_id() );
$user_role    = ( ! empty( $current_user->roles ) ) ? array_shift( $current_user->roles ) : NULL;

if ( ! $user_role || ! in_array( $user_role, array( 'customer', 'administrator' ) ) ) {
return;
}

2.  Filter:   Hook into this filter and add this function which leverages the already-existing function used to hide the button on the listing page under the “Listing Page” heading above  (this is the “recommended” way, but either will work).


add_filter( 'wpim_get_template_part_path_<wbr />reserve-form.php', 'wpim_hide_button_in_detail', 99999, 1 );

function wpim_hide_button_in_detail( $template ) {
if ( wpim_button_by_role( FALSE ) {
// return nothing, which will cause the system to NOT render the template.
return '';
}

return $template;
}

Filters

WP Inventory Manager Filters

Welcome to the documentation for WPIM filters

WP Inventory is built with developers in mind, and includes a long list of filters and actions that may be leveraged to control the way WP Inventory behaves.  You can use any number of the filters in the right hand sidebar.  If you feel we are missing one or would like to see something added, please reach out to us at [email protected].

For more information on WordPress filters, please refer to the WordPress Plugin API Filter Reference.