Skip Navigation

[Resolved] Redirect to post url submitted through form after crud commerce success

This thread is resolved. Here is a description of the problem and solution.

Problem:
Redirect to post url submitted through form after cred commerce success after payment

Solution:
You can use WooCommerce standard hook "woocommerce_thankyou" to redirect user to specific custom URL on successful payment.

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/redirect-to-post-url-submitted-through-form-after-crud-commerce-success/#post-1081327

Relevant Documentation:

This support ticket is created 6 years, 3 months ago. 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Tagged: 

This topic contains 6 replies, has 2 voices.

Last updated by udais 6 years, 3 months ago.

Assisted by: Minesh.

Author
Posts
#1078429

Tell us what you are trying to do? Redirecting back to post for which payment made after crud commerce success

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#1078436

Hello

i have custum post "allowed posts"

there are total 3 custom fields user-id, post-id and post-url. In post-url field i stores url of post(post type post) submitted through crud form. i get post-url field from

[cred_field field='post-url' value='' urlparam='post-url' class='form-control' output='bootstrap']

now i am trying to redirect to url in post-url field after success of crud commerce form.

I searched form but could not find solution.

Test url
hidden link
click on subscribe post for form

Thanks

#1079659

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - Toolset Forms Commerce Offers a hook cred_commerce_after_payment_completed , You should check if that helps:

add_action( 'cred_commerce_after_payment_completed', 'func_call_function_after_payment', 10, 1 );
function func_call_function_after_payment( $data ) {

$post_id =  $data['extra_data']['cred_post_id'];

$redirect_url = get_post_meta($post_id,'post-url',true);

header('location:'.$redirect_url);
exit;

    //some code here
}

More info:
https://toolset.com/documentation/programmer-reference/cred-commerce-api/#cred_commerce_after_payment_completed

If above does not work - you need to find a way to use some WooCommerce standard hook that runs after payment completed.

For example:
https://stackoverflow.com/questions/28218580/woocommerce-hook-for-after-payment-complete-actions

#1079666

hello

i added code but it still not redirect to post-url

you may check on hidden link

click subscribe

Thanks

#1079667

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - I need access details as well to test this issue.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#1081327

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've added following code to your current theme's functions.php file:

add_action('cred_save_data','func_set_custom_redirect_value',10,2);
function func_set_custom_redirect_value($post_id,$form_data) {
    if ($form_data['id']==110) {
        $url  = get_post_meta($post_id, 'wpcf-post-url', true);
        $_SESSION['payment_redirect_url'] = $url;
    }
}

add_action( 'woocommerce_thankyou', 'func_custom_redirect_after_payment');
function func_custom_redirect_after_payment( $order_id ){
      
	$url = $_SESSION['payment_redirect_url'];
 
    if ( $order->status != 'failed' ) {
		$_SESSION['payment_redirect_url'] = '';
        wp_redirect($url);
        exit;
    }
}

Now I can see the page is redirected to your desired post-url field after payment. Could you please confirm.

#1082716

Hello

it's working.

Thanks