Jump to content
Daniel

Removing cancelled/terminated services from "Related Service" on ticket form

Recommended Posts

Hey guys,

Is anyone aware of a way to remove the cancelled/terminated services from the related services dropdown menu of step 2 of the submit ticket page?

Some of our clients have a lot of terminated or cancelled services that they don't want listed and I can't see a way to remove those.

 

Thanks

Share this post


Link to post
Share on other sites

Hi Daniel,

19 hours ago, Daniel said:

Is anyone aware of a way to remove the cancelled/terminated services from the related services dropdown menu of step 2 of the submit ticket page?

the usual two ways would be to either edit the supportticketsibmit-steptwo.tpl template, or use an action hook...

to edit the template, you could just put an if statement in the foreach loop that generates the relatedservices dropdown content, e.g change...

{foreach from=$relatedservices item=relatedservice}
	<option value="{$relatedservice.id}">{$relatedservice.name} ({$relatedservice.status})</option>
{/foreach}

to...

{foreach from=$relatedservices item=relatedservice}
	{if !in_array($relatedservice.status,array('Cancelled','Terminated'))}
		<option value="{$relatedservice.id}">{$relatedservice.name} ({$relatedservice.status})</option>
	{/if}
{/foreach}

if you want to avoid editing the template, then you could use a hook to modify the array and remove the cancelled/terminated services...

<?php

# Filter & Sort Ticket Related Services Hook
# Written by brian!

function filter_related_services_hook($vars){
	
	if ($vars['templatefile']=='supportticketsubmit-steptwo'){
		$relatedservices = $vars['relatedservices'];
		$cancelled = array('Cancelled','Terminated');
		foreach($relatedservices as $key => $service) {
			if (in_array($service['status'],$cancelled)) {
				unset($relatedservices[$key]);
			}
		}
		array_multisort(array_column($relatedservices, 'status'), SORT_ASC, array_column($relatedservices, 'name'), SORT_ASC, $relatedservices);
		return array("relatedservices" => $relatedservices);
	}
}
add_hook("ClientAreaPageSubmitTicket", 1, "filter_related_services_hook");

i've also added sort functionality to the hook that will sort the array by status (e.g Active services will be first), and then sorted by name... if you don't want/need this, then just remove the array_multisort line.

that sorting idea is from another step2 hook that I posted in the thread below - no point letting it go to waste if you want to use the feature! thanks.png

Share this post


Link to post
Share on other sites

Thanks so much Brian!

 

That hook is exactly what I was looking for and works perfectly.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

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