LLMS_Controller_Orders::transition_status( string $new_status, string $old_status, WP_Post $post )
Trigger actions when the status of LifterLMS Orders and LifterLMS Transactions change status.
Parameters Parameters
- $new_status
-
(string) (Required) New status.
- $old_status
-
(string) (Required) Old status.
- $post
-
(WP_Post) (Required) WP_Post instance of the transaction.
Return Return
(void)
Source Source
File: includes/controllers/class.llms.controller.orders.php
if ( $order->is_legacy() ) {
return;
}
// Update the status based on the order type.
$status = $order->is_recurring() ? 'llms-active' : 'llms-completed';
$order->set( 'status', $status );
$order->set( 'last_retry_rule', '' ); // Retries should always start with tne first rule for new transactions.
// Maybe schedule a payment.
$order->maybe_schedule_payment();
}
/**
* Trigger actions when the status of LifterLMS Orders and LifterLMS Transactions change status.
*
* @since 3.0.0
* @since 3.19.0 Unknown.
*
* @param string $new_status New status.
* @param string $old_status Old status.
* @param WP_Post $post WP_Post instance of the transaction.
* @return void
*/
public function transition_status( $new_status, $old_status, $post ) {
// Don't do anything if the status hasn't changed.
if ( $new_status === $old_status ) {
return;
}
// We're only concerned with order post statuses here.
if ( 'llms_order' !== $post->post_type && 'llms_transaction' !== $post->post_type ) {
return;
}
$post_type = str_replace( 'llms_', '', $post->post_type );
$obj = 'order' === $post_type ? new LLMS_Order( $post ) : new LLMS_Transaction( $post );
// Record order status changes as notes.
if ( 'order' === $post_type ) {
$obj->add_note( sprintf( __( 'Order status changed from %1$s to %2$s', 'lifterlms' ), llms_get_order_status_name( $old_status ), llms_get_order_status_name( $new_status ) ) );
}
// Remove prefixes from all the things.
$new_status = str_replace( array( 'llms-', 'txn-' ), '', $new_status );
$old_status = str_replace( array( 'llms-', 'txn-' ), '', $old_status );
/**
* Fired when a LifterLMS order or transaction changes status.
*
* The first dynamic portion of this hook, `$post_type`, refers to the unprefixed object post type ('order|transaction').
* The second dynamic portion of this hook, `$old_status`, refers to the previous object status.
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 3.19.0 | Unknown. |
| 3.0.0 | Introduced. |