WP Inventory Item Detail Page Actions

These actions allow you to expand the functionality of the item detail page, hooking into every field or only specified fields to add your desired additions.

  • wpim_single_before_the_field: This action is triggered before every field is rendered in the single item display.
  • wpim_single_before_the_field_[FIELD]: This action is triggered immediately after wpim_single_before_the_field, but only for the specified field (e.g. wpim_single_before_the_field_inventory_name would only trigger for the name field).
  • wpim_the_field_close: This action is triggered after every field is rendered in the single item display.
  • wpim_the_field_[FIELD]: This action is triggered immediately after wpim_the_field_close, but only for the specified field (e.g. wpim_the_field_inventory_name would only trigger for the name field).

Each of the listed hooks pass two arguments into the action function: $field and $inventory_display. The $field variable is the CSS class of the targetted inventory field, and the $inventory_display variable is an array of all the fields set to display for the item in the Display settings.

Below are several basic examples of how to hook into each of these actions, with simple functions based on the field. However, the possibilities go much deeper. You could run multiple different notices in one function by checking what fields are being displayed, or always ensure a field is displayed regardless of your display settings by pushing a value into the $inventory_display array if it’s not already there.

add_action( 'wpim_single_before_the_field', 'my_custom_function_before', 10, 2 ); 
/* Echo a notice before each field that specifies the field */ 
function my_custom_function_before( $field, $inventory_display ) { 
     echo "<span style='display: block;'>I'm displaying before the " . $field . " field!</span>"; 
}

 

add_action( 'wpim_single_before_the_field_inventory_price', 'sale_price_notice_before' ); 
/* Echo a Sale Price notice BEFORE the price field */ 
function sale_price_notice_before() { 
     echo "<span style='display: block; color: red;'>SALE PRICE!</span>"; 
}

 

add_action( 'wpim_the_field_inventory_price', 'sale_price_notice_after' ); 
/* Echo a Sale Price notice AFTER the price field */ 
function sale_price_notice_after() { 
     echo "<span style='display: block; color: red;'>SALE PRICE!</span>"; 
}

 

add_action( 'wpim_the_field_close', 'my_custom_function_after', 10, 2 ); 
/* Echo a Limited Availability notice after the name field */ 
function my_custom_function_after( $field, $inventory_display ) { 
     if ( $field != 'inventory_name' ) { 
          return; 
     } 
     echo "<span style='display: block; color: red;'>Limited Time Item!</span>"; 
}