Skip to content

Instantly share code, notes, and snippets.

@kimcoleman
Created February 23, 2018 00:42
Show Gist options
  • Save kimcoleman/8e09a903b96eb455cd8346953e2ccc7a to your computer and use it in GitHub Desktop.
Save kimcoleman/8e09a903b96eb455cd8346953e2ccc7a to your computer and use it in GitHub Desktop.
Count the number of times a subscription ID has processed in total with each added order.
<?php
/**
* Count the number of times a subscription ID has processed in total with each added order.
*/
function count_transation_ids( $MemberOrder ) {
global $wpdb;
$orders = $wpdb->get_results("SELECT o.*, UNIX_TIMESTAMP(o.timestamp) as timestamp, l.name as membership_level_name FROM $wpdb->pmpro_membership_orders o LEFT JOIN $wpdb->pmpro_membership_levels l ON o.membership_id = l.id WHERE o.user_id = '$MemberOrder->user_id' AND o.subscription_transaction_id = '$MemberOrder->subscription_transaction_id' ORDER BY timestamp DESC");
$orders_count = count( $orders );
}
add_action( 'pmpro_added_order', 'count_transation_ids' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment