diff --git a/orders/renewal-label-for-renewal-orders-only.php b/orders/renewal-label-for-renewal-orders-only.php new file mode 100644 index 0000000..c5348e9 --- /dev/null +++ b/orders/renewal-label-for-renewal-orders-only.php @@ -0,0 +1,108 @@ +' . esc_html__( 'Status', 'paid-memberships-pro' ) . ''; +} ); + +add_action( 'pmpro_orders_extra_cols_body', function ( $order ) { + ?> + + + status ) ); ?> + + + + + + + + is_renewal ) ) { + return $order->is_renewal; + } + + // Can't tell if this is a renewal without a user. + if ( empty( $order->user_id ) ) { + $order->is_renewal = false; + + return $order->is_renewal; + } + + if ( ! empty( $order->subscription_transaction_id ) ) { + // Logic for recurring orders. + $original_subscription_order = $order->get_original_subscription_order(); + if ( $order->id !== $original_subscription_order->id ) { + $order->is_renewal = true; + } else { + $order->is_renewal = false; + } + } else { + // Logic for non-recurring orders. + $sqlQuery = "SELECT `id` + FROM $wpdb->pmpro_membership_orders + WHERE `user_id` = '" . esc_sql( $order->user_id ) . "' + AND `id` <> '" . esc_sql( $order->id ) . "' + AND `gateway_environment` = '" . esc_sql( $order->gateway_environment ) . "' + AND `total` > 0 + AND `total` IS NOT NULL + AND status NOT IN('refunded', 'review', 'token', 'error') + AND timestamp < '" . esc_sql( date( 'Y-m-d H:i:s', $order->timestamp ) ) . "' + LIMIT 1"; + $older_order_id = $wpdb->get_var( $sqlQuery ); + + if ( ! empty( $older_order_id ) ) { + $order->is_renewal = true; + } else { + $order->is_renewal = false; + } + } + + return $order->is_renewal; +} + +add_action( 'admin_footer', function () { + ?> + +