I had a client with a request that i didn’t thought until I speak with him, he told me that clients on their website should be able to skip one month of subscription but keeping the subsscription as Active. That means we cannot change the status of the subscription.
Well in case you need it for any reason, or a cllient request like me. You can achieve this with the following code snippet in your theme/plugin:
<?php
add_filter( 'wcs_view_subscription_actions', 'add_skip_action', 10, 3 );
public function subscription_skip_handler(){
global $post;
// If the current user doesn't own the subscription, remove the query arg from the URL
if ( isset( $_GET['subscription_id'] ) ) {
$subscription = wcs_get_subscription( absint( $_GET['subscription_id'] ) );
// Visiting a switch link for someone elses subscription or if the switch link doesn't contain a valid nonce
if ( ! is_object( $subscription ) || empty( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( $_GET['_wpnonce'] ), $subscription->get_id() . '_skip' ) ) {
wp_redirect( remove_query_arg( array( 'skip' ) ) );
exit();
} else {
$date = date('Y-m-d H:i:s', $subscription->get_time( 'next_payment' ));
$new_date = date('Y-m-d H:i:s', strtotime($date. ' + 1 months') );
try {
$subscription->update_dates( ['next_payment' => $new_date], 'gmt' );
wp_cache_delete( $subscription->get_id(), 'posts' );
wc_add_notice( "Your next renewal payment is in: {$new_date}", 'success' );
wp_redirect( remove_query_arg( array( 'skip', 'subscription_id', '_wpnonce' ) ) );
} catch ( \Exception $e ) {
wcs_add_admin_notice( $e->getMessage(), 'error' );
}
}
}
}
What it dows is to add 1 month to the next subscription renewal and tada!. Happy Clients.
Hey people!!!!!
Good mood and good luck to everyone!!!!!
vaiia vaiia!!
creado por dios