Skip Navigation

[Resolved] Link back to post once message is sent to seller

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

Problem: I have a link to a CRED form on my single post page. I would like to redirect the success message displayed after the form is submitted to include a link back to the single post page.

Solution: Add some custom PHP that will allow you to access the URL parameter from the CRED form page. Use the URL parameter from the CRED page to build your link.

// Access URL parameters
// Example: [wpv-post-param var='someurlparam']
 
add_shortcode( 'wpv-post-param', 'wpv_post_param_shortcode' );
 
function wpv_post_param_shortcode( $atts ) {
  if ( !empty( $atts['var'] ) ) {
    $var = (array)$_GET[$atts['var']];
    return esc_html( implode( ', ', $var ) );
  }
}
<div class="woocommerce-message" style="text-align: center;">Your message has been sent to the Seller.</div>
<ul class="nav-single pager">
    <li class="nav-previous previous"><a href="/motorcycles/[wpv-post-param var='listing-id']" rel="prev"> Click here to return to the [wpv-post-title id="[wpv-post-param var='listing-id']"]</a></li>
</ul>
This support ticket is created 7 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 replies, has 2 voices.

Last updated by Charles 7 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#553315

Support,

I am trying to create a link that is shown in the display message once a customer successfully sends a message to a seller. I am having trouble successfully linking back to the post. It wants to revert to my "contact seller" page.

Current code:

<div class="woocommerce-message" style="text-align: center;">Your message has been sent to the Seller.</div>
<ul class="nav-single pager">
 	<li class="nav-previous previous"><a href="[motorcycles-info info='id']" rel="prev">" Click here to return to the [motorcycles-info info='post-title']</a></li>
</ul>

Screenshot: hidden link

It may be best if I provide my credentials so you can see my link structuring.

Thanks,
Chuck

#553583

Okay yes, please provide login credentials and a URL where I can see this message in wp-admin. Private reply fields are enabled here.

#553585

Nevermind, I see the login credentials in a separate ticket. I'm working through these now, please stand by.

#553587

Hi, can you tell me about this shortcode you are using:

[motorcycles-info info='post-title']

Where is the motorcycles-info shortcode defined? It's not native to Toolset and I don't see it added in your child theme files - is it part of a separate plugin?

#553648

Okay thanks.

The main issue is that on the Contact Seller page, shortcodes like [wpv-post-id] and [wpv-post-title] will not refer to the original motorcycle post, they will refer to the Contact Seller page itself. You can use the "id" attribute to reference a different post, but you must know the post's numeric ID. So that's tricky on this page, since it's not related to the motorcycle post.

I see that you are including the listing ID as a URL parameter on the contact seller page. If you're planning to keep that, I can offer this solution:

1. The following code will create a shortcode that gives you access to URL parameters. Add to functions.php:

// Access URL parameters
// Example: [wpv-post-param var='someurlparam']

add_shortcode( 'wpv-post-param', 'wpv_post_param_shortcode' );

function wpv_post_param_shortcode( $atts ) {
  if ( !empty( $atts['var'] ) ) {
    $var = (array)$_GET[$atts['var']];
    return esc_html( implode( ', ', $var ) );
  }
}

2. Access listing-id from the URL and use it to build your link URL and message:

<div class="woocommerce-message" style="text-align: center;">Your message has been sent to the Seller.</div>
<ul class="nav-single pager">
    <li class="nav-previous previous"><a href="/motorcycles/[wpv-post-param var='listing-id']" rel="prev"> Click here to return to the [wpv-post-title id="[wpv-post-param var='listing-id']"]</a></li>
</ul>

Please implement these changes and let me know the results, or let me know how I can test this on your site for myself - I didn't want to assume I can submit the form.

#553972

That code did the trick, works great!

Thanks,
Chuck