Tribe__Tickets__Commerce__PayPal__Order::update()
Updates an order data on the database.
Return
(int|false) Either the updated/created order post ID or false if the Order could not be saved.
Source
File: src/Tribe/Commerce/PayPal/Order.php
public function update() {
if ( empty( $this->paypal_order_id ) ) {
return false;
}
$meta_input = array(
$this->hashed_meta_key => array(),
self::$meta_prefix . 'attendees' => wp_list_pluck( $this->attendees, 'attendee_id' ),
);
foreach ( $this->meta as $key => $value ) {
if ( in_array( $key, $this->searchable_meta_keys ) ) {
$key = self::$meta_prefix . $key;
$meta_input[ $key ] = $value;
} else {
$meta_input[ $this->hashed_meta_key ][ $key ] = $value;
}
}
if ( empty( $this->status ) ) {
$this->status = Tribe__Tickets__Commerce__PayPal__Stati::$undefined;
}
$postarr = array(
'post_type' => Tribe__Tickets__Commerce__PayPal__Main::ORDER_OBJECT,
'post_title' => $this->paypal_order_id,
'post_status' => $this->status,
'meta_input' => $meta_input,
);
/**
* Filters the post array that will be saved to the database for the Order post.
*
* @since 4.7
*
* @param array $postarr
* @param Tribe__Tickets__Commerce__PayPal__Order $order
*/
$postarr = apply_filters( 'tribe_tickets_tpp_order_postarr', $postarr, $this );
if ( empty( $this->post_id ) ) {
$post_id = wp_insert_post( $postarr );
} else {
// remove any existing PayPal meta before the update
global $wpdb;
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->postmeta} WHERE post_id = %d and meta_key LIKE %s",
$this->post_id,
self::$meta_prefix . '%'
)
);
wp_cache_delete( $this->post_id, 'post_meta' );
$postarr['ID'] = $this->post_id;
$post_id = wp_update_post( $postarr );
}
if ( ! empty( $post_id ) ) {
foreach ( $this->ticket_ids as $ticket_id ) {
add_post_meta( $post_id, self::$meta_prefix . 'ticket', $ticket_id );
}
foreach ( $this->post_ids as $related_post_id ) {
add_post_meta( $post_id, self::$meta_prefix . 'post', $related_post_id );
}
}
}
Changelog
| Version | Description |
|---|---|
| 4.7 | Introduced. |