Created
July 5, 2018 17:11
-
-
Save bernattorras/a984463cc968dba2074d8e4a40ec604b to your computer and use it in GitHub Desktop.
Function to save the end of the trial date (on a custom meta field) when changing a subsription status to 'cancel', 'pending cancelation', 'switched' or 'expired'
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 | |
/** | |
* Function to save the end of the trial date (on a custom meta field) when changing a subsription status to 'cancel', 'pending cancelation', 'switched' or 'expired' | |
**/ | |
add_action('woocommerce_subscription_pre_update_status', 'save_trial_end_meta', 10, 3); | |
function save_trial_end_meta($old_status, $new_status, $sub){ | |
if(in_array($new_status, array('cancelled', 'pending-cancel', 'switched', 'expired'))){ | |
$sub_id = $sub->get_id(); | |
$trial_end_date = $sub->get_date('trial_end'); | |
update_post_meta($sub_id, '_trial_end_date', $trial_end_date); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment