WordPress at Your Fingertips
function is not described

WC_Order::maybe_set_date_paid() public WC 3.0.0

Maybe set date paid.

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.

{} It's a method of the class: WC_Order{}


null. Nothing.


$WC_Order = new WC_Order();


Since 3.0.0 Introduced.

Code of WC_Order::maybe_set_date_paid() WC 5.7.1

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() );