*

kenoffice

  • **
  • 21 posts
[Suggestion] time of membership in months/years instead of days
« on: October 19, 2023, 03:01:52 AM »
I write this post only in case someone will want to sell subscriptions for 1-2-3 years and showing to customers in days might not look so nice.

I didn't liked the way the user have the options to buy membership, I mean the price table.
There is mentioned membership period in days, which might be fine for websites who want to sell membership/subscription for 30/60/90/120/etc days.
But in my case I want to have 6 months / 1 year / 2 years / 3 years. If I leave the original code will look like 183 days / 366 days / 732 days / 1098 days which is ugly (the user I bet will prefere 3 years instead of 1098 days :)


So I altered group.php and user.js to look like images bellow. If someone want the same, can try:
1. in group.php
ORIGINAL line:
<div class="osp-cost">/ <?php _e('user', 'osclass_pay'); ?> / <span><?php echo $g['i_days'] . '</span> ' . __('days', 'osclass_pay'); ?></div>
MODIFIED:
<div class="osp-cost"><span><?php
            if ($g['i_days'] < 365) {
               echo round($g['i_days'] / 30) . '</span> <i>' . substr(__('%d months', 'osclass_pay'), 2) . '</i>';
            }
            else {
               echo round($g['i_days'] / 365) . '</span> <i>' . substr(__('%d years', 'osclass_pay'), 2) . '</i>';
            }          
?></div>
Note: due the fact that in .po file for language translation there is not "months" and "years" individually, I taken from there the "%d months" and "%d years" as already being translated and stripped with php function substr() the first 2 characters, I mean the %d. Other way is to add manually these 2 words in original en_US module .po file and translate it.

2. In user.js
The line which replace the days numbers when user click on drop-down list, were:
//$('.osp-group[data-group="' + group + '"]').find('.osp-cost > span').text(days);
(as can be seen, I commented it out)
Instead, I replaced with:
   var monthsNumber = Math.round(days / 30);
   var yearsNumber = Math.round(days / 365);
   var monthsText = 'luni';
   var yearsText = 'ani';
   if (days < 365) {
      $('.osp-group[data-group="' + group + '"]').find('.osp-cost > span').text(monthsNumber);
      //this one bellow will change the default text/name (days) to months
      $('.osp-group[data-group="' + group + '"]').find('.osp-cost > i').text(monthsText);
   }
   else {
      $('.osp-group[data-group="' + group + '"]').find('.osp-cost > span').text(yearsNumber);
      //this one bellow will change the default text/name (days) to YEARS
      $('.osp-group[data-group="' + group + '"]').find('.osp-cost > i').text(yearsText);
   }
The only problem is that name / text of months and years I defined myself (luni, ani) into 2 variables, monthsText and yearsText because I couldn't find from where to instruct javascript to read them. But if your webiste is only 1 language then might be fine.

Of course, any update of plugin will overwrite your changes so will need to do them again :)
There is no perfect classifieds script. I dream to make it.

*

bobyrou

  • ****
  • 107 posts
Re: [Suggestion] time of membership in months/years instead of days
« Reply #1 on: October 22, 2023, 10:12:33 PM »
Thank you! Same I use yearly subscriptions and showing in days instead of years is very confusing for customers, to me shows these options: 365 days, 730 days, 1095 days, 1460 days and 1825 days. Very bad for customers

*

MB Themes

Re: [Suggestion] time of membership in months/years instead of days
« Reply #2 on: October 27, 2023, 07:24:50 AM »
Will be implemented in next update
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots