Tribe__Tickets__Global_Stock::set_stock_level( int $quantity, boolean $force = false )
Sets the global stock level for the current post.
Contents
Parameters
- $quantity
-
(int) (Required) Quantity to set for stock.
- $force
-
(boolean) (Optional) Whether to force setting stock, even if capacity is less.
Default value: false
Return
(bool|int)
Source
File: src/Tribe/Global_Stock.php
public function set_stock_level( $quantity ) {
$capacity = tribe_tickets_get_capacity( $this->post_id );
$quantity = (int) $quantity;
// When we are dealing with non-unlimited capacities verify before updating the Post
if (
! is_null( $capacity ) // We need to verify null to prevent capacity check when it doesn't exist
&& $capacity >= 0
&& $quantity > $capacity
) {
$quantity = $capacity;
}
$status = update_post_meta( $this->post_id, self::GLOBAL_STOCK_LEVEL, $quantity );
/**
* Fires when the global stock level is set/changed.
*
* @since 4.1
* @since 4.6 Added $status param
*
* @param int $post_id
* @param int $quantity
* @param bool $status
*/
do_action( 'tribe_tickets_global_stock_level_changed', $this->post_id, $quantity, $status );
return $status;
}
Changelog
| Version | Description |
|---|---|
| 4.6 | Added a Return |
| 4.11.4 | Added new $force parameter. |
| 4.1 | Introduced. |