Pro Sites - Division by zero in Checkout.php

If you only have one level in Pro Sites and disable the 1 month and 3 month prices, there is a division by zero in Checkout.php.

Method: render_pricing_columns

$show_first_column  = $show_periods && 'option2' != $psts->get_setting( 'pricing_table_period_position', 'option1' );
$total_columns      = $show_first_column ? count( $columns ) : count( $columns ) - 1;
$total_width        = 100.0;
$total_width        -= 6.0; // account for extra space around featured plan
// This line will divide by zero as $total_columns will be 0
$column_width       = $total_width / $total_columns;

Adjusting this to the following will correct this issue

$show_first_column  = $show_periods && 'option2' != $psts->get_setting( 'pricing_table_period_position', 'option1' );
$total_columns      = $show_first_column ? count( $columns ) : count( $columns ) - 1;
// Make sure we're not setting $total_columns to 0
$total_columns		= $total_columns == 0 ? 1 : $total_columns;
$total_width        = 100.0;
$total_width        -= 6.0; // account for extra space around featured plan
$column_width       = $total_width / $total_columns;

If it is set to 0 and errors are turned off, it throws out the pricing table as you can see in the screenshot. This was how I found the error to start with.

  • Predrag Dubajic

    Hey @Daryll,

    Hope you're doing well today :slight_smile:

    Thanks for all the details and debugging this, however I was unable to replicate this issue on my end.

    I believe it's because of different setting on our sites so if you wouldn't mind granting support access I would like to test this and copy the setup on my site so I could provide developer with as much details as possible.

    To enable support access you can follow this guide here:
    https://premium.wpmudev.org/manuals/wpmu-dev-dashboard-enabling-staff-login/

    Best regards,
    Predrag

  • Digital Web Media

    Hi Predrag,

    Unfortunately it's a local site so I won't be able to grant access to it.

    If it helps at all this is how pro sites is set up:

    - Add a single Pro Site Level and un-tick the 1 Month Price and 3 Month Price boxes on /wp-admin/network/admin.php?page=psts-levels
    - Go to /pro-site/?bid=YOUR-BLOG-ID
    - See issue

    If it helps at all, here is my psts_settings and psts_levels meta_values from wp_sitemeta on a site I duplicated the issues on.

    Levels:
    a:1:{i:1;a:5:{s:4:"name";s:16:"Standard Package";s:7:"price_1";d:0;s:7:"price_3";d:0;s:8:"price_12";d:195;s:10:"is_visible";i:1;}}

    Settings:

    a:95:{s:12:"base_country";s:2:"US";s:8:"currency";s:3:"USD";s:20:"curr_symbol_position";i:1;s:12:"curr_decimal";i:1;s:7:"rebrand";s:8:"Pro Site";s:10:"lbl_signup";s:11:"Pro Upgrade";s:8:"lbl_curr";s:12:"Your Account";s:16:"gateways_enabled";a:0:{}s:15:"modules_enabled";a:0:{}s:15:"enabled_periods";a:1:{i:0;i:12;}s:14:"hide_adminmenu";i:0;s:13:"hide_adminbar";i:0;s:19:"hide_adminbar_super";i:0;s:11:"show_signup";i:1;s:11:"free_signup";i:0;s:15:"multiple_signup";i:1;s:9:"free_name";s:4:"Free";s:8:"free_msg";s:55:"No thank you, I will continue with a basic site for now";s:11:"trial_level";i:1;s:10:"trial_days";b:0;s:13:"trial_message";s:103:"You have DAYS days left in your LEVEL free trial. Checkout now to prevent losing LEVEL features &raquo;";s:14:"cancel_message";s:345:"Your DAYS day trial begins once you click "Subscribe" below. We perform a $1 pre-authorization to ensure your credit card is valid, but we won't actually charge your card until the end of your trial. If you don't cancel by day DAYS, your card will be charged for the subscription amount shown above. You can cancel your subscription at any time.";s:23:"recurring_subscriptions";i:1;s:12:"ga_ecommerce";s:4:"none";s:14:"signup_message";s:43:"Would you like to upgrade this site to Pro?";s:15:"feature_message";s:47:"Upgrade to LEVEL to access this feature &raquo;";s:14:"active_message";s:203:"Your Pro Site privileges will expire on: DATE<br />Unless you have canceled your subscription or your site was upgraded via the Bulk Upgrades tool, your Pro Site privileges will automatically be renewed.";s:15:"success_subject";s:41:"Thank you for becoming a Pro Site member!";s:11:"success_msg";s:477:"Thank you for becoming a Pro Site member!
    
    We have received your first subscription payment and you can now access all LEVEL features!
    
    Subscription payments should show on your credit card or bank statement as "THIS COMPANY". If you ever need to view, modify, upgrade, or cancel your Pro Site subscription you can do so here:
    http://mysite.com/pro-site/
    
    If you ever have any billing questions please contact us:
    http://mysite.com/contact/
    
    Thanks again for joining!";s:16:"canceled_subject";s:44:"Your Pro Site subscription has been canceled";s:12:"canceled_msg";s:284:"Your Pro Site subscription has been canceled.
    
    You should continue to have access until ENDDATE.
    
    We are very sorry to see you go, but we are looking forward to you subscribing to our services again.
    
    You can resubscribe at any time here:
    http://mysite.com/pro-site/
    
    Thanks!";s:15:"receipt_subject";s:29:"Your Pro Site payment receipt";s:11:"receipt_msg";s:420:"Your Pro Site subscription payment was successful!
    
    PAYMENTINFO
    
    Subscription payments should show on your credit card or bank statement as "YOUR COMPANY". If you ever need to view, modify, upgrade, or cancel your Pro Site subscription you can do so here:
    http://mysite.com/pro-site/
    
    If you ever have any billing questions please contact us:
    http://mysite.com/contact/
    
    Thanks again for being a valued member!";s:15:"expired_subject";s:32:"Your Pro Site status has expired";s:11:"expired_msg";s:281:"Unfortunately the Pro status for your site SITENAME (SITEURL) has lapsed.
    
    You can renew your Pro Site status here:
    CHECKOUTURL
    
    If you're having billing problems please contact us for help:
    http://mysite.com/contact/
    
    Looking forward to having you back as a valued member!";s:14:"failed_subject";s:41:"Your Pro Site subscription payment failed";s:10:"failed_msg";s:366:"It seems like there is a problem with your latest Pro Site subscription payment, sorry about that.
    
    Please update your payment information or change your payment method as soon as possible to avoid a lapse in Pro Site features. If you're still having billing problems please contact us for help:
    http://mysite.com/contact/
    
    Many thanks again for being a member!";s:17:"extension_subject";s:45:"You have been given free Pro Site membership.";s:13:"extension_msg";s:328:"We have given you Pro Site access. You will now be able to enjoy all the benefits of being a Pro Site member.
    
    These benefits will be available to you until: ENDDATE.
    
    After this date your site will revert back to a standard site.
    
    You can subscribe at any time from the link below:
    http://mysite.com/pro-site/
    
    Thanks!";s:9:"pypl_site";s:2:"US";s:13:"pypl_currency";s:3:"USD";s:11:"pypl_status";s:4:"test";s:15:"pypl_enable_pro";i:0;s:10:"stripe_ssl";i:0;s:7:"mp_name";s:14:"Manual Payment";s:12:"mp_show_form";i:0;s:8:"mp_email";s:19:"daryll@wearedwm.com";s:7:"pt_name";s:14:"Premium Themes";s:7:"pt_text";s:55:"Upgrade to LEVEL to activate this premium theme &raquo;";s:8:"ps_level";i:1;s:8:"ps_email";s:19:"daryll@wearedwm.com";s:7:"ps_name";s:15:"Premium Support";s:10:"ps_message";s:93:"You can send us a priority direct email support request here if you need help with your site.";s:9:"ps_notice";s:58:"To enable premium support, please upgrade to LEVEL &raquo;";s:16:"publishing_level";i:1;s:24:"publishing_message_posts";s:59:"To enable publishing posts, please upgrade to LEVEL &raquo;";s:24:"publishing_message_pages";s:59:"To enable publishing pages, please upgrade to LEVEL &raquo;";s:13:"quota_message";s:44:"For SPACE of upload space, upgrade to LEVEL!";s:17:"quota_out_message";s:86:"You are out of upload space! Please upgrade to LEVEL to enable SPACE of storage space.";s:12:"xmlrpc_level";i:1;s:14:"xmlrpc_message";s:67:"To enable XML-RPC remote publishing please upgrade to LEVEL &raquo;";s:9:"bp_notice";s:47:"Upgrade to LEVEL to access this feature &raquo;";s:7:"pp_name";s:15:"Premium Plugins";s:8:"ads_name";s:11:"Disable Ads";s:9:"ads_level";i:1;s:16:"ads_enable_blogs";i:0;s:9:"ads_count";i:3;s:15:"ads_before_page";i:0;s:14:"ads_after_page";i:0;s:15:"ads_before_post";i:0;s:14:"ads_after_post";i:0;s:10:"ads_themes";i:0;s:8:"bu_email";b:0;s:9:"bu_status";s:4:"test";s:15:"bu_payment_type";s:9:"recurring";s:8:"bu_level";i:1;s:12:"bu_credits_1";i:10;s:13:"bu_option_msg";s:59:"Upgrade CREDITS sites to LEVEL for one year for only PRICE:";s:15:"bu_checkout_msg";s:278:"You can upgrade multiple sites at a lower cost by purchasing Pro Site credits below. After purchasing your credits just come back to this page, search for your sites via the tool at the bottom of the page, and upgrade them to Pro Site status. Each site is upgraded for one year.";s:14:"bu_payment_msg";s:177:"Depending on your payment method it may take just a few minutes (Credit Card or PayPal funds) or it may take several days (eCheck) for your Pro Site credits to become available.";s:7:"bu_name";s:13:"Bulk Upgrades";s:11:"bu_link_msg";s:68:"Purchase credits to upgrade multiple sites for one discounted price!";s:17:"ptb_front_disable";i:1;s:13:"ptb_front_msg";s:85:"This site is temporarily disabled until payment is received. Please check back later.";s:16:"ptb_checkout_msg";s:33:"You must pay to enable your site.";s:8:"pq_level";i:1;s:9:"pq_quotas";a:2:{s:4:"post";a:1:{s:5:"quota";s:9:"unlimited";}s:4:"page";a:1:{s:5:"quota";s:9:"unlimited";}}s:8:"uh_level";i:1;s:10:"uh_message";s:61:"To enable the embedding html, please upgrade to LEVEL &raquo;";s:10:"co_pricing";s:8:"disabled";s:19:"plans_table_enabled";s:7:"enabled";i:0;b:0;s:7:"version";s:7:"3.5.0.4";s:13:"checkout_page";i:585;s:12:"checkout_url";s:28:"http://test.dev/pro-site/";}
  • Adam Czajczyk

    Hey Daryll,

    I hope you're well today and thank you for you question and in-depth analysis.

    I've confirmed this on my test setup: if there's only one level and it has only one price active (free level doesn't count) there's a "division by zero" error.

    This is obviously a bug and I've reported it to a developer, so hopefully it will be fixed as soon as possible.

    As for now. A "quick fix" would be to edit the "checkout.php" file (as you've already examined it) and replace this line (it's the last line of the first code in your original question):

    $column_width       = $total_width / $total_columns;

    with this one

    if ($total_columns > 0 ) {
    				$column_width       = $total_width / $total_columns;
    			}
    			else {
    				$column_width	= $total_width;
    			}

    I've tested it and it's working fine.

    Please keep in mind though that this change is worth noting down as it will be lost upon the plugin update and may have been reapplied. I hope though that by this time it should be fixed :slight_smile:

    Let me know please if it helped!

    Cheers,
    Adam

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.