Home Forums Add-ons User Submitted Changing redirect url after post save


Changing redirect url after post save

  • Hi all. I have a problem and hoping that there’s some good folks here who can help me. I have prepared a front-end form. This is for a donation form, and I have added a cURL call after the form has submitted, to the payment gateway api. the problem here is, I want the form page to be redirect to a url returned by the payment gateway api, for users to pay with their bank, offsite.

    The idea that I have is to change the post permalink after the post have been saved, but before user being redirected, so that they will be redirected to the correct url (given by payment gateway api), and not the original permalink.

    Any idea to execute this?

    Here’s my code so far:

    	add_action('acf/save_post', 'my_save_post', 10, 1);
    function my_save_post( $post_id ) {
    	$billplzApi = get_field('billplz_secret_key', 'option');
    	$billplzId = get_field('billplz_collection_id', 'option');
    	// bail early if not a donation post
    	if( get_post_type($post_id) !== 'donation' ) {
    	// bail early if editing in admin
    	if( is_admin() ) {	
    	$post = get_post( $post_id);
    	$amount = '';
    	$donationGroup = get_field('donation_amount', $post);
    	$selectedAmount = $donationGroup['select_donation_amount'];
    	$customAmount = $donationGroup['specify_any_amount'];
    		$amount = $selectedAmount;
    	} else {
    		$amount = $customAmount;
    	$name = get_field('name', $post);
    	$email = get_field('email', $post);
    	$unmobile = get_field('mobile', $post);
    	$mobile = "+6" . $unmobile;
    	$billplz_data = array(
    	  'amount' => $amount * 100,
    	  'name' => $name,
    	  'mobile' => $mobile,
    	  'email' => $email,
    	  'collection_id' => $billplzId,
    	  'deliver' => false,
    	  'description' => 'a test for payment gateway',
    	  'redirect_url' => home_url('donation-redirect'),
    	  'callback_url' => home_url('donation-callback')
    	  $process = curl_init('');
    	  curl_setopt($process, CURLOPT_HEADER, 0);
    	  curl_setopt($process, CURLOPT_USERPWD, $billplzApi . ":");
    	  curl_setopt($process, CURLOPT_TIMEOUT, 30);
    	  curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
    	  curl_setopt($process, CURLOPT_POSTFIELDS, http_build_query($billplz_data));
    	  $return = curl_exec($process);
    	  $arr = json_decode($return, true);
              //this is the url to replace the original post permalink
    	  $billplz_url = $arr['url'];		
    <div class="row">
    	<div class="col-sm-12 col-md-8 col-md-offset-2 col-xs-12">
    while (have_posts()) : the_post();
    	'post_id' 		=> 'new_post',
    	'new_post'		=> array(
    						'post_type' 	=> 'donation',
    						'post_status'	=> 'publish'
    	'submit_value'	=> 'Donate',
    	'html_submit_button' => '<input type="submit" class="acf-button btn btn-success btn-lg pull-right" value="%s" />',
    	'return' => '%post_url%'
  • Found a solution to this problem here:

    so basically i need to add:


    and remove:

    'return' => '%post_url%'

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.