Code-Snippets-Functions/Execute a function on a child site/WooCommerce/subscription-add-order-note-when-end-date-is-changed.txt

17 lines
686 B
Text

function add_subscription_note_when_end_date_change( $subscription_id ) {
// Get the end date of the subscription
$old_end_date = $subscription->get_date('end');
$old_end_date_ymd = explode(' ', $old_end_date);
$old_end_date_yr = $old_end_date_ymd[0];
$submited_end_date = sanitize_text_field(wp_unslash($_POST['end']));
if (null !== $submited_end_date && $old_end_date_yr !== $submited_end_date) {
$note = 'End date changed from ' . $old_end_date . ' to ' . $submited_end_date;
$subscription->add_order_note($note);
}
}
add_action('woocommerce_process_shop_order_meta', 'add_subscription_note_when_end_date_change', 0);