Advertisement
vapvarun

Remove cancel button ( When last payment was less then 3 months ago )

Feb 21st, 2022
911
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. /**
  2.  * Remove cancel button ( When last payment was less then 3 months ago )
  3.  *
  4.  * @param array $actions, action array.
  5.  * @param int $subscription_id, the id of the current subscription.
  6.  * @return array $actions, the altered action array.
  7.  */
  8. function remove_cancel_button( $actions, $subscription_id ) {
  9.  
  10.   // Gets the subscription object on subscription id
  11.   $subscription = new WC_Subscription( $subscription_id );
  12.  
  13.   // Get last payment date from subscription object, uses the sites timezone setting
  14.   $last_payment_date = $subscription->get_date( 'last_payment', 'site' );
  15.   $last_payment_date = new DateTime( $last_payment_date );
  16.  
  17.   // The current date/time, uses the sites timezone setting
  18.   $today = new DateTime( current_time('mysql') );
  19.  
  20.   // Get the difference in date
  21.   $interval = $today->diff( $last_payment_date );
  22.  
  23.   // Check if interval is less then 3 months
  24.   if( $interval->m < 3 ){
  25.     unset( $actions['cancel'] );
  26.   }
  27.  
  28.   // Return the actions
  29.   return $actions;
  30. }
  31. add_filter( 'wcs_view_subscription_actions', 'remove_cancel_button', 100, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement