wpim_reserve_confirmation_sent

Unlike the reserve_confirmation hook that runs at the exact time the reserve confirmation email is sent, this hook fires after the reservation confirmation is sent. It is directly after reserve_confirmation.

/**
 * @param $inventory_id
 * @param $data
 * @param $subject
 * @param $message
 */
function my_custom_function($inventory_id, $data, $subject, $message) {
   // As an example how to get the item info, you could do the following...
   $item_info = new WPIMItem();  // Call new instance of WPIMItem class
   $item_info = $item_info->get( $inventory_id );  // Get the item information with inventory id
   $name = $item_info->inventory_name;  // Example of how you would get the name of an item

   // Do whatever you want from here!
}

add_action('wpim_reserve_confirmation_sent', 'my_custom_function', 10, 4);

reserve_confirmation

This hook is run after successfully passing error validation. This hook only fires if the send confirmation email to the requester is set to yes in the settings.

function my_custom_function($confirm_email, $subject, $message) {
	$confirm_email; // Email from the reserve form (reserving party email)
	$subject; // Subject of the email that was sent out
	$message; // Message of email sent

	// Do whatever you want with this information

}

add_action('reserve_confirmation', 'my_custom_function', 10, 3);

wpim_save_reserve

This function runs during save.  It runs for each item.  So, with core WPIM only, it runs after each reservation because only one item can be reserved at a time with just core.  If you have Reserve Cart, then this runs for each item in the cart.

function my_custom_function($inventory_id, $quantity, $original_quantity) {
   $inventory_id; // Item id
   $quantity; // Quantity reserved
   $original_quantity; // The quantity the item had at the time of the reserve (not including the reduction)

   // Get the item information

   $item_info = new WPIMItem();  // Call new instance of WPIMItem class
   $item_info = $item_info->get( $inventory_id );  // Get the item information with inventory id
   $name = $item_info->inventory_name;  // Example of how you would get the name of an item

    // Do whatever you want from here!

}

add_action('wpim_save_reserve', 'my_custom_function', 10, 3);

Reserve Form Actions

WP Inventory Reserve Form Actions

WP Inventory reserve form actions can really help you to build your brand and customize your presentation.  Another possibility is to add messages to the checkout page.  Options are seemingly endless.  Below and in the right hand side navigation; are links to various different action hooks with example code.

wpim_reserve_sent – This hook allows you to get information about an item that was reserved after the email is sent to the admin.  If Reserve Cart is installed and active, it runs for each item in the cart. This is run after error checking.  Only run if decrease quantity setting on reserve is set to true.

wpim_save_reserve – This hook runs after each item on reserve when it is being saved.  This is run after error checking.

reserve_confirmation – This hook runs at the time the email is being sent to the reserver.  Must have send email confirmation to customer set to on.

wpim_reserve_confirmation_sent – This hook fires after the reserve_confirmation hook.

 

 

wpim_reserve_sent

This action allows you to get four pieces of data in order to do something different with it after the reserve email has been sent.  This does not modify the info sent to the user, it is just available if you want to add it to another table in your database, send it to another person (like an admin of your site), etc.


function my_custom_function($inventory_id, $data, $subject, $message) {
$inventory_id; // Id of the inventory item that was just reserved
$data; // The array of information from the reserve form (not the cart data)
$subject; // Subject of the email
$message; // Message of the email

// Get the item information

$item_info = new WPIMItem(); // Get new instance of the item class
$item_info = $item_info->get( $inventory_id ); // use the get method with the inventory id to get item information

$name = $item_info->inventory_name;  // Example to fetch the item name

// Do whatever you want from here!

}

add_action('wpim_reserve_sent', 'my_custom_function', 10, 4); 

Extending Reserve Form

Extending the Reserve Form

1.  In order to accomplish this job you are going to first have to setup your own reserve-form.php file via the template override system.  This is important because if you ever do an update with us, your form will not get wiped out.  So, you will want to copy that from the plugins directory and then setup the override system as explained here:

Template Override System

2.  So, now that you have copied over the file to a location that looks like:

/wp-content/themes/your-theme-name/wpinventory/views/reserve-form.php

We can start to modify it.

3.  For this tutorial, we will setup a check for the logged in user’s ID.  You want to paste this block of code inside the reserve-form.php file above the submit button some place.  You can put it wherever you want, just make sure you insert it between areas of PHP:

<?php if ($display_user) {

// Use WordPress Built in functionality to find the logged in user

if (!is_user_logged_in()) {
$user = 'Unknown User';
} else {
$user = get_current_user_id();
}

$required = ($display_user == 2) ? ' required' : '';  ?>
<div class="user"<?php echo $required; ?> style="display: none;">
<label><?php echo $user_label; ?><?php if ($required) { echo '<span class="req">*</span>'; } ?></label>
<input type="hidden" name="wpinventory_reserve_user" value="<?php echo $user; ?>"<?php echo $required; ?> />
</div>
<?php } ?>

Please notice the inline style that is “display: none;”.  You can do this to hide this block from the form.  It is an input we are going to take automatically without the user filling out anything at all.  And, to that point, the input is also type=”hidden”.  If the user is not logged in, it assigns the value “Unknown User”.  You can get creative and do your own checks for different conditions, etc., but for this tutorial we have done a basic one for a default value.

4.  Now, you need to go to your functions.php file located in your theme directory.  Then copy the following into it:
add_action('wpim_reserve_config', 'my_reserve_form_customizations');
function my_reserve_form_customizations($args)
{
$args = wpinventory_reserve_add_field($args, 'user', 'optional', 'User ID', 'wpinventory_reserve_name');

return $args;
}

What this is doing is passing the information along to the processor once the form field you just added in step three above has been added.  You need the add_action and you need the function.  What this function does is accepts five arguments:

4.1 –

$args

– you always have to have this and never need to change it.  It is always

$args

4.2 –  The next one is the name of the input.  Ours is ‘user’

4.3 –  The next one is if it is optional or required.  I have elected to make it optional.

4.4  –  The next one is the label.  The text that will sit next to the input on the form.  It is also the text that will be passed in the confirmation email.

4.5 –  The last one is the position in the form.  When you want to put the field in a certain position you need to know the name value of the field before it.  Passing this to the fifth parameter of this function will tell it to put the new field directly above the one you gave it the name for.

5.  To setup another field, you would just repeat the process by adding a new line like this:

$args = wpinventory_reserve_add_field($args, 'user', 'optional', 'User ID', 'wpinventory_reserve_name');
$args = wpinventory_reserve_add_field($args, 'project', 'required', 'Project', 'wpinventory_reserve_user');

So in this example, we added another field right under the ‘user’ called ‘project’ and gave it a label of “Project” and we want it to be required.  We then have to go back over to the reserve form, and again add that field:

<?php if ($display_project) {
$required = ($display_project == 2) ? ' required' : '';  ?>
<div class="state"<?php echo $required; ?>>
<label><?php echo $project_label; ?><?php if ($required) { echo '<span class="req">*</span>'; } ?></label>
<input type="text" name="wpinventory_reserve_project" value="<?php echo $project; ?>"<?php echo $required; ?> />
</div>
<?php } ?>

6.  You can now navigate to your form and fill it out and submit it.  You will receive an email that will have these details in it for you as well as whatever normal settings you have set through the dashboard.

Using the logic of this tutorial, you can put any field types you want in the reserve form.  Such as checkboxes, radio buttons, textarea, etc.

Reserve System

Reserve System

The reserve system is a nice feature to help convert your users to paying clients!

Using the reserve system allows you to enable a reserve form on your inventory item pages.  A user can fill in this reserve form and they will then be allowed to pick it up at a later time.  They get an email confirmation and the administrator also gets a confirmation email.  In addition, the quantity decreases by the reserve amount automatically in the system. For more information, please refer to the Reserve Setting section in the Quick Start Guide.

Be advised that emails being sent are dependent on your server settings and/or host environment.  For best results with regards to receiving emails, we strongly recommend the WP Mail SMTP plugin.

Previewing reservation entries

This is possible with our Ledger Add-On.  By default, the reservation system does not keep journal entries of the emails or for whom reserved the item(s).  If you would like a log of this from the dashboard as well as ability to invoice; then you will need the Ledger Add-On as well.