Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Remove cancel button ( When last payment was less then 3 months ago )
- *
- * @param array $actions, action array.
- * @param int $subscription_id, the id of the current subscription.
- * @return array $actions, the altered action array.
- */
- function remove_cancel_button( $actions, $subscription_id ) {
- // Gets the subscription object on subscription id
- $subscription = new WC_Subscription( $subscription_id );
- // Get last payment date from subscription object, uses the sites timezone setting
- $last_payment_date = $subscription->get_date( 'last_payment', 'site' );
- $last_payment_date = new DateTime( $last_payment_date );
- // The current date/time, uses the sites timezone setting
- $today = new DateTime( current_time('mysql') );
- // Get the difference in date
- $interval = $today->diff( $last_payment_date );
- // Check if interval is less then 3 months
- if( $interval->m < 3 ){
- unset( $actions['cancel'] );
- }
- // Return the actions
- return $actions;
- }
- add_filter( 'wcs_view_subscription_actions', 'remove_cancel_button', 100, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement