Tribe__Tickets_Plus__Commerce__WooCommerce__Global_Stock::maybe_increase_global_stock( int $post_id, int $product_id, Tribe__Tickets__Ticket_Object $ticket, int $stock_increase = 1 )
Maybe Increase the Global Stock
Contents
See also
- Tribe__Tickets__Ticket_Object::global_stock_mode(): Definitions for the various ways to account for stock.
Parameters
- $post_id
-
(int) (Required) The post or event id for the attendee.
- $product_id
-
(int) (Required) The ticket-product id in WooCommerce.
- $ticket
-
(Tribe__Tickets__Ticket_Object) (Required) A ticket object.
- $stock_increase
-
(int) (Optional) An integer to increase stock by.
Default value: 1
Source
File: src/Tribe/Commerce/WooCommerce/Global_Stock.php
public function maybe_increase_global_stock( $post_id, $product_id, Tribe__Tickets__Ticket_Object $ticket, $stock_increase = 1) {
if ( Tribe__Tickets__Global_Stock::OWN_STOCK_MODE !== $ticket->global_stock_mode() ) {
$global_stock_obj = new Tribe__Tickets__Global_Stock( $post_id );
$new_stock = $global_stock_obj->get_stock_level() + $stock_increase;
$global_stock_obj->set_stock_level( $new_stock );
if ( Tribe__Tickets__Global_Stock::CAPPED_STOCK_MODE === $ticket->global_stock_mode() ) {
$capped_stock = get_post_meta( $product_id, Tribe__Tickets__Global_Stock::TICKET_STOCK_CAP, true );
$new_capped_stock = $capped_stock + $stock_increase;
update_post_meta( $product_id, Tribe__Tickets__Global_Stock::TICKET_STOCK_CAP, $new_capped_stock, $capped_stock );
}
}
}
Changelog
| Version | Description |
|---|---|
| 4.10.4 | Introduced. |