-
Notifications
You must be signed in to change notification settings - Fork 22
Show "Renewal" for orders which are actually renewals #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,108 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <?php | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Replace "Renewal" label logics showing "Renewal" for orders which are actually renewals. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Orders status column in admin shows a not clear "Renewal" label for returning customers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * (orders from a customer who already had an order before - might be a renewal or not). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Some people just want to see "Renewal" for orders which are actually renewals. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * title: Show "Renewal" for orders which are actually renewals. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * layout: snippet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * collection: orders | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * category: status, renewal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * You can add this recipe to your site by creating a custom plugin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * or using the Code Snippets plugin available for free in the WordPress repository. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Read this companion article for step-by-step directions on either method. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| add_action( 'pmpro_orders_extra_cols_header', function ( $order_id ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo '<th class="column-status-v2">' . esc_html__( 'Status', 'paid-memberships-pro' ) . '</th>'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| add_action( 'pmpro_orders_extra_cols_body', function ( $order ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ?> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <td class="column-status-v2" data-colname="<?php esc_attr_e( 'Status', 'paid-memberships-pro' ); ?>"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <span class="pmpro_order-status pmpro_order-status-<?php esc_attr_e( $order->status ); ?>"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <?php esc_html_e( ucwords( $order->status ) ); ?> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+28
to
+29
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <span class="pmpro_order-status pmpro_order-status-<?php esc_attr_e( $order->status ); ?>"> | |
| <?php esc_html_e( ucwords( $order->status ) ); ?> | |
| <span class="pmpro_order-status pmpro_order-status-<?php echo esc_attr( $order->status ); ?>"> | |
| <?php echo esc_html( ucwords( $order->status ) ); ?> |
Copilot
AI
Mar 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The “Renewal” link always searches by $order->subscription_transaction_id. For non-recurring renewals (where this field is empty) this renders a link with an empty s parameter, which won’t show the intended related orders. Consider only linking when a subscription transaction ID exists, or using a different query target for non-recurring renewals.
| <?php if ( pmpro_order_is_renewal_in_subscription( $order ) ) { ?> | |
| <a href="<?php echo esc_url( add_query_arg( array( | |
| 'page' => 'pmpro-orders', | |
| 's' => $order->subscription_transaction_id | |
| ), admin_url( 'admin.php' ) ) ); ?>" | |
| title="<?php esc_attr_e( 'View all orders for this subscription', 'paid-memberships-pro' ); ?>" | |
| class="pmpro_order-renewal"><?php esc_html_e( 'Renewal', 'paid-memberships-pro' ); ?></a> | |
| <?php } ?> | |
| <?php if ( pmpro_order_is_renewal_in_subscription( $order ) ) : ?> | |
| <?php if ( ! empty( $order->subscription_transaction_id ) ) : ?> | |
| <a href="<?php echo esc_url( add_query_arg( array( | |
| 'page' => 'pmpro-orders', | |
| 's' => $order->subscription_transaction_id, | |
| ), admin_url( 'admin.php' ) ) ); ?>" | |
| title="<?php esc_attr_e( 'View all orders for this subscription', 'paid-memberships-pro' ); ?>" | |
| class="pmpro_order-renewal"><?php esc_html_e( 'Renewal', 'paid-memberships-pro' ); ?></a> | |
| <?php else : ?> | |
| <span class="pmpro_order-renewal"><?php esc_html_e( 'Renewal', 'paid-memberships-pro' ); ?></span> | |
| <?php endif; ?> | |
| <?php endif; ?> |
Copilot
AI
Mar 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The non-recurring renewal check builds SQL via string concatenation. Even with esc_sql(), this is error-prone and bypasses $wpdb->prepare() protections/type handling. Please switch to $wpdb->prepare() with placeholders and cast numeric fields (e.g., user_id/id) to integers.
| $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"; | |
| $sqlQuery = $wpdb->prepare( | |
| "SELECT `id` | |
| FROM $wpdb->pmpro_membership_orders | |
| WHERE `user_id` = %d | |
| AND `id` <> %d | |
| AND `gateway_environment` = %s | |
| AND `total` > 0 | |
| AND `total` IS NOT NULL | |
| AND status NOT IN('refunded', 'review', 'token', 'error') | |
| AND timestamp < %s | |
| LIMIT 1", | |
| (int) $order->user_id, | |
| (int) $order->id, | |
| $order->gateway_environment, | |
| date( 'Y-m-d H:i:s', (int) $order->timestamp ) | |
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docblock wording is grammatically incorrect/unclear (e.g., “label logics”, “a not clear”). Please rephrase for clarity since these snippet headers are user-facing in the recipe library.