Tribe__Tickets__RSVP::decrease_ticket_sales_by( int $ticket_id, int $quantity = 1 )
Decrease the sales for a ticket by a specific quantity.
Contents
Parameters
- $ticket_id
-
(int) (Required) The ticket post ID.
- $quantity
-
(int) (Optional) The quanitity to decrease the ticket sales by.
Default value: 1
Return
(int) The new sales amount.
Source
File: src/Tribe/RSVP.php
public function decrease_ticket_sales_by( $ticket_id, $quantity = 1 ) {
// Adjust sales.
$sales = (int) get_post_meta( $ticket_id, 'total_sales', true ) - $quantity;
// Prevent negatives.
$sales = max( $sales, 0 );
update_post_meta( $ticket_id, 'total_sales', $sales );
// Adjust stock.
$stock = (int) get_post_meta( $ticket_id, '_stock', true ) + $quantity;
update_post_meta( $ticket_id, '_stock', $stock );
return $sales;
}
Changelog
| Version | Description |
|---|---|
| 5.1.0 | Introduced. |