WC_Order_Data_Store_CPT::update
Method to update an order in the database.
Method of the class: WC_Order_Data_Store_CPT{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$WC_Order_Data_Store_CPT = new WC_Order_Data_Store_CPT(); $WC_Order_Data_Store_CPT->update( $order );
- $order(WC_Order) (required) (passed by reference — &)
- Order object.
WC_Order_Data_Store_CPT::update() WC Order Data Store CPT::update code WC 10.4.3
public function update( &$order ) {
// Before updating, ensure date paid is set if missing.
if ( ! $order->get_date_paid( 'edit' ) && version_compare( $order->get_version( 'edit' ), '3.0', '<' ) ) {
/**
* Filter the order status to use when payment is complete.
*
* @since 3.0.0
*
* @param string $payment_complete_status Default status to use when payment is complete.
* @param int $order_id Order ID.
*/
$payment_complete_status = apply_filters( 'woocommerce_payment_complete_order_status', $order->needs_processing() ? OrderStatus::PROCESSING : OrderStatus::COMPLETED, $order->get_id(), $order );
if ( $order->has_status( $payment_complete_status ) ) {
$order->set_date_paid( $order->get_date_created( 'edit' ) );
}
}
// Also grab the current status so we can compare.
$previous_status = get_post_status( $order->get_id() );
// If the order doesn't exist in the DB, we will consider it as new.
if ( ! $previous_status && $order->get_id() === 0 ) {
$previous_status = 'new';
}
// Update the order.
parent::update( $order );
$current_status = $order->get_status( 'edit' );
// We need to remove the wc- prefix from the status for comparison and proper evaluation of new vs updated orders.
$previous_status = OrderUtil::remove_status_prefix( $previous_status );
$current_status = OrderUtil::remove_status_prefix( $current_status );
$draft_statuses = array( 'new', OrderStatus::AUTO_DRAFT, OrderStatus::DRAFT, 'checkout-draft' );
// This hook should be fired only if the new status is not one of draft statuses and the previous status was one of the draft statuses.
if (
$current_status !== $previous_status
&& ! in_array( $current_status, $draft_statuses, true )
&& in_array( $previous_status, $draft_statuses, true )
) {
do_action( 'woocommerce_new_order', $order->get_id(), $order ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
return;
}
do_action( 'woocommerce_update_order', $order->get_id(), $order ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
}