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/73806900/hide-woocommerce-subscriptions-cancel-button-2-days-before-subscription-renewal
22 lines
766 B
Text
22 lines
766 B
Text
function wc_remove_cancel_button( $actions, $subscription_id ) {
|
|
|
|
// Gets the subscription object on subscription id
|
|
$subscription = new WC_Subscription( $subscription_id );
|
|
|
|
$next_payment_date = $subscription->get_date( 'next_payment', 'site' );
|
|
|
|
$nt = strtotime($next_payment_date);
|
|
$local_time = current_datetime();
|
|
$ct = $local_time->getTimestamp() + $local_time->getOffset();
|
|
|
|
// Get the difference in date
|
|
$diff = $ct - $nt;
|
|
$final = abs(round($diff / 86400));
|
|
// Change the number (days) according to your choice
|
|
if ($final <= "2") {
|
|
unset( $actions['cancel'] );
|
|
}
|
|
|
|
// Return the actions
|
|
return $actions;
|
|
} add_filter( 'wcs_view_subscription_actions', 'wc_remove_cancel_button', 100, 2);
|