mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-29 11:32:21 +08:00
https://stackoverflow.com/questions/75539087/woocommerce-subscription-add-order-note-when-end-date-is-changed
17 lines
686 B
Text
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);
|