WC_Order::maybe_set_date_paid()

Maybe set date paid.


Description Description

Sets the date paid variable when transitioning to the payment complete order status. This is either processing or completed. This is not filtered to avoid infinite loops e.g. if loading an order via the filter.

Date paid is set once in this manner – only when it is not already set. This ensures the data exists even if a gateway does not use the payment_complete method.


Source Source

File: includes/class-wc-order.php

	public function maybe_set_date_paid() {
		// This logic only runs if the date_paid prop has not been set yet.
		if ( ! $this->get_date_paid( 'edit' ) ) {
			$payment_completed_status = apply_filters( 'woocommerce_payment_complete_order_status', $this->needs_processing() ? 'processing' : 'completed', $this->get_id(), $this );

			if ( $this->has_status( $payment_completed_status ) ) {
				// If payment complete status is reached, set paid now.
				$this->set_date_paid( time() );

			} elseif ( 'processing' === $payment_completed_status && $this->has_status( 'completed' ) ) {
				// If payment complete status was processing, but we've passed that and still have no date, set it now.
				$this->set_date_paid( time() );
			}
		}
	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.