kreamweb
2/23/2017 - 9:59 AM

add a message to customer with the date of next payment

add a message to customer with the date of next payment

<?php
if ( defined( 'YITH_YWSBS_PREMIUM' ) ) {
	add_action( 'woocommerce_init', 'ywsbs_add_notice' );
	function ywsbs_add_notice(){
		if( is_user_logged_in()){
			$current_user =  wp_get_current_user();
			$sbs = YITH_WC_Subscription()->get_user_subscriptions( $current_user->get('ID'), $status = 'active' );

			foreach ( $sbs as $sub_id ){
				$subscription = ywsbs_get_subscription( $sub_id );
				if( ! empty( $subscription->payment_due_date ) ){
					//expired_date - payment_due_date
					wc_add_notice( sprintf( 'Your subscription will expire on %s.', date_i18n( wc_date_format(), $subscription->payment_due_date ) ), 'notice' );
				}elseif ( ! empty( $subscription->expired_date)  ){
					wc_add_notice( sprintf( 'Your subscription will expire on %s.', date_i18n( wc_date_format(), $subscription->expired_date ) ), 'notice' );
				}
			}
		}
	}
}