Skip Navigation

[Gelöst] Different thank you pages in CRED depending on the URL parameter

This support ticket is created vor 8 Jahre. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 -
- - - - - - -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 6 Antworten, has 2 Stimmen.

Last updated by willem-siebeS vor 8 Jahre.

Assigned support staff: Waqas.

Author
Artikel
#262783

Hi,

I have two product pages and from there I link people to a page with CRED form to write a review, which is creating an URL with parent_page_id parameter, these two URLs:

<em><u>hidden link</u></em>
<em><u>hidden link</u></em>

Now, CRED offers to send people to a 'thank-you' page. That this is the same page all the time is not bothering me at all, but because the fact it's always the same URL I can not use this page for my conversion tracking / improvement. For that I need the thank you page for id=17 and for id=35 also to have a different URL. Is it possible to add these parameters to the thank you page URL?

Even better would be if I can tell CRED when a review is written for id=17, go to this thank you page. When a review is written for id=35, go to this thank you page. In that way, we can also present customers with a new offer/coupon on that page related to the product they were reviewing.

Kind regards,

Willem-Siebe Spoelstra

#263124

Waqas
Supporter

Languages: Englisch (English )

Timezone: Asia/Karachi (GMT+05:00)

Yes you can achieve this by using CRED API's cred_success_redirect() filter.

add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
	if ($form_data['id']==17) {
		return '<em><u>hidden link</u></em>';
	}
	
	if ($form_data['id']==35) {
		return '<em><u>hidden link</u></em>';
	}
	
	// You can also replace above if blocks with a switch() block.
 
	return $url;
}

Please find more information at https://toolset.com/documentation/user-guides/cred-api/#csr

#263481

Hi,

I think you misunderstood. The '17' and '35' are not the ID's from the CRED form. There is only ONE cred form, with ID '6'. The '17' is added as a URL parameter, so that the CRED form knows this person is writing a review for the parent page with ID '17'. Same for '35'.

So in Types the CPT 'Review' has 'Page' as parent. From this pages with ID 17 and 35 I link to the CRED form, that's why the URL parameter _parent_page_id is being added.

Now I need that when somebody filles in a review for parent page with ID 17 is being redirected to another URL then the person who is filling in a review for parent page with ID 35.

I would like to know two scenario's:

1) Redirect them to completely different pages, the one we were working on:

This is what I tried, changed 'id' to '_wpcf_belongs_page_id', but this is not working:

add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
    if ($form_data['_wpcf_belongs_page_id']==17) {
        return '<em><u>hidden link</u></em>';
    }
     
    if ($form_data['_wpcf_belongs_page_id']==35) {
        return '<em><u>hidden link</u></em>';
    }
     
    // You can also replace above if blocks with a switch() block.
  
    return $url;
}

2) Just like the CRED form (the is only ONE cred form), I would like to have on 'thank you page', but with again (just like the cred form) a URL parameter added. So in the setting of CRED form with ID 6 I redirect people to the page 'thank-you-for-review'.

Now, when somebody fills in a review on:

<em><u>hidden link</u></em>

I want the redirect filter to add the '?parent_page_id=17' part also to the thank you page, like this:

<em><u>hidden link</u></em>

Same for:

<em><u>hidden link</u></em>

Needs to be redirected to:

<em><u>hidden link</u></em>

Thanks.

Kind regards,

Willem

#263500

Waqas
Supporter

Languages: Englisch (English )

Timezone: Asia/Karachi (GMT+05:00)

Actually the main hook I mentioned in my previous reply, should work for this purpose. However, you may need to alter it around the parameter you want to check. Since you couldn't find 'parent_page_id' in $form_data, you may need to grab it from $_GET, store it in a generic hidden field and grab it in the hook when form is submitted.

You can create following custom short code to grab a URL parameter from $_GET:

add_shortcode('get-url-param', 'get_url_param');
function get_url_param ($atts) {
    $var = $atts["var"];
	
	return $_GET[$var];
}

Then add following generic hidden field in your CRED form:

[cred_generic_field field="parent_page_id" type="hidden" class="" urlparam="parent_page_id"]
{
"required":0,
"validate_format":0,
"persist":0,
"default":"[get-url-param var='parent_page_id']"
}
[/cred_generic_field]

When form is submitted, use following code (updated previously mentioned hook code to reflect the changes):

add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
	$parent_page_id = $_POST["parent_page_id"];
	$thankyouUrl = "<em><u>hidden link</u></em>";

	if(!empty($parent_page_id)) {
		if ($parent_page_id == 17) {
			$thankyouUrl .= '/thank-you-for-your-review/';
		}
		 
		if ($parent_page_id == 35) {
			$thankyouUrl .= '/thank-you-for-your-review/';
		}
		
		// Above 2 blocks demonstrate if you want 2 different pages based on parent_page_id
		// You can omit these blocks if you want the single page for both, but with parent_page_id added to the URL,
		// the following line does that.
		
		$thankyouUrl .= '?parent_page_id='.$parent_page_id;
		 
		// You can also replace above if blocks with a switch() block.
		
		return $thankyouUrl;
	}
	
    return $url;
}

Please pay attention to the comments given in the code above. This code summarizes 2 use cases, you can alter according to yours.

#263521

Hi,

Although I would never be able to make this code myself, I do understand what you are doing and.. it works :-).

In my case I go with the second scenario to have one thank you page, but add a parameter to the URL. Although your code works for that, I found it to be unneccesary to manually enter the thank you URL again, while I already have set this up in the cred form user interface.

So for the second scenario, based on your code ofcourse, I created this one:

add_filter('cred_success_redirect', 'wsis_add_parent_page_id_to_redirect_page',10,3);
function wsis_add_parent_page_id_to_redirect_page($url, $post_id, $form_data)
{
    $parent_page_id = $_POST["parent_page_id"];
 
    if(!empty($parent_page_id)) {
                  
        return $url .= '?parent_page_id='.$parent_page_id;
         
    }
     
    return $url;
}

It seems to work, so if this code had no downside in your opinion as well, I will mark this topic as solved after your reply.

Thanks for your great help with offering solutions for both scenario's!

Kind regards,

Willem

#263523

Waqas
Supporter

Languages: Englisch (English )

Timezone: Asia/Karachi (GMT+05:00)

You did it well 🙂 That's the way it should work.

#263526

Great! Solved!