Last active
July 30, 2024 22:50
-
-
Save cartpauj/9308f60e7fd51939e6809b2ce3a685f4 to your computer and use it in GitHub Desktop.
Stop MemberPress from setting transaction expires dates to 23:59:59 UTC+0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// This will set the expires at hour, minute, second to the same hour, minute, second when the user joined. | |
function update_txn_expires_at($txn, $old_txn = false) { | |
global $wpdb; | |
if(!isset($txn->id) || (int)$txn->id <=0 || $txn->expires_at == '0000-00-00 00:00:00') { return; } | |
$expires_at_ts = strtotime($txn->expires_at); | |
$created_at_ts = strtotime($txn->created_at); | |
$new_expires_at_ts = mktime( | |
gmdate("H", $created_at_ts), //hour | |
gmdate("i", $created_at_ts), //minute | |
gmdate("s", $created_at_ts), //second | |
gmdate("n", $expires_at_ts), //month | |
gmdate("j", $expires_at_ts), //day | |
gmdate("Y", $expires_at_ts) //year | |
); | |
$expires_at = gmdate('Y-m-d H:i:s', $new_expires_at_ts); | |
$wpdb->query("UPDATE {$wpdb->prefix}mepr_transactions SET expires_at = '{$expires_at}' WHERE id = {$txn->id}"); | |
} | |
add_action('mepr-txn-store', 'update_txn_expires_at', 999999, 2); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment