Jump to content

Can you have a product addon only be purchased at checkout not from the account manager?


Recommended Posts

On 10/07/2018 at 20:07, Web Host Pro said:

I have an addon that only will work with new accounts. I was hoping to not have it available for existing accounts already activated. Basically only have it available during checkout.

there won't be a way from the settings, so you'll be left with a one line template edit (basically {if $addon.id neq 'x'} inside the first foreach loop - add closing if) or as a hook...

<?php

/**
* Prevent ordering of specific product addons for existing products
* @author brian!
*/

use Illuminate\Database\Capsule\Manager as Capsule;
 
function cart_prevent_ordering_of_product_addons($vars)
{
	$blocked = [1,9,10];
	if ($vars['templatefile']=='addons'){
		$addons = $vars['addons'];
		foreach ($addons as $key => $addon) {
			if (in_array($addon['id'],$blocked)) {
				unset($addons[$key]);
			}
		}
		$addons = array_values($addons);
		return array("addons" => $addons);
	}
}
add_hook("ClientAreaPageCart", 1, "cart_prevent_ordering_of_product_addons");

in the above hook example, $blocked is an array of addon IDs that you don't want to let clients add to existing products... addons purchased through the cart via configureproduct won't be affected by this hook.

Link to comment
Share on other sites

  • 2 weeks later...
2 hours ago, Web Host Pro said:

O.K. awesome, I see it's removed on the cart.php?gid=addons page. Also on the product page there is this section in the image called addons and extras. Any chance I can have it removed from there as well?

I can't expand the hook to remove it because that output is being generated by the cPanel overview template before the hook would run, e.g I can write a hook to create/manipulate the appropriate arrays, but it runs only after the existing array has already been used for the output - horse, meet the stable door closing behind you. 🐴

therefore, you will have to edit /modules/servers/cpanel/templates/overview.tpl and change...

{foreach $availableAddonProducts as $addonId => $addonName}
	<option value="{$addonId}">{$addonName}</option>
{/foreach}

to...

{assign var=blocked value=[1,2,10,20]}
{foreach $availableAddonProducts as $addonId => $addonName}
	{if !in_array($addonId,$blocked)}
		<option value="{$addonId}">{$addonName}</option>
	{/if}
{/foreach}

you'll either have to remember to edit this after after each WHMCS update (I suspect the auto-updater will overwrite it), or you can move it to your active template folder and avoid it being overwritten by an update (but you would then have to manually compare the two template files for any other changes in the update).

https://docs.whmcs.com/Working_with_Module_Templates

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated